Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #4251
Closed
Open
Issue created Oct 24, 2019 by Martin Delille@MartinDelilleContributor

Pass parameters to a post operation

Hello everyone!

I’m coming back to openapi-generator after quite a long times and I wanted to test my api with the bash client.

Description

When doing a post operation, I wonder how to pass parameters to the operation.

openapi-generator version

4.1.3

OpenAPI declaration file content or url
openapi: 3.0.1
servers:
  - url: 'https://api.martin.delille.org'
info:
  description: This is martin.delille.org API.
  version: 1.0.0
  title: martin.delille.org API
  contact:
    url: 'https://martin.delille.org'
    email: 'martin@delille.org'
paths:
  /login:
    post:
      operationId: login
      requestBody:
          required: true
          content:
            application/x-www-form-urlencoded:
              schema:
                type: object
                properties:
                  email:
                    type: string
                  password:
                    type: string
                required:
                  - email
                  - password
      responses:
        '200':
          description: Login successfull
          content:
            application/json:
              schema:
                type: object
                required:
                  - access_token
                properties:
                  access_token:
                    type: string
Command line used for generation
openapi-generator generate -i api.yaml -g bash
Steps to reproduce
./client.sh http://localhost:3000 login email=martin@delille.org password=12345
Related issues/PRs

?

Suggest a fix/enhancement

I'm not a bash script expert so I don't understand how to pass the email/password parameters but when I look at the generated code, I doesn't seems to be passed to the curl command:

    local method="POST"
    local headers_curl
    headers_curl=$(header_arguments_to_curl)
    if [[ -n $header_accept ]]; then
        headers_curl="${headers_curl} -H 'Accept: ${header_accept}'"
    fi

    local basic_auth_option=""
    if [[ -n $basic_auth_credential ]]; then
        basic_auth_option="-u ${basic_auth_credential}"
    fi
    if [[ "$print_curl" = true ]]; then
        echo "curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\""
    else
        eval "curl ${basic_auth_option} ${curl_arguments} ${headers_curl} -X ${method} \"${host}${path}\""
    fi

I managed to perform this request with this curl command:

curl -X POST "http://localhost:3000/login" -d "email=martin@delille.org&password=12345"
Assignee
Assign to
Time tracking