Skip to content

Pass parameters to a post operation #4251

@MartinDelille

Description

@MartinDelille

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: '[email protected]'
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 protected] 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 protected]&password=12345"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions