Skip to content

Commit e1de801

Browse files
Merge branch 'OpenAPITools:master' into single-request-parameter-builder
2 parents 074b355 + 1311107 commit e1de801

506 files changed

Lines changed: 4308 additions & 1483 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
103103
|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|
104104
|useOptional|Use Optional container for optional parameters| |false|
105105
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
106+
|useSealed|Whether to generate sealed model interfaces and classes| |false|
106107
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
107108
|useSpringController|Annotate the generated API as a Spring Controller| |false|
108109
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|

docs/generators/protobuf-schema.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
1919
| Option | Description | Values | Default |
2020
| ------ | ----------- | ------ | ------- |
2121
|numberedFieldNumberList|Field numbers in order.| |false|
22-
|startEnumsWithUnknown|Introduces "UNKNOWN" as the first element of enumerations.| |false|
22+
|startEnumsWithUnspecified|Introduces "UNSPECIFIED" as the first element of enumerations.| |false|
2323

2424
## IMPORT MAPPING
2525

docs/generators/rust-axum.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,16 @@ These options may be applied as additional-properties (cli) or configOptions (pl
209209
|Union|✗|OAS3
210210
|allOf|✗|OAS2,OAS3
211211
|anyOf|✗|OAS3
212-
|oneOf||OAS3
212+
|oneOf||OAS3
213213
|not|✗|OAS3
214214

215215
### Security Feature
216216
| Name | Supported | Defined By |
217217
| ---- | --------- | ---------- |
218-
|BasicAuth||OAS2,OAS3
218+
|BasicAuth||OAS2,OAS3
219219
|ApiKey|✓|OAS2,OAS3
220220
|OpenIDConnect|✗|OAS3
221-
|BearerToken||OAS3
221+
|BearerToken||OAS3
222222
|OAuth2_Implicit|✗|OAS2,OAS3
223223
|OAuth2_Password|✗|OAS2,OAS3
224224
|OAuth2_ClientCredentials|✗|OAS2,OAS3

docs/generators/spring.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
9696
|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|
9797
|useOptional|Use Optional container for optional parameters| |false|
9898
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
99+
|useSealed|Whether to generate sealed model interfaces and classes| |false|
99100
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot 3.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
100101
|useSpringController|Annotate the generated API as a Spring Controller| |false|
101102
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|

flake.lock

Lines changed: 24 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/OpenApiGeneratorPlugin.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class OpenApiGeneratorPlugin : Plugin<Project> {
9898
outputDir.set(generate.outputDir)
9999
inputSpec.set(generate.inputSpec)
100100
inputSpecRootDirectory.set(generate.inputSpecRootDirectory)
101+
inputSpecRootDirectorySkipMerge.set(generate.inputSpecRootDirectorySkipMerge)
101102
remoteInputSpec.set(generate.remoteInputSpec)
102103
templateDir.set(generate.templateDir)
103104
templateResourcePath.set(generate.templateResourcePath)

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/extensions/OpenApiGeneratorGenerateExtension.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,28 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
5151

5252
/**
5353
* The Open API 2.0/3.x specification location.
54+
*
55+
* Be default, Gradle will treat the openApiGenerate task as up-to-date based only on this file, regardless of
56+
* changes to any $ref referenced files. Use the `inputSpecRootDirectory` property to have Gradle track changes to
57+
* an entire directory of spec files.
5458
*/
5559
val inputSpec = project.objects.property<String>()
5660

5761
/**
58-
* Local root folder with spec files
62+
* Local root folder with spec files.
63+
*
64+
* By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the
65+
* `inputSpecRootDirectorySkipMerge` property.
5966
*/
6067
val inputSpecRootDirectory = project.objects.property<String>()
6168

69+
/**
70+
* Skip bundling all spec files into a merged spec file, if true.
71+
*
72+
* Default false.
73+
*/
74+
val inputSpecRootDirectorySkipMerge = project.objects.property<Boolean>()
75+
6276
/**
6377
* The remote Open API 2.0/3.x specification URL location.
6478
*/
@@ -400,6 +414,7 @@ open class OpenApiGeneratorGenerateExtension(project: Project) {
400414
@Suppress("MemberVisibilityCanBePrivate")
401415
fun applyDefaults() {
402416
releaseNote.set("Minor update")
417+
inputSpecRootDirectorySkipMerge.set(false)
403418
modelNamePrefix.set("")
404419
modelNameSuffix.set("")
405420
apiNameSuffix.set("")

modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,34 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
106106

107107
/**
108108
* The Open API 2.0/3.x specification location.
109+
*
110+
* Be default, Gradle will treat the openApiGenerate task as up-to-date based only on this file, regardless of
111+
* changes to any $ref referenced files. Use the `inputSpecRootDirectory` property to have Gradle track changes to
112+
* an entire directory of spec files.
109113
*/
110114
@Optional
111115
@get:InputFile
112116
@PathSensitive(PathSensitivity.RELATIVE)
113117
val inputSpec = project.objects.property<String>()
114118

115119
/**
116-
* Local root folder with spec files
120+
* Local root folder with spec files.
121+
*
122+
* By default, a merged spec file will be generated based on the contents of the directory. To disable this, set the
123+
* `inputSpecRootDirectorySkipMerge` property.
117124
*/
118125
@Optional
119126
@get:InputDirectory
120127
@PathSensitive(PathSensitivity.RELATIVE)
121128
val inputSpecRootDirectory = project.objects.property<String>();
122129

130+
/**
131+
* Skip bundling all spec files into a merged spec file, if true.
132+
*/
133+
@Input
134+
@Optional
135+
val inputSpecRootDirectorySkipMerge = project.objects.property<Boolean>()
136+
123137
/**
124138
* Name of the file that will contain all merged specs
125139
*/
@@ -625,9 +639,16 @@ open class GenerateTask @Inject constructor(private val objectFactory: ObjectFac
625639
}
626640

627641
inputSpecRootDirectory.ifNotEmpty { inputSpecRootDirectoryValue ->
628-
run {
629-
resolvedInputSpec = MergedSpecBuilder(inputSpecRootDirectoryValue, mergedFileName.getOrElse("merged")).buildMergedSpec()
630-
logger.info("Merge input spec would be used - {}", resolvedInputSpec)
642+
val skipMerge = inputSpecRootDirectorySkipMerge.get()
643+
val runMergeSpec = !skipMerge
644+
if (runMergeSpec) {
645+
run {
646+
resolvedInputSpec = MergedSpecBuilder(
647+
inputSpecRootDirectoryValue,
648+
mergedFileName.getOrElse("merged")
649+
).buildMergedSpec()
650+
logger.info("Merge input spec would be used - {}", resolvedInputSpec)
651+
}
631652
}
632653
}
633654

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class CodegenModel implements IJsonSchemaValidationProperties {
5959
public Set<String> oneOf = new TreeSet<>();
6060
public Set<String> allOf = new TreeSet<>();
6161

62+
// direct descendants that are allowed to extend the current model
63+
public List<String> permits = new ArrayList<>();
64+
6265
// The schema name as written in the OpenAPI document
6366
// If it's a reserved word, it will be escaped.
6467
@Getter @Setter
@@ -922,6 +925,7 @@ public boolean equals(Object o) {
922925
Objects.equals(parentModel, that.parentModel) &&
923926
Objects.equals(interfaceModels, that.interfaceModels) &&
924927
Objects.equals(children, that.children) &&
928+
Objects.equals(permits, that.permits) &&
925929
Objects.equals(anyOf, that.anyOf) &&
926930
Objects.equals(oneOf, that.oneOf) &&
927931
Objects.equals(allOf, that.allOf) &&
@@ -975,7 +979,7 @@ public boolean equals(Object o) {
975979
@Override
976980
public int hashCode() {
977981
return Objects.hash(getParent(), getParentSchema(), getInterfaces(), getAllParents(), getParentModel(),
978-
getInterfaceModels(), getChildren(), anyOf, oneOf, allOf, getName(), getSchemaName(), getClassname(), getTitle(),
982+
getInterfaceModels(), getChildren(), permits, anyOf, oneOf, allOf, getName(), getSchemaName(), getClassname(), getTitle(),
979983
getDescription(), getClassVarName(), getModelJson(), getDataType(), getXmlPrefix(), getXmlNamespace(),
980984
getXmlName(), getClassFilename(), getUnescapedDescription(), getDiscriminator(), getDefaultValue(),
981985
getArrayModelType(), isAlias, isString, isInteger, isLong, isNumber, isNumeric, isFloat, isDouble,
@@ -1005,6 +1009,7 @@ public String toString() {
10051009
sb.append(", allParents=").append(allParents);
10061010
sb.append(", parentModel=").append(parentModel);
10071011
sb.append(", children=").append(children != null ? children.size() : "[]");
1012+
sb.append(", permits=").append(permits != null ? permits.size() : "[]");
10081013
sb.append(", anyOf=").append(anyOf);
10091014
sb.append(", oneOf=").append(oneOf);
10101015
sb.append(", allOf=").append(allOf);

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,25 @@ public Map<String, ModelsMap> updateAllModels(Map<String, ModelsMap> objs) {
621621

622622
// Let parent know about all its children
623623
for (Map.Entry<String, CodegenModel> allModelsEntry : allModels.entrySet()) {
624-
String name = allModelsEntry.getKey();
625624
CodegenModel cm = allModelsEntry.getValue();
626625
CodegenModel parent = allModels.get(cm.getParent());
626+
if (parent != null) {
627+
if (!parent.permits.contains(cm.classname) && parent.permits.stream()
628+
.noneMatch(name -> name.equals(cm.getName()))) {
629+
parent.permits.add(cm.classname);
630+
}
631+
}
627632
// if a discriminator exists on the parent, don't add this child to the inheritance hierarchy
628633
// TODO Determine what to do if the parent discriminator name == the grandparent discriminator name
629634
while (parent != null) {
630635
if (parent.getChildren() == null) {
631636
parent.setChildren(new ArrayList<>());
632637
}
633-
parent.getChildren().add(cm);
638+
if (parent.getChildren().stream().map(CodegenModel::getName)
639+
.noneMatch(name -> name.equals(cm.getName()))) {
640+
parent.getChildren().add(cm);
641+
}
642+
634643
parent.hasChildren = true;
635644
Schema parentSchema = this.openAPI.getComponents().getSchemas().get(parent.schemaName);
636645
if (parentSchema == null) {
@@ -2704,7 +2713,6 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<S
27042713
LOGGER.debug("{} (anyOf schema) already has `{}` defined and therefore it's skipped.", m.name, languageType);
27052714
} else {
27062715
m.anyOf.add(languageType);
2707-
27082716
}
27092717
} else if (composed.getOneOf() != null) {
27102718
if (m.oneOf.contains(languageType)) {
@@ -2751,6 +2759,9 @@ protected void updateModelForComposedSchema(CodegenModel m, Schema schema, Map<S
27512759
m.anyOf.add(modelName);
27522760
} else if (composed.getOneOf() != null) {
27532761
m.oneOf.add(modelName);
2762+
if (!m.permits.contains(modelName)) {
2763+
m.permits.add(modelName);
2764+
}
27542765
} else if (composed.getAllOf() != null) {
27552766
m.allOf.add(modelName);
27562767
} else {

0 commit comments

Comments
 (0)