Fix(all) schema-mappings and import-mapping for api#24261
Conversation
merge master
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Generated code. It has already plenty of unused imports
…en/java/spring/SpringCodegenTest.java Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
… bugfix/schemaMappingForApi
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
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
Fixes missing imports for schema- or type-mapped parameter types in API generation so
importMappingis honored with--schema-mappings(fixes #24232).DefaultCodegen.fromOperation, add mapped parameterdataTypetokens toop.importswhen present inimportMapping, so fully qualified imports are emitted.org.myorg.MyCustomIdandorg.myorg.MyCustomKeyare generated inSomeApi.javaandDummy.java.org.springframework.core.io.Resource; Kotlin Javalin importsio.javalin.http.UploadedFile; Kotlin Ktor importsio.ktor.http.content.PartData.FileItem; Groovy addsjava.io.File.Written for commit 3a6f08c. Summary will update on new commits.