Swagger Default Date
Hi,
I've a parameter to_date and from_date and by default i want to set it from 2000-01-01 and from_date: current date
=> Starting date parameter
name: from_date description: Filter by starting date in: query schema: type: string format: date description: Date in YYYY-MM-DD format default: "2000-01-01" | I want default date here example: "2015-10-10"
=> Ending date parameter
name: to_date description: Filter by starting date in: query schema: type: string format: date description: Date in YYYY-MM-DD format default: "2022-01-15" | I want current date here example: "2022-01-15"
Getting following error on make gen-spec command, what is wrong here?
File "/home/daniyal/.cache/pypoetry/virtualenvs/e2e-ai-api-K3f0-_qS-py3.8/lib/python3.8/site-packages/connexion/spec.py", line 242, in _validate_spec raise InvalidSpecification.create_from(e) connexion.exceptions.InvalidSpecification: {'name': 'to_date', 'description': 'Filter by ending date', 'in': 'query', 'required': False, 'schema': {'type': 'string', 'format': 'date', 'description': 'Date in YYYY-MM-DD format', 'default': datetime.date(2000, 1, 10)}, 'example': datetime.date(2020, 10, 10)} is not valid under any of the given schemas
Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['get']['properties']['parameters']['items']: {'oneOf': [{'$ref': '#/definitions/parameter'}, {'$ref': '#/definitions/reference'}]}
On instance['paths']['/polygon/aggregates']['get']['parameters'][1]: {'description': 'Filter by ending date', 'example': datetime.date(2020, 10, 10), 'in': 'query', 'name': 'to_date', 'required': False, 'schema': {'default': datetime.date(2000, 1, 10), 'description': 'Date in YYYY-MM-DD format', 'format': 'date', 'type': 'string'}}
I think the problem is you're putting code into your OpenAPI deacription that is not being executed, leaving you with a string of literal code that is not a valid date format.
You don't need to try and do this. OAS describes the input/output and if the current date is being used then just don't put the default in and say "If no date is provided the current date will be assumed" in the description. The example is clear enough already.
No further comments after the answer in 2022, closing.