-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request:
$250$1,000 (see below!)
Description
Using -g python on a spec that has a schema item with a string value, it's usually an integer but it doesn't have to be. When it's an integer that can be parsed as a date, it gets turned into a date. Sometimes. The way I've been able to consistently replicate it is with a composite object using allOf.
In the spec below, there are two schemas called thingone and thingtwo, each an object with two string properties, and another schema called twothings which is an allOf composition of thingone and thingtwo. When processing a twothings response, where all the string properties are of the form YYYYMMDD, the string properties that belong to thingone are coerced into dates.
openapi-generator version
5.3.1-SNAPSHOT using Docker
OpenAPI declaration file content or url
https://gist.github.com/mariodsantana/9944ee3e4d669771bccaeb059ce863a0
Generation Details
docker run -u $UID --rm -v $PWD:/local openapitools/openapi-generator-cli \
generate -i /local/openapi.yaml -g python -o /local \
--additional-properties packageName=fake \
--additional-properties pythonAttrNoneIfUnset=true \
--additional-properties generateSourceCodeOnly=true
Steps to reproduce
- Copy the openapi spec below
- Generate client code
- Run mocking server
- Call the get_twothings API
- Notice that some of the results are dates
I've written a little bash script to do all of the above, see https://gist.github.com/mariodsantana/28477b908e0d50e17cbcddb52161d790
Related issues/PRs
Obviously there's a lot of work going on with composed schemas and allOf &co, but in my ignorance I couldn't find anything that seemed actually related to this.
Suggest a fix
No real idea. I can fix the immediate issue with a small patch to the generated model_utils.py but then that keeps legitimate dates from being converted from strings.
I'm willing to sponsor this work to the tune of $250. Maybe more if it turns out to be a complicated issue. ETA: It's turned out to be a complicated issue. I've upped the bounty to $1,000. :)