-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
fix(core): avoid dangling request-model import for skipped form models #24807
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
Open
SubhamAshok
wants to merge
6
commits into
OpenAPITools:master
Choose a base branch
from
SubhamAshok:fix/24727-dangling-request-model-import
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3e336bb
fix(core): avoid dangling request-model import for skipped form models
SubhamAshok 620fdc9
fix(core): align skipFormModel resolution and preserve shared form mo…
SubhamAshok 68bf8f8
fix(core): preserve existing skipFormModel in additionalProperties
SubhamAshok 69db41a
fix(core): read normalized skipFormModel from additionalProperties in…
SubhamAshok b16feb6
refactor(core): extract convertGlobalPropertyToBooleanAndWriteBack he…
SubhamAshok bde822c
fix(core): restore correct additionalProperties mapping for generator…
SubhamAshok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,21 @@ void configureGeneratorProperties() { | |
| generateApiDocumentation = GlobalSettings.getProperty(CodegenConstants.API_DOCS) != null ? Boolean.valueOf(GlobalSettings.getProperty(CodegenConstants.API_DOCS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_DOCS, true); | ||
| generateRecursiveDependentModels = GlobalSettings.getProperty(CodegenConstants.GENERATE_RECURSIVE_DEPENDENT_MODELS) != null ? Boolean.valueOf(GlobalSettings.getProperty(CodegenConstants.GENERATE_RECURSIVE_DEPENDENT_MODELS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.GENERATE_RECURSIVE_DEPENDENT_MODELS, false); | ||
|
|
||
| Boolean skipFormModel = null; | ||
| if (config.additionalProperties().containsKey(CodegenConstants.SKIP_FORM_MODEL)) { | ||
| final Object val = config.additionalProperties().get(CodegenConstants.SKIP_FORM_MODEL); | ||
| if (val instanceof Boolean) { | ||
| skipFormModel = (Boolean) val; | ||
| } else if (val != null) { | ||
| skipFormModel = Boolean.parseBoolean(val.toString()); | ||
| } | ||
| } | ||
| if (skipFormModel == null) { | ||
| skipFormModel = GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ? | ||
| Boolean.valueOf(GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL)) : | ||
| getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, true); | ||
| } | ||
|
|
||
| // Additional properties added for tests to exclude references in project related files | ||
| config.additionalProperties().put(CodegenConstants.GENERATE_API_TESTS, generateApiTests); | ||
| config.additionalProperties().put(CodegenConstants.GENERATE_MODEL_TESTS, generateModelTests); | ||
|
|
@@ -236,6 +251,7 @@ void configureGeneratorProperties() { | |
| config.additionalProperties().put(CodegenConstants.GENERATE_MODELS, generateModels); | ||
| config.additionalProperties().put(CodegenConstants.GENERATE_WEBHOOKS, generateWebhooks); | ||
| config.additionalProperties().put(CodegenConstants.GENERATE_RECURSIVE_DEPENDENT_MODELS, generateRecursiveDependentModels); | ||
| config.additionalProperties().put(CodegenConstants.SKIP_FORM_MODEL, skipFormModel); | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| if (!generateApiTests && !generateModelTests) { | ||
| config.additionalProperties().put(CodegenConstants.EXCLUDE_TESTS, true); | ||
|
|
@@ -470,9 +486,11 @@ void generateModels(List<File> files, List<ModelMap> allModels, List<String> unu | |
| // store all processed models | ||
| Map<String, ModelsMap> allProcessedModels = new TreeMap<>((o1, o2) -> ObjectUtils.compare(config.toModelName(o1), config.toModelName(o2))); | ||
|
|
||
| Boolean skipFormModel = GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ? | ||
| Boolean.valueOf(GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL)) : | ||
| getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, true); | ||
| Boolean skipFormModel = config.additionalProperties().containsKey(CodegenConstants.SKIP_FORM_MODEL) ? | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @SubhamAshok Same as above. This looks way too convulated |
||
| Boolean.valueOf(config.additionalProperties().get(CodegenConstants.SKIP_FORM_MODEL).toString()) : | ||
| (GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL) != null ? | ||
| Boolean.valueOf(GlobalSettings.getProperty(CodegenConstants.SKIP_FORM_MODEL)) : | ||
| getGeneratorPropertyDefaultSwitch(CodegenConstants.SKIP_FORM_MODEL, true)); | ||
|
|
||
| // process models only | ||
| for (String name : modelKeys) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
modules/openapi-generator/src/test/resources/3_0/issue_24727.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: Multiple request-body content types repro | ||
| version: 1.0.0 | ||
| paths: | ||
| /api/multi_article_importer: | ||
| post: | ||
| operationId: createMultiArticleImporter | ||
| summary: Create a multi article importer | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/MultiArticleImporter' | ||
| multipart/form-data: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| file: | ||
| type: string | ||
| format: binary | ||
| responses: | ||
| '201': | ||
| description: Created | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/MultiArticleImporter' | ||
| components: | ||
| schemas: | ||
| MultiArticleImporter: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: integer | ||
| format: int64 | ||
| name: | ||
| type: string |
32 changes: 32 additions & 0 deletions
32
modules/openapi-generator/src/test/resources/3_0/issue_24727_shared.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: Shared form model repro | ||
| version: 1.0.0 | ||
| paths: | ||
| /api/upload: | ||
| post: | ||
| operationId: uploadArticle | ||
| summary: Upload an article | ||
| requestBody: | ||
| required: true | ||
| content: | ||
| multipart/form-data: | ||
| schema: | ||
| $ref: '#/components/schemas/ArticlePayload' | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| $ref: '#/components/schemas/ArticlePayload' | ||
| components: | ||
| schemas: | ||
| ArticlePayload: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: integer | ||
| format: int64 | ||
| title: | ||
| type: string |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SubhamAshok I had the same kind of issue when I wrote
DefaultCodegen.convertPropertyToBooleanAndWriteBackThe configuration could come from a cliOption or from additionalProperties. Before there were discrepancies, leading to side effects if the code or the template used additionalProperties or getter in the CodeGen.
It think we could have the same for GlobalSettings.
Maybe we can have something like:
boolean convertGlobalSettingsPropertyToBooleanAndWriteBack(String propertyKey, Consumer<Boolean> booleanSetter, Supplier<Boolean> defaultIfMissing)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! Added
convertGlobalPropertyToBooleanAndWriteBackinDefaultGeneratorto resolve the global/generator defaults and write them back intoadditionalProperties.configureGeneratorPropertiesandgenerateModelsnow use this single standard path.