OpenAPITools / OpenAPITools/openapi-generator

[BUG] [flask-python] Optional date in query parameters results in dateutil error when None

Open
#5,813 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
    4.3.0
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

I've recently extended my api with a query parameter of type string, format date. The parameter is optional. If the client does not fill in the parameter, it is None on the Python side, resulting in a parse error in dateutil:

Parser must be a string or character stream, not NoneType
openapi-generator version

4.3.0

OpenAPI declaration file content or url
paths:
  /events:
    get:
      tags:
        - events
      summary: "Get a list of all events"
      operationId: listEvents
      parameters:
        - $ref: '#/components/parameters/startDateParam'
components:
  parameters:
    startDateParam:
      name: startDate
      in: query
      description: Optional start date when querying date based items
      required: false
      schema:
        type: string
        format: date
Command line used for generation

openapi-generator generate -i ./api/openapi.yaml -g python-flask -o ./server/generated/ -c ./server/codegen/config.json

Steps to reproduce
  • Generate server with above yaml and command line
  • Start flask app
  • Go to Swagger UI (/ui)
  • Use events list call without filling in startDateParam
  • See error as shown above
Related issues/PRs

Couldn't find a related issue.

Suggest a fix

It should either be fixed in util.mustache by adding a check for the date being not None and otherwise returning None. Or something similar in controller.mustache.

Same goes for datetime I guess, but haven't tested that.

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 by inspecting modules/openapi-generator/src/main/resources/python-flask/util.mustache and controller.mustache, then generate the sample Flask server with an optional date query parameter using the reported command. Reproduce the Swagger UI request without startDate and verify that the generated server accepts None without the reported dateutil error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.