Skip to content

Bugfix/ignore schema mappings and import mappings for forced generate schemas - #24771

Draft
Picazsoo wants to merge 12 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/ignore-schemaMappings-and-importMappings-for-forcedGenerateSchemas
Draft

Bugfix/ignore schema mappings and import mappings for forced generate schemas#24771
Picazsoo wants to merge 12 commits into
OpenAPITools:masterfrom
Picazsoo:bugfix/ignore-schemaMappings-and-importMappings-for-forcedGenerateSchemas

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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

    • Emits forced schemas as stock-name shadow models in a second pass; typeMapping still applies, and * covers all mapping-suppressed schemas.
    • Removes mappings for all forced component schemas, not only top-level ones, so forced schemas reachable as recursive dependents also resolve by stock names.
    • Pulls recursive dependents into the shadow pass when generateRecursiveDependentModels is enabled and the model set is constrained.
    • Keeps production outputs mapped: APIs, non-forced models, and supporting-file metadata; mapping-sensitive caches and mutable state are restored between passes.
    • Clears cached CodegenProperty during the shadow pass to rebuild properties with current mappings.
    • Adds ForcedSchemaSupport.clearModelNameCache() for Java, Groovy, Kotlin, C#, Python (incl. Pydantic v1), PHP, Go client, Perl, PowerShell, R, and Ruby; unsupported generators fail early.
    • Adds samples/configs mapping Category to com.example.mapped.Category; tests verify isolation per family, accounting for pydantic-v1's camelCase sanitization of dotted mappings.
  • Migration

    • No action if you don't use forcedGenerateSchemas.
    • If you relied on forced models using mapped names, update references: forced schemas generate as stock names while APIs and non-forced models reference the mapped class.

Written for commit bcc18fd. Summary will update on new commits.

Review in cubic

@Picazsoo
Picazsoo marked this pull request as ready for review August 24, 2026 21:31
@Picazsoo
Picazsoo marked this pull request as draft August 24, 2026 21:32

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 39 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@Picazsoo
Picazsoo marked this pull request as ready for review August 25, 2026 12:04
@Picazsoo
Picazsoo marked this pull request as draft August 25, 2026 12:05

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 36 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Picazsoo and others added 2 commits August 25, 2026 15:51
…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>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant