Bugfix/ignore schema mappings and import mappings for forced generate schemas - #24771
Conversation
…as as isolated shadow models
…mas as isolated shadow models
There was a problem hiding this comment.
All reported issues were addressed across 39 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…o handle isolated shadow model generation
…ependents and suppress mapping leaks
…s for improved readability
There was a problem hiding this comment.
All reported issues were addressed across 36 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…sure correct model reference handling
…y API isolation Enabling APIS in ForcedGenerateSchemasSupportedFamiliesTest exposed that the forced shadow pass reused a CodegenProperty cached during api generation (with the schemaMapping intact), leaking the mapped name into the stock shadow model (observed in the R generator's widget.R). Clear schemaCodegenPropertyCache in DefaultCodegen.clearModelNameCache() so properties are rebuilt with the current mappings. The test now keeps APIS enabled and asserts non-forced API artifacts still reference the mapped class. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
1 issue found across 36 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/ForcedGenerateSchemasSpringTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/ForcedGenerateSchemasSpringTest.java:185">
P2: The spec has no tags, so all operations fall under the default "default" tag and Spring generates a single `DefaultApi.java`, never `WidgetApi.java`. The assertion reads `src/main/java/org/openapitools/api/WidgetApi.java`, which does not exist, so `assertFileContains` throws NoSuchFileException and the test fails. Assert against `DefaultApi.java` (the file that the no-tag spec actually produces), or add explicit `tags` to the spec so the API name matches.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
|
||
| generate(output, codegen, true, "Widget", "Group", "Shape", "Circle", "Square", "Container"); | ||
|
|
||
| Path api = Paths.get(output + "/src/main/java/org/openapitools/api/WidgetApi.java"); |
There was a problem hiding this comment.
P2: The spec has no tags, so all operations fall under the default "default" tag and Spring generates a single DefaultApi.java, never WidgetApi.java. The assertion reads src/main/java/org/openapitools/api/WidgetApi.java, which does not exist, so assertFileContains throws NoSuchFileException and the test fails. Assert against DefaultApi.java (the file that the no-tag spec actually produces), or add explicit tags to the spec so the API name matches.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/ForcedGenerateSchemasSpringTest.java, line 185:
<comment>The spec has no tags, so all operations fall under the default "default" tag and Spring generates a single `DefaultApi.java`, never `WidgetApi.java`. The assertion reads `src/main/java/org/openapitools/api/WidgetApi.java`, which does not exist, so `assertFileContains` throws NoSuchFileException and the test fails. Assert against `DefaultApi.java` (the file that the no-tag spec actually produces), or add explicit `tags` to the spec so the API name matches.</comment>
<file context>
@@ -0,0 +1,223 @@
+
+ generate(output, codegen, true, "Widget", "Group", "Shape", "Circle", "Square", "Container");
+
+ Path api = Paths.get(output + "/src/main/java/org/openapitools/api/WidgetApi.java");
+ assertFileContains(api, "com.example.mapped.Widget");
+ assertFileNotContains(api, "ApiWidget");
</file context>
| Path api = Paths.get(output + "/src/main/java/org/openapitools/api/WidgetApi.java"); | |
| Path api = Paths.get(output + "/src/main/java/org/openapitools/api/DefaultApi.java"); |
…c-v1 isolation Forced-schema pass now derives the mapping-removal set from all component schemas (not just the MODELS-constrained top-level keys), so a forced, mapping-suppressed schema reachable only as a recursive dependent of another forced schema is emitted under its stock name instead of being skipped (its mapping previously stayed in place, so the forced-to-forced reference resolved to the mapped class). Added a DefaultGeneratorTest regression covering a forced dependent outside a constrained model set. Also verify the isolation contract for the python-pydantic-v1 family: it sanitizes a dotted schemaMapping to a camelCase token (ComExampleMappedWidget) rather than carrying it verbatim, so ForcedGenerateSchemasSupportedFamiliesTest now checks the actually-rendered mapped reference per family (Container, API, and shadow no-leak) instead of skipping pydantic-v1. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary by cubic
Forced schema generation now ignores schema/import mappings and emits isolated shadow models under their stock names. Normal generation keeps mapped classes, and unsupported generators fail fast before writing files; we also clear mapping-sensitive caches so shadow models don't leak mapped names while APIs keep mapped references.
Bug Fixes
typeMappingstill applies, and*covers all mapping-suppressed schemas.generateRecursiveDependentModelsis enabled and the model set is constrained.CodegenPropertyduring the shadow pass to rebuild properties with current mappings.ForcedSchemaSupport.clearModelNameCache()for Java, Groovy, Kotlin, C#, Python (incl. Pydantic v1), PHP, Go client, Perl, PowerShell, R, and Ruby; unsupported generators fail early.Categorytocom.example.mapped.Category; tests verify isolation per family, accounting for pydantic-v1's camelCase sanitization of dotted mappings.Migration
forcedGenerateSchemas.Written for commit bcc18fd. Summary will update on new commits.