[BUG] [flask-python] Optional date in query parameters results in dateutil error when None
Created by: Tohnmeister
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.