swagger-api / swagger-api/swagger-codegen

[python-flask] stub not called if requiered parameters in header

Open
#11,263 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

The stub are not called if there is requiered parameters in header

      parameters:
      - name: "api_version"
        in: "header"
        required: true
        type: "integer"
        enum:
        - 1
        - 2
        - 3
      - in: "body"
        name: "body"
        description: "Pet object that needs to be added to the store"
        required: true
        schema:
          $ref: "#/definitions/Pet"

cf. controller.mustache, if parameter in header is "required: true" :

template :

...
def {{operationId}}({{#allParams}}{{paramName}}{{^required}}=None{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}):  # noqa: E501
    """{{#summary}}{{.}}{{/summary}}{{^summary}}{{operationId}}{{/summary}}
...

generated code :

def add_pet(api_version, body):  # noqa: E501

But it seems that the {{^required}}=None{{/required}} is incompatible with the current connection framework on top of Flask.
"Currently, header parameters are not passed to the handler functions as parameters. But they can be accessed through the underlying connexion.request.headers object which aliases the flask.request.headers object."

Temporarly to be defined

def add_pet(api_version=None, body=None):  # noqa: E501
Swagger-codegen version

2.4.23

Swagger declaration file content or url

Replace

.\swagger-codegen\modules\swagger-codegen\src\test\resources\2_0\petstore-flask.yaml

with

petstore-flask.zip

Command line used for generation

bin\windows\python3-flask-petstore.bat

Steps to reproduce

Use this API
http://localhost:8080/v2/ui/#!/pet/add_pet
http://localhost:8080/v2/ui/#!/pet/update_pet

Related issues/PRs

Not found

Suggest a fix/enhancement

To be defined

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

Start with modules/swagger-codegen/src/main/resources/python-flask/controller.mustache and the supplied 2_0/petstore-flask.yaml definition. Reproduce the issue with bin\windows\python3-flask-petstore.bat and inspect the generated add_pet handler for the required header parameter. Done means the generated stub is called correctly for the documented header and body parameters, with a regression test or fixture capturing the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.