You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[kotlin][kotlin-spring] Add companionObject option to generate companion objects in data classes (#23176)
* [kotlin] Add companionObject option to generate companion objects in data classes
Add a new boolean CLI option `companionObject` (default: false) that generates
an empty `companion object { }` on all data class models, enabling users to add
companion extensions from outside the generated code.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* [kotlin-spring] Add companionObject option to generate companion objects in data classes
Extend the same companionObject option to the kotlin-spring server generator,
enabling companion extensions on generated Spring model classes.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* update spec, add tests
---------
Co-authored-by: Jeffrey Blayney <jeffrey.blayney@missionlane.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/generators/kotlin-spring.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
27
27
|autoXSpringPaginated|Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected.||false|
28
28
|basePackage|base package (invokerPackage) for generated code||org.openapitools|
29
29
|beanQualifiers|Whether to add fully-qualifier class names as bean qualifiers in @Component and @RestController annotations. May be used to prevent bean names clash if multiple generated libraries (contexts) added to single project.||false|
30
+
|companionObject|Whether to generate companion objects in data classes, enabling companion extensions.||false|
30
31
|configPackage|configuration package for generated code||org.openapitools.configuration|
31
32
|declarativeInterfaceReactiveMode|What type of reactive style to use in Spring Http declarative interface|<dl><dt>**coroutines**</dt><dd>Use kotlin-idiomatic 'suspend' functions</dd><dt>**reactor**</dt><dd>Use reactor return wrappers 'Mono' and 'Flux'</dd></dl>|coroutines|
32
33
|delegatePattern|Whether to generate the server files using the delegate pattern||false|
@@ -288,6 +291,8 @@ public KotlinClientCodegen() {
288
291
289
292
cliOptions.add(CliOption.newBoolean(GENERATE_ONEOF_ANYOF_WRAPPERS, "Generate oneOf, anyOf schemas as wrappers. Only `jvm-retrofit2`(library) with `gson` or `kotlinx_serialization`(serializationLibrary) support this option."));
290
293
294
+
cliOptions.add(CliOption.newBoolean(COMPANION_OBJECT, "Whether to generate companion objects in data classes, enabling companion extensions.", false));
@@ -265,6 +267,7 @@ public KotlinSpringServerCodegen() {
265
267
addOption(SCHEMA_IMPLEMENTS, "A map of single interface or a list of interfaces per schema name that should be implemented (serves similar purpose as `x-kotlin-implements`, but is fully decoupled from the api spec). Example: yaml `schemaImplements: {Pet: com.some.pack.WithId, Category: [com.some.pack.CategoryInterface], Dog: [com.some.pack.Canine, com.some.pack.OtherInterface]}` implements interfaces in schemas `Pet` (interface `com.some.pack.WithId`), `Category` (interface `com.some.pack.CategoryInterface`), `Dog`(interfaces `com.some.pack.Canine`, `com.some.pack.OtherInterface`)", "empty map");
266
268
addOption(SCHEMA_IMPLEMENTS_FIELDS, "A map of single field or a list of fields per schema name that should be prepended with `override` (serves similar purpose as `x-kotlin-implements-fields`, but is fully decoupled from the api spec). Example: yaml `schemaImplementsFields: {Pet: id, Category: [name, id], Dog: [bark, breed]}` marks fields to be prepended with `override` in schemas `Pet` (field `id`), `Category` (fields `name`, `id`) and `Dog` (fields `bark`, `breed`)", "empty map");
267
269
addSwitch(AUTO_X_SPRING_PAGINATED, "Automatically add x-spring-paginated to operations that have 'page', 'size', and 'sort' query parameters. When enabled, operations with all three parameters will have Pageable support automatically applied. Operations with x-spring-paginated explicitly set to false will not be auto-detected.", autoXSpringPaginated);
270
+
addSwitch(COMPANION_OBJECT, "Whether to generate companion objects in data classes, enabling companion extensions.", companionObject);
268
271
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
269
272
supportedLibraries.put(SPRING_CLOUD_LIBRARY,
270
273
"Spring-Cloud-Feign client with Spring-Boot auto-configured settings.");
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java
+29Lines changed: 29 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -4706,6 +4706,35 @@ public void testDeprecatedAnnotationOnController() throws IOException {
4706
4706
"@Deprecated(message=\"Operation is deprecated\") @RequestMapping("
0 commit comments