Skip to content

Fix(all) schema-mappings and import-mapping for api#24261

Open
jpfinne wants to merge 19 commits into
OpenAPITools:masterfrom
jpfinne:bugfix/schemaMappingForApi
Open

Fix(all) schema-mappings and import-mapping for api#24261
jpfinne wants to merge 19 commits into
OpenAPITools:masterfrom
jpfinne:bugfix/schemaMappingForApi

Conversation

@jpfinne

@jpfinne jpfinne commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

fix #24232 for all generators

Ensure that import statements are correctly put in the generated api when schema-mappings and import-mappings are used.

Minor side effect that can breaks some code: for Spring, and Kotlin, some additional imports can be added in the generated apis.
For example:
import org.springframework.core.io.Resource;
import java.io.File;

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

Fixes missing imports for schema- or type-mapped parameter types in API generation so importMapping is honored with --schema-mappings (fixes #24232).

  • Bug Fixes
    • In DefaultCodegen.fromOperation, add mapped parameter dataType tokens to op.imports when present in importMapping, so fully qualified imports are emitted.
    • Added a Spring test and OpenAPI fixture to verify imports of org.myorg.MyCustomId and org.myorg.MyCustomKey are generated in SomeApi.java and Dummy.java.
    • Updated samples: Spring now imports org.springframework.core.io.Resource; Kotlin Javalin imports io.javalin.http.UploadedFile; Kotlin Ktor imports io.ktor.http.content.PartData.FileItem; Groovy adds java.io.File.

Written for commit 3a6f08c. Summary will update on new commits.

Review in cubic

@jpfinne jpfinne changed the title schema mapping for api Fix(all) schema-mappings and import-mapping for api Jul 9, 2026
@jpfinne jpfinne marked this pull request as ready for review July 9, 2026 07:37

@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.

2 issues found across 112 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="samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/PetApi.java">

<violation number="1" location="samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/PetApi.java:11">
P3: Unused import of `org.springframework.core.io.Resource` — the added import is not referenced anywhere in this file's code body. While this is a known side effect of the code generator change (as noted in the PR description), unused imports add noise and may trigger IDE warnings or lint checks. Consider whether the code generator's import emission logic could be scoped to only emit the import when the type is actually used in the file body, rather than when it appears anywhere in the parameter type resolution chain.</violation>
</file>

<file name="samples/server/petstore/springboot-x-implements-skip/src/main/java/org/openapitools/api/PetApi.java">

<violation number="1" location="samples/server/petstore/springboot-x-implements-skip/src/main/java/org/openapitools/api/PetApi.java:12">
P3: Unused import: `org.springframework.core.io.Resource` — added but never used in any method parameter, return type, or annotation within PetApi. This will cause a compiler warning.</violation>
</file>

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

Re-trigger cubic

import org.openapitools.model.ModelApiResponse;
import org.springframework.lang.Nullable;
import org.openapitools.model.Pet;
import org.springframework.core.io.Resource;

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.

P3: Unused import of org.springframework.core.io.Resource — the added import is not referenced anywhere in this file's code body. While this is a known side effect of the code generator change (as noted in the PR description), unused imports add noise and may trigger IDE warnings or lint checks. Consider whether the code generator's import emission logic could be scoped to only emit the import when the type is actually used in the file body, rather than when it appears anywhere in the parameter type resolution chain.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/server/petstore/spring-boot-springdoc/src/main/java/org/openapitools/api/PetApi.java, line 11:

<comment>Unused import of `org.springframework.core.io.Resource` — the added import is not referenced anywhere in this file's code body. While this is a known side effect of the code generator change (as noted in the PR description), unused imports add noise and may trigger IDE warnings or lint checks. Consider whether the code generator's import emission logic could be scoped to only emit the import when the type is actually used in the file body, rather than when it appears anywhere in the parameter type resolution chain.</comment>

<file context>
@@ -8,6 +8,7 @@
 import org.openapitools.model.ModelApiResponse;
 import org.springframework.lang.Nullable;
 import org.openapitools.model.Pet;
+import org.springframework.core.io.Resource;
 import io.swagger.v3.oas.annotations.ExternalDocumentation;
 import io.swagger.v3.oas.annotations.Operation;
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Generated code. It has already plenty of unused imports

import org.springframework.lang.Nullable;
import org.openapitools.model.PetDto;
import java.util.Set;
import org.springframework.core.io.Resource;

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.

P3: Unused import: org.springframework.core.io.Resource — added but never used in any method parameter, return type, or annotation within PetApi. This will cause a compiler warning.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/server/petstore/springboot-x-implements-skip/src/main/java/org/openapitools/api/PetApi.java, line 12:

<comment>Unused import: `org.springframework.core.io.Resource` — added but never used in any method parameter, return type, or annotation within PetApi. This will cause a compiler warning.</comment>

<file context>
@@ -9,6 +9,7 @@
 import org.springframework.lang.Nullable;
 import org.openapitools.model.PetDto;
 import java.util.Set;
+import org.springframework.core.io.Resource;
 import io.swagger.v3.oas.annotations.ExternalDocumentation;
 import io.swagger.v3.oas.annotations.Operation;
</file context>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Generated code. It has already plenty of unused imports

jpfinne and others added 3 commits July 9, 2026 09:53
…en/java/spring/SpringCodegenTest.java

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@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.

[BUG] [JAVA] [SPRING] missing import for schemaMapping in api

1 participant