Skip to content

Commit e74e0e4

Browse files
Merge branch 'OpenAPITools:master' into master
2 parents 05fdd18 + 930fc30 commit e74e0e4

82 files changed

Lines changed: 2098 additions & 74 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/generators/java-camel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
104104
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
105105
|sourceFolder|source folder for generated code| |src/main/java|
106106
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
107-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot or spring-http-interface.| |false|
107+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation.| |false|
108108
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
109109
|title|server title name or client service name| |OpenAPI Spring|
110110
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|

docs/generators/jaxrs-cxf-cdi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8585
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8686
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8787
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
88+
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
8889
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
8990
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9091
|useTags|use tags for creating interface and controller classnames| |false|

docs/generators/jaxrs-spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8686
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8787
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8888
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
89+
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
8990
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
9091
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9192
|useTags|use tags for creating interface and controller classnames| |false|

docs/generators/kotlin-spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5858
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null|
5959
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null|
6060
|sourceFolder|source folder for generated code| |src/main/kotlin|
61-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot or spring-declarative-http-interface.| |false|
61+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation.| |false|
6262
|title|server title name or client service name| |OpenAPI Kotlin Spring|
6363
|useBeanValidation|Use BeanValidation API annotations to validate data types| |true|
6464
|useFeignClientUrl|Whether to generate Feign client with url parameter.| |true|

docs/generators/spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9797
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
9898
|sourceFolder|source folder for generated code| |src/main/java|
9999
|springApiVersion|Value for 'version' attribute in @RequestMapping (for Spring 7 and above).| |null|
100-
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation. Only applies when library=spring-boot or spring-http-interface.| |false|
100+
|substituteGenericPagedModel|Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' pagination-metadata property) and replace their generated references with PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata schema are suppressed from code generation.| |false|
101101
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
102102
|title|server title name or client service name| |OpenAPI Spring|
103103
|unhandledException|Declare operation methods to throw a generic exception and allow unhandled exceptions (useful for Spring `@ControllerAdvice` directives).| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
5353
public static final String USE_MUTINY = "useMutiny";
5454
public static final String OPEN_API_SPEC_FILE_LOCATION = "openApiSpecFileLocation";
5555
public static final String GENERATE_JSON_CREATOR = "generateJsonCreator";
56+
public static final String USE_QUARKUS_SECURITY_ANNOTATIONS = "useQuarkusSecurityAnnotations";
5657

5758
public static final String QUARKUS_LIBRARY = "quarkus";
5859
public static final String THORNTAIL_LIBRARY = "thorntail";
@@ -68,6 +69,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
6869
private boolean useSwaggerV3Annotations = false;
6970
private boolean useMicroProfileOpenAPIAnnotations = false;
7071
private boolean useMutiny = false;
72+
private boolean useQuarkusSecurityAnnotations = false;
7173

7274
@Getter @Setter
7375
protected boolean generateJsonCreator = true;
@@ -147,6 +149,7 @@ public JavaJAXRSSpecServerCodegen() {
147149
cliOptions.add(CliOption.newString(OPEN_API_SPEC_FILE_LOCATION, "Location where the file containing the spec will be generated in the output folder. No file generated when set to null or empty string."));
148150
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
149151
cliOptions.add(CliOption.newBoolean(USE_MUTINY, "Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.", useMutiny));
152+
cliOptions.add(CliOption.newBoolean(USE_QUARKUS_SECURITY_ANNOTATIONS, "Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.", useQuarkusSecurityAnnotations));
150153
cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate @JsonCreator constructor for required properties.", generateJsonCreator));
151154
}
152155

@@ -189,6 +192,10 @@ public void processOpts() {
189192
convertPropertyToBooleanAndWriteBack(USE_MUTINY, value -> useMutiny = value);
190193
}
191194

195+
if (QUARKUS_LIBRARY.equals(library)) {
196+
convertPropertyToBooleanAndWriteBack(USE_QUARKUS_SECURITY_ANNOTATIONS, value -> useQuarkusSecurityAnnotations = value);
197+
}
198+
192199
convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator);
193200

194201
if (additionalProperties.containsKey(OPEN_API_SPEC_FILE_LOCATION)) {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public KotlinSpringServerCodegen() {
308308
"Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' "
309309
+ "pagination-metadata property) and replace their generated references with "
310310
+ "PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata "
311-
+ "schema are suppressed from code generation. Only applies when library=spring-boot or spring-declarative-http-interface.",
311+
+ "schema are suppressed from code generation.",
312312
substituteGenericPagedModel);
313313
addSwitch(COMPANION_OBJECT, "Whether to generate companion objects in data classes, enabling companion extensions.", companionObject);
314314
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
@@ -750,7 +750,7 @@ public void processOpts() {
750750
this.setGeneratePageableConstraintValidation(convertPropertyToBoolean(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION));
751751
}
752752
writePropertyBack(GENERATE_PAGEABLE_CONSTRAINT_VALIDATION, generatePageableConstraintValidation);
753-
if (additionalProperties.containsKey(SUBSTITUTE_GENERIC_PAGED_MODEL) && (library.equals(SPRING_BOOT) || library.equals(SPRING_DECLARATIVE_HTTP_INTERFACE_LIBRARY))) {
753+
if (additionalProperties.containsKey(SUBSTITUTE_GENERIC_PAGED_MODEL)) {
754754
this.setSubstituteGenericPagedModel(convertPropertyToBoolean(SUBSTITUTE_GENERIC_PAGED_MODEL));
755755
}
756756
writePropertyBack(SUBSTITUTE_GENERIC_PAGED_MODEL, substituteGenericPagedModel);
@@ -1211,7 +1211,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
12111211
}
12121212
}
12131213

1214-
if ((SPRING_BOOT.equals(library) || SPRING_DECLARATIVE_HTTP_INTERFACE_LIBRARY.equals(library)) && substituteGenericPagedModel) {
1214+
if (substituteGenericPagedModel) {
12151215
pagedModelRegistry = PagedModelScanUtils.scanPagedModels(openAPI);
12161216
if (!pagedModelRegistry.isEmpty()) {
12171217
boolean customMapping = importMapping.containsKey("PagedModel");

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ public GeneratorLanguage generatorLanguage() {
15301530

15311531
@Override
15321532
public String toEnumVarName(String name, String datatype) {
1533-
if (name.length() == 0) {
1533+
if (name.isEmpty()) {
15341534
return "EMPTY";
15351535
}
15361536

@@ -1539,8 +1539,9 @@ public String toEnumVarName(String name, String datatype) {
15391539
return (getSymbolName(name)).toUpperCase(Locale.ROOT);
15401540
}
15411541

1542-
// number
1543-
if ("Int16".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype) ||
1542+
if (name.matches("^\\d.*") || // any data type (including string) starting with a number
1543+
// numeric data type
1544+
"Int16".equals(datatype) || "Int32".equals(datatype) || "Int64".equals(datatype) ||
15441545
"UInt16".equals(datatype) || "UInt32".equals(datatype) || "UInt64".equals(datatype) ||
15451546
"Double".equals(datatype) || "Single".equals(datatype) || "Decimal".equals(datatype)) {
15461547
String varName = name;

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ public SpringCodegen() {
380380
"Detect schemas that represent paginated responses (an object with a 'content' array property and a 'page' "
381381
+ "pagination-metadata property) and replace their generated references with "
382382
+ "PagedModel<T>. By default this uses a generated type in the config package (default 'org.openapitools.configuration'), but `importMappings.PagedModel` can override it to a custom/FQCN-mapped type. The detected page schemas and the pagination metadata "
383-
+ "schema are suppressed from code generation. Only applies when library=spring-boot or spring-http-interface.",
383+
+ "schema are suppressed from code generation.",
384384
substituteGenericPagedModel));
385385

386386
}
@@ -591,9 +591,7 @@ public void processOpts() {
591591

592592
convertPropertyToBooleanAndWriteBack(ADDITIONAL_NOT_NULL_ANNOTATIONS, this::setAdditionalNotNullAnnotations);
593593

594-
if (SPRING_BOOT.equals(library) || SPRING_HTTP_INTERFACE.equals(library)) {
595-
convertPropertyToBooleanAndWriteBack(SUBSTITUTE_GENERIC_PAGED_MODEL, this::setSubstituteGenericPagedModel);
596-
}
594+
convertPropertyToBooleanAndWriteBack(SUBSTITUTE_GENERIC_PAGED_MODEL, this::setSubstituteGenericPagedModel);
597595

598596
if (SPRING_BOOT.equals(library)) {
599597
convertPropertyToBooleanAndWriteBack(AUTO_X_SPRING_PAGINATED, this::setAutoXSpringPaginated);
@@ -873,7 +871,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
873871
}
874872
}
875873

876-
if ((SPRING_BOOT.equals(library) || SPRING_HTTP_INTERFACE.equals(library)) && substituteGenericPagedModel) {
874+
if (substituteGenericPagedModel) {
877875
pagedModelRegistry = PagedModelScanUtils.scanPagedModels(openAPI);
878876
if (!pagedModelRegistry.isEmpty()) {
879877
boolean customMapping = importMapping.containsKey("PagedModel");

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptFetchClientCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,22 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
463463
}
464464
}
465465

466+
// Build a set of classnames that are oneOf models (union types)
467+
Set<String> oneOfModelNames = allModels.stream()
468+
.filter(m -> !m.oneOf.isEmpty())
469+
.map(m -> m.classname)
470+
.collect(Collectors.toSet());
471+
472+
// Mark models whose parent is a oneOf model — these cannot use
473+
// "interface X extends Parent" because TypeScript does not allow
474+
// an interface to extend a union type. They use
475+
// "type X = Parent & { ... }" instead.
476+
for (ExtendedCodegenModel m : allModels) {
477+
if (m.parent != null && oneOfModelNames.contains(m.parent)) {
478+
m.parentIsOneOf = true;
479+
}
480+
}
481+
466482
for (ExtendedCodegenModel rootModel : allModels) {
467483
for (String curImport : rootModel.imports) {
468484
boolean isModelImport = false;
@@ -1385,6 +1401,7 @@ public ExtendedCodegenProperty(CodegenProperty cp) {
13851401
this.xmlName = cp.xmlName;
13861402
this.xmlNamespace = cp.xmlNamespace;
13871403
this.isXmlWrapped = cp.isXmlWrapped;
1404+
this.setHasSanitizedName(cp.getHasSanitizedName());
13881405
}
13891406

13901407
@Override
@@ -1548,6 +1565,8 @@ public class ExtendedCodegenModel extends CodegenModel {
15481565
public Set<CodegenProperty> oneOfPrimitives = new HashSet<>();
15491566
@Getter @Setter
15501567
public CodegenDiscriminator.MappedModel selfReferencingDiscriminatorMapping;
1568+
@Getter @Setter
1569+
public boolean parentIsOneOf; // true when this model's parent is a oneOf union type
15511570

15521571
public boolean isEntity; // Is a model containing an "id" property marked as isUniqueId
15531572
public String returnPassthrough;

0 commit comments

Comments
 (0)