-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[JAVA-SPRING;KOTLIN-SPRING] - add possibility to override x-implements and x-kotlin-implements via config options. #22839
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
base: master
Are you sure you want to change the base?
[JAVA-SPRING;KOTLIN-SPRING] - add possibility to override x-implements and x-kotlin-implements via config options. #22839
Conversation
| }}{{#serializableModel}}{{! no newline | ||
| }}{{^vendorExtensions.x-kotlin-implements}}, Serializable{{/vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{#vendorExtensions.x-kotlin-implements}}, Serializable, {{! no newline | ||
| }}{{#-first}} {{{.}}}{{/-first}}{{! no newline | ||
| }}{{^-first}}, {{{.}}}{{/-first}}{{! no newline | ||
| }}{{/vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{/serializableModel}}{{! no newline | ||
| }}{{^serializableModel}}{{! no newline | ||
| }}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{/serializableModel}}{{! no newline | ||
| }}{{#vendorExtensions.x-kotlin-implements}}, {{{.}}}{{/vendorExtensions.x-kotlin-implements}}{{! <- serializableModel is also handled via x-kotlin-implements | ||
| }}{{/parent}}{{! no newline | ||
| }}{{^parent}}{{! no newline | ||
| }}{{#serializableModel}}{{! no newline | ||
| }}{{^vendorExtensions.x-kotlin-implements}} : Serializable{{/vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{#vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{#-first}} : Serializable, {{{.}}}{{/-first}}{{! no newline | ||
| }}{{^-first}}, {{{.}}}{{/-first}}{{! no newline | ||
| }}{{/vendorExtensions.x-kotlin-implements}}{{! no newline | ||
| }}{{/serializableModel}}{{! no newline | ||
| }}{{^serializableModel}}{{! no newline |
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.
I think this simplifications is pretty much worth it. I now handle adding the Serializable as one of the x-kotlin-implements items. That allows me to remove much of the mustache template complexity.
| {{#serializableModel}} | ||
| import java.io.Serializable | ||
| {{/serializableModel}} |
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.
No need as I now fully qualify the Serializable.
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.
2 issues found across 293 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name=".github/workflows/samples-jdk17.yaml">
<violation number="1" location=".github/workflows/samples-jdk17.yaml:57">
P2: New matrix sample lacks matching path filters, so changes to it won’t trigger this workflow.</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java:2021">
P2: Unsafe cast of x-implements to List<String> can throw ClassCastException when the vendor extension is defined as a scalar string (as seen in test resources).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
.../openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
Outdated
Show resolved
Hide resolved
|
Ok, I am pleasantly surprised by the cubic-dev-ai bot. Pretty cool stuff. |
Provides a flexible mechanism to:
x-implementsorx-kotlin-implements= hence no need to pre-process existing open api spec file.Implementation details:
Adds config options
xImplementsSkip(java-spring) andxKotlinImplementsSkipandxKotlinImplementsFieldsSkip(kotlin-spring) to allow specifying interfaces that should be EXCLUDED from implementation despite being requested via the vendor extensionsx-implements(java-spring) andx-kotlin-implements(kotlin-spring). This should help with reuse of a spec between server/client where the interfaces are not shared among both.Adds config options
schemaImplements(java-spring and kotlin-spring) andschemaImplementsFields(kotlin-spring) to allow specifying interfaces that should be IMPLEMENTED in a schema (similar functionality tox-implementsandx-kotlin-implementsbut fully decoupled from the open api spec)(in kotlin-spring) Imports
java.io.Serializableas fully qualified and simplifies the template logic by passing it as one of thex-kotlin-implementsitem.(in kotlin-spring) also fixes issue [BUG][KOTLIN][SPRING] Wildcard path generates invalid code #22756 (whether it is a valid bug is a matter of opinion, but fixing it is trivial and does not hurt anything)
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Adds config-driven controls to replace or skip x-implements/x-kotlin-implements and adds schema-level interface mapping for Java and Kotlin Spring. This lets you add, substitute, or skip interfaces per model without editing the OpenAPI spec.
New Features
Bug Fixes
Written for commit 9d6f082. Summary will update on new commits.