-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Models with additionalProperties
and properties
that are complex now generate correct code (Issue #20213)
#21827
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
base: master
Are you sure you want to change the base?
Conversation
…now generate correct code
A check failed from what seems to be a random build issue: |
Hi @DavidGrath, Could we add a test to the OpenAPINormalizerTest to more precisely illustrate how the fix affects the OpenAPI swagger-core model representation? |
@Mattias-Sehlstedt , thank you, I'm thinking of adding another assertion to an existing test that seems specifically made for this: Line 844 in 065eceb
Schema schema23 = openAPI.getComponents().getSchemas().get("AnyOfNullableAdditionalPropertiesTest");
assertEquals(((Schema) schema23.getProperties().get("str")).getAnyOf(), null);
assertTrue(((Schema) schema23.getProperties().get("str")).getNullable());
assertEquals(schema22.getTypes(), Set.of("string")); AnyOfNullableAdditionalPropertiesTest:
description: to test anyOf with additional properties
additionalProperties: false
properties:
str:
anyOf:
- type: string
- type: 'null'
- type: null
- $ref: null Do you think this is sufficient or should I still go ahead to make a new test or modify another existing test? |
I can start off by clarifying that I am not a maintainer of the repo, only a contributor. So I make personal comments that do not affect whether anything will get approved or not.
I believe it should be fine if you add an additional model and assertion to that test (I believe I might have done so myself previously). The current test in DefaultCodegen I believe could be kept if you find that they are valuable for preventing regression. But if you elect to keep them, then I would argue that you should either move them to their respective Codegen class (so Why I make this suggestion is because the current tests in DefaultCodegenTest are testing behavior way beyond that of DefaultCodegen. The code generation is basically:
Your current test in DefaultCodegen does 3, 4 and 5, while it should preferably only do step 3 in the tests. So if you want to have tests in DefaultCodegen, you should inspect the created code properties rather than generating a file and inspecting that. |
It potentially looks like this change is something that could fix this? I.e., we could skip attempting the "map" processing if the property is only additionalProperties=false? |
I agree, I'll move the
Do you mean something like this? : if(!ModelUtils.isModelWithPropertiesOnly(schema)) {
normalizeMapSchema(schema);
} else {
normalizeProperties(schema.getProperties(), visitedSchemas);
} |
I have not tried it out myself, but I read the code as "if there are additional properties, process it as a map, otherwise continue". That seems to work well for 3.0, where the if-case is properly false, but for 3.1 I assume the parser creates a different model for |
@Mattias-Sehlstedt , thank you. I've subscribed to that PR so that I can make the changes when it's merged. |
PR checklist
Commit all changed files.
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*
.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master
(upcoming7.x.0
minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)"fixes #123"
present in the PR description)Fixes #20213
Concerning the test, specifically, since the original issue isn't tied to one specific language, I wanted to know where the most fitting place would be to put it, and if I should bother using all 3 generators that @lesteenman mentioned or just stick to one