swagger-api / swagger-api/swagger-codegen

[ALL] parameter name for post body must be 'body'

Open
#9,295 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

in Swagger version 2, it was possible to specify a name for the body parameter in the yaml...

      parameters:
        - in: body
          name: instanceInputs
          required: true
          description: The inputs to use to create instances from the parent definition.
          schema:
            $ref: '#/definitions/CreateExternalWorkflowInstances'

which after generation yielded a name for the parameter...

def create_external_workflows_instances(self, uid, instance_inputs, **kwargs):  # noqa: E501

with the update to open api 3.0, this no longer appears to be possible...

      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateExternalWorkflowInstances"
        description: The inputs to use to create instances from the parent definition.
        required: true

and the parameter name for the body seems to be stuck as 'body'.

def create_external_workflows_instances(self, body, uid, **kwargs):  # noqa: E501

using 'body' as the parameter name is ok as a default but it is 'leaking' the implementation detail (the fact that the value is passed in the http body of a post) into the programatic api. It should be (and was previously) possible to change this default.

Swagger-codegen version

3.0.5

Swagger declaration file content or url
  "/workflows/instances/external/{uid}":
    parameters:
      - name: uid
        in: path
        required: true
        schema:
          type: string
    post:
      summary: Create external workflow instance(s) based on an external definition
      operationId: create_external_workflows_instances
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateExternalWorkflowInstances"
        description: The inputs to use to create instances from the parent definition.
        required: true
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Bookmark"
      security:
        - api_key:
            []
      tags:
        - workflows_instances
Command line used for generation

swagger-codegen generate -DmodelTests=false -DapiDocs=false -DmodelDocs=false -i ./procanswonhttp-py/swonSwagger.yaml -l python -o ./procanswonhttp-py --additional-properties packageName=procanswonhttp

Related issues/PRs

Issue #9103 pertains to the order of the body parameter which is also an issue for me

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied OpenAPI declaration and the shown swagger-codegen command, then inspect the generated Python method signature. Compare the OpenAPI 3 requestBody handling with the Swagger 2 body-parameter behavior and review related issue #9103. Done means the generated API exposes an appropriate configurable body argument without regressing parameter ordering.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.