Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
5 tasks done
Tohnmeister opened this issue Apr 3, 2020 · 4 comments · Fixed by #10081
Open
5 tasks done

Comments

@Tohnmeister
Copy link

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.

@auto-labeler
Copy link

auto-labeler bot commented Apr 3, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@Tohnmeister
Copy link
Author

Tested it locally by modifying util.mustache like above and using that one as the template. This seems to fix the issue. Will see later today if I can checkout the project and contribute a fix.

LeComptoirDesPharmacies pushed a commit to LeComptoirDesPharmacies/openapi-generator that referenced this issue Aug 2, 2021
As "deserialize_date" and "deserialize_datetime" are used outside of "deserialize_model", we should check 'None' value before parsing string.
wing328 pushed a commit that referenced this issue Aug 14, 2021
#10081)

* Bug #5813 :

As "deserialize_date" and "deserialize_datetime" are used outside of "deserialize_model", we should check 'None' value before parsing string.

* Bugfix 5813 :

Update samples and docs
@wing328
Copy link
Member

wing328 commented Aug 14, 2021

Closed via #10081. Thanks for the PR by @LeComptoirDesPharmacies

@pala1212
Copy link

This bug affects python-aiohttp, as well. Fix was only applied to python-flask

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants