-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Add schema mappings #12600
Add schema mappings #12600
Conversation
I just tried this and managed to compile it. It took a while since 6.x introduced a bunch of other changes as well. At times I wasn't entirely sure when to use importMappings and when to use schemaMappings. I think I still have a bunch of importMappings left over, that are not needed. |
@pschichtel thanks for testing the change. Usually
(for java client) Without the importMappings, the auto-generated code above won't compile. |
Ok, so basically we can map types, which are not generated, to other types and introduce import mappings for those. we basically do 3 things:
what I noticed, and I'm not sure if that is related to this feature or something else included in version 6: Duration:
description: An amount of time, measured in milliseconds.
type: integer
format: duration
example: 60000 This type is referenced by a bunch of spec files. We don't generate models for "primitives" (anything but type:object), so normally properties referencing this would end up being a Integer in our generated clients/servers. However we introduce a typeMapping integer+duration -> Duration and an importMapping Duration -> java.time.Duration. That was previously enough to have the clients/servers have Duration for these properties. On this branch with version 6+, it instead generated a model Duration, which I corrected to java.time.Duration by adding a schemaMapping for it. Is this intended behavior? It feels odd to me, but maybe I'm missing something. |
There was a bug (edge case?) when using importMappings to skip model from being generated and fixed via #11217 so we need to introduce another option |
But in these cases there shouldn't even be a model being generated, right? Since it's only a primitive without the type mapping. |
I couldn't repeat the issue with
and reference it in a property of another model as follows: --- a/modules/openapi-generator/src/test/resources/3_0/petstore.yaml
+++ b/modules/openapi-generator/src/test/resources/3_0/petstore.yaml
@@ -736,3 +736,10 @@ components:
type: string
message:
type: string
+ duration:
+ $ref: '#/components/schemas/Duration'
+ Duration:
+ description: An amount of time, measured in milliseconds.
+ type: integer
+ format: duration
+ example: 60000 command:
I don't see any "Duration" model file generated. |
Let's merge this and we can always submit another PR to further improve it. |
Since the 6.0.1 milestone is already overdue, is there already a plan for when to release this? |
@pschichtel @wing328 |
We ran into two issues with the current implementation: |
Great, thank you! |
Add schema mappings
To fix #11506
FYI @OpenAPITools/generator-core-team
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*
.For Windows users, please run the script in Git BASH.
master
(6.0.1) (patch release),6.1.x
(breaking changes with fallbacks),7.0.x
(breaking changes without fallbacks)