Skip to content

Commit 254a558

Browse files
committed
resolved conflicts
2 parents 9df0c03 + 67af02c commit 254a558

File tree

457 files changed

+11997
-1602
lines changed

Some content is hidden

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

457 files changed

+11997
-1602
lines changed

.github/workflows/samples-kotlin-client.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
sample:
2121
# client
2222
- samples/client/petstore/kotlin
23+
- samples/client/petstore/kotlin-explicit
2324
- samples/client/petstore/kotlin-gson
2425
- samples/client/petstore/kotlin-jackson
2526
- samples/client/petstore/kotlin-model-prefix-type-mappings

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in
632632
- [CAM](https://www.cam-inc.co.jp/)
633633
- [Camptocamp](https://www.camptocamp.com/en)
634634
- [Carlsberg Group](https://www.carlsberggroup.com/)
635+
- [CERN](https://home.cern/)
635636
- [Christopher Queen Consulting](https://www.christopherqueenconsulting.com/)
636637
- [Cisco](https://www.cisco.com/)
637638
- [codecentric AG](https://www.codecentric.de/)

bin/configs/kotlin-explicit.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
generatorName: kotlin
2+
outputDir: samples/client/petstore/kotlin-explicit
3+
inputSpec: modules/openapi-generator/src/test/resources/2_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/kotlin-client
5+
additionalProperties:
6+
artifactId: kotlin-petstore-explicit
7+
explicitApi: "true"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
generatorName: rust
2+
outputDir: samples/client/petstore/rust/reqwest-trait/petstore
3+
library: reqwest-trait
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/rust
6+
additionalProperties:
7+
topLevelApiClient: true
8+
packageName: petstore-reqwest
9+
mockall: true
10+
enumNameMappings:
11+
delivered: shipped

docs/faq-generators.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,28 @@ First you implement the `OpenAPIInterceptor` protocol.
350350
public class BearerOpenAPIInterceptor: OpenAPIInterceptor {
351351
public init() {}
352352
353-
public func intercept(urlRequest: URLRequest, urlSession: URLSessionProtocol, openAPIClient: OpenAPIClient, completion: @escaping (Result<URLRequest, any Error>) -> Void) {
353+
public func intercept<T>(urlRequest: URLRequest, urlSession: URLSessionProtocol, requestBuilder: RequestBuilder<T>, completion: @escaping (Result<URLRequest, any Error>) -> Void) {
354+
355+
guard requestBuilder.requiresAuthentication else {
356+
// no authentication required
357+
completion(.success(urlRequest))
358+
return
359+
}
360+
354361
refreshTokenIfDoesntExist { token in
355362
356363
// Change the current url request
357364
var newUrlRequest = urlRequest
358365
newUrlRequest.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
359366
360367
// Change the global headers
361-
openAPIClient.customHeaders["Authorization"] = "Bearer \(token)"
368+
requestBuilder.openAPIClient.customHeaders["Authorization"] = "Bearer \(token)"
362369
363370
completion(.success(newUrlRequest))
364371
}
365372
}
366373
367-
public func retry(urlRequest: URLRequest, urlSession: URLSessionProtocol, openAPIClient: OpenAPIClient, data: Data?, response: URLResponse, error: Error, completion: @escaping (OpenAPIInterceptorRetry) -> Void) {
374+
public func retry<T>(urlRequest: URLRequest, urlSession: URLSessionProtocol, requestBuilder: RequestBuilder<T>, data: Data?, response: URLResponse?, error: Error, completion: @escaping (OpenAPIInterceptorRetry) -> Void) {
368375
// We will analyse the response to see if it's a 401, and if it's a 401, we will refresh the token and retry the request
369376
refreshTokenIfUnauthorizedRequestResponse(
370377
data: data,
@@ -375,7 +382,7 @@ public class BearerOpenAPIInterceptor: OpenAPIInterceptor {
375382
if wasTokenRefreshed, let newToken = newToken {
376383
377384
// Change the global headers
378-
openAPIClient.customHeaders["Authorization"] = "Bearer \(newToken)"
385+
requestBuilder.openAPIClient.customHeaders["Authorization"] = "Bearer \(newToken)"
379386
380387
completion(.retry)
381388
} else {
@@ -397,7 +404,7 @@ public class BearerOpenAPIInterceptor: OpenAPIInterceptor {
397404
}
398405
}
399406
400-
func refreshTokenIfUnauthorizedRequestResponse(data: Data?, response: URLResponse, error: Error, completionHandler: @escaping (Bool, String?) -> Void) {
407+
func refreshTokenIfUnauthorizedRequestResponse(data: Data?, response: URLResponse?, error: Error, completionHandler: @escaping (Bool, String?) -> Void) {
401408
if let response = response as? HTTPURLResponse, response.statusCode == 401 {
402409
startRefreshingToken { token in
403410
completionHandler(true, token)

docs/generators/javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
4343
|sourceFolder|source folder for generated code| |src|
4444
|useInheritance|use JavaScript prototype chains &amp; delegation for inheritance| |true|
4545
|usePromises|use Promises as return values from the client API, instead of superagent callbacks| |false|
46+
|useURLSearchParams|use JS build-in UrlSearchParams, instead of deprecated npm lib 'querystring'| |true|
4647

4748
## IMPORT MAPPING
4849

docs/generators/kotlin.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2525
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd></dl>|list|
2626
|dateLibrary|Option. Date library to use|<dl><dt>**threetenbp-localdatetime**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, for legacy app only)</dd><dt>**kotlinx-datetime**</dt><dd>kotlinx-datetime (preferred for multiplatform)</dd><dt>**string**</dt><dd>String</dd><dt>**java8-localdatetime**</dt><dd>Java 8 native JSR310 (jvm only, for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (jvm only, preferred for jdk 1.8+)</dd><dt>**threetenbp**</dt><dd>Threetenbp - Backport of JSR310 (jvm only, preferred for jdk &lt; 1.8)</dd></dl>|java8|
2727
|enumPropertyNaming|Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'| |original|
28+
|explicitApi|Generates code with explicit access modifiers to comply with Kotlin Explicit API Mode.| |false|
2829
|failOnUnknownProperties|Fail Jackson de-serialization on unknown properties| |false|
2930
|generateOneOfAnyOfWrappers|Generate oneOf, anyOf schemas as wrappers.| |false|
3031
|generateRoomModels|Generate Android Room database models in addition to API models (JVM Volley library only)| |false|
@@ -34,6 +35,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3435
|mapFileBinaryToByteArray|Map File and Binary to ByteArray (default: false)| |false|
3536
|modelMutable|Create mutable models| |false|
3637
|moshiCodeGen|Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info.| |false|
38+
|nonPublicApi|Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.| |false|
3739
|nullableReturnType|Nullable return type| |false|
3840
|omitGradlePluginVersions|Whether to declare Gradle plugin versions in build files.| |false|
3941
|omitGradleWrapper|Whether to omit Gradle wrapper for creating a sub project.| |false|

docs/generators/rust.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2222
|bestFitInt|Use best fitting integer type where minimum or maximum is set| |false|
2323
|enumNameSuffix|Suffix that will be appended to all enum names.| ||
2424
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
25-
|library|library template (sub-template) to use.|<dl><dt>**hyper**</dt><dd>HTTP client: Hyper (v1.x).</dd><dt>**hyper0x**</dt><dd>HTTP client: Hyper (v0.x).</dd><dt>**reqwest**</dt><dd>HTTP client: Reqwest.</dd></dl>|reqwest|
25+
|library|library template (sub-template) to use.|<dl><dt>**hyper**</dt><dd>HTTP client: Hyper (v1.x).</dd><dt>**hyper0x**</dt><dd>HTTP client: Hyper (v0.x).</dd><dt>**reqwest**</dt><dd>HTTP client: Reqwest.</dd><dt>**reqwest-trait**</dt><dd>HTTP client: Reqwest (trait based).</dd></dl>|reqwest|
26+
|mockall|Adds `#[automock]` from the mockall crate to api traits. This option is for 'reqwest-trait' library only| |false|
2627
|packageName|Rust package name (convention: lowercase).| |openapi|
2728
|packageVersion|Rust package version.| |1.0.0|
2829
|preferUnsignedInt|Prefer unsigned integers where minimum value is &gt;= 0| |false|
2930
|supportAsync|If set, generate async function call instead. This option is for 'reqwest' library only| |true|
30-
|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' library only| |false|
31-
|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' library only| |false|
32-
|supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' library only and requires the 'supportAsync' option| |false|
31+
|supportMiddleware|If set, add support for reqwest-middleware. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
32+
|supportMultipleResponses|If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' and 'reqwest-trait' library only| |false|
33+
|supportTokenSource|If set, add support for google-cloud-token. This option is for 'reqwest' and 'reqwest-trait' library only and requires the 'supportAsync' option| |false|
34+
|topLevelApiClient|Creates a top level `Api` trait and `ApiClient` struct that contain all Apis. This option is for 'reqwest-trait' library only| |false|
35+
|useBonBuilder|Use the bon crate for building parameter types. This option is for the 'reqwest-trait' library only| |false|
3336
|useSingleRequestParameter|Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.| |false|
3437
|withAWSV4Signature|whether to include AWS v4 signature support| |false|
3538

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

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3861,8 +3861,29 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
38613861
}
38623862

38633863
Schema original = null;
3864+
// process the dereference schema if it's a ref to allOf with a single item
3865+
// and certain field(s) (e.g. description, readyOnly, etc) is set
3866+
if (p.get$ref() != null) {
3867+
Schema derefSchema = ModelUtils.getReferencedSchema(openAPI, p);
3868+
if (ModelUtils.isAllOfWithSingleItem(derefSchema) && (
3869+
derefSchema.getReadOnly() != null ||
3870+
derefSchema.getWriteOnly() != null ||
3871+
derefSchema.getDeprecated() != null ||
3872+
derefSchema.getDescription() != null ||
3873+
derefSchema.getMaxLength() != null ||
3874+
derefSchema.getMinLength() != null ||
3875+
derefSchema.getMinimum() != null ||
3876+
derefSchema.getMaximum() != null ||
3877+
derefSchema.getMaximum() != null ||
3878+
derefSchema.getMinItems() != null ||
3879+
derefSchema.getTitle() != null
3880+
)) {
3881+
p = ModelUtils.getReferencedSchema(openAPI, p);
3882+
}
3883+
}
3884+
38643885
// check if it's allOf (only 1 sub schema) with or without default/nullable/etc set in the top level
3865-
if (ModelUtils.isAllOf(p) && p.getAllOf().size() == 1) {
3886+
if (ModelUtils.isAllOfWithSingleItem(p)) {
38663887
if (p.getAllOf().get(0) instanceof Schema) {
38673888
original = p;
38683889
p = (Schema) p.getAllOf().get(0);
@@ -4331,7 +4352,7 @@ protected ApiResponse findMethodResponse(ApiResponses responses) {
43314352
if (code == null) {
43324353
return null;
43334354
}
4334-
return responses.get(code);
4355+
return ModelUtils.getReferencedApiResponse(openAPI, responses.get(code));
43354356
}
43364357

43374358
/**
@@ -4363,7 +4384,8 @@ protected void handleMethodResponse(Operation operation,
43634384
CodegenOperation op,
43644385
ApiResponse methodResponse,
43654386
Map<String, String> schemaMappings) {
4366-
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, methodResponse));
4387+
ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, methodResponse);
4388+
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, response));
43674389

43684390
if (responseSchema != null) {
43694391
CodegenProperty cm = fromProperty("response", responseSchema, false);
@@ -4416,7 +4438,7 @@ protected void handleMethodResponse(Operation operation,
44164438
}
44174439
op.returnProperty = cm;
44184440
}
4419-
addHeaders(methodResponse, op.responseHeaders);
4441+
addHeaders(response, op.responseHeaders);
44204442
}
44214443

44224444
/**
@@ -4482,7 +4504,7 @@ public CodegenOperation fromOperation(String path,
44824504
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
44834505
for (Map.Entry<String, ApiResponse> operationGetResponsesEntry : operation.getResponses().entrySet()) {
44844506
String key = operationGetResponsesEntry.getKey();
4485-
ApiResponse response = operationGetResponsesEntry.getValue();
4507+
ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, operationGetResponsesEntry.getValue());
44864508
addProducesInfo(response, op);
44874509
CodegenResponse r = fromResponse(key, response);
44884510
Map<String, Header> headers = response.getHeaders();
@@ -4552,9 +4574,10 @@ public CodegenOperation fromOperation(String path,
45524574
List<Map<String, String>> examples = new ArrayList<>();
45534575

45544576
for (String statusCode : operation.getResponses().keySet()) {
4555-
ApiResponse apiResponse = operation.getResponses().get(statusCode);
4577+
ApiResponse apiResponse = ModelUtils.getReferencedApiResponse(openAPI, operation.getResponses().get(statusCode));
45564578
Schema schema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, apiResponse));
45574579
if (schema == null) {
4580+
// void response
45584581
continue;
45594582
}
45604583

@@ -4751,7 +4774,7 @@ public CodegenOperation fromOperation(String path,
47514774
op.hasRequiredParams = op.requiredParams.size() > 0;
47524775

47534776
// check if the operation has only a single parameter
4754-
op.hasSingleParam = op.allParams.size() == 1;
4777+
op.hasSingleParam = op.allParams.size() == 1;
47554778

47564779
// set Restful Flag
47574780
op.isRestfulShow = op.isRestfulShow();
@@ -5142,7 +5165,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
51425165
parameterModelName = getParameterDataType(parameter, parameterSchema);
51435166
CodegenProperty prop;
51445167
if (this instanceof RustServerCodegen) {
5145-
// for rust server, we need to do somethings special as it uses
5168+
// for rust server, we need to do something special as it uses
51465169
// $ref (e.g. #components/schemas/Pet) to determine whether it's a model
51475170
prop = fromProperty(parameter.getName(), parameterSchema, false);
51485171
} else if (getUseInlineModelResolver()) {
@@ -6090,7 +6113,7 @@ private String uniqueCaseInsensitiveString(String value, Map<String, String> see
60906113
return seenValues.get(value);
60916114
}
60926115

6093-
Optional<Entry<String,String>> foundEntry = seenValues.entrySet().stream().filter(v -> v.getValue().toLowerCase(Locale.ROOT).equals(value.toLowerCase(Locale.ROOT))).findAny();
6116+
Optional<Entry<String, String>> foundEntry = seenValues.entrySet().stream().filter(v -> v.getValue().toLowerCase(Locale.ROOT).equals(value.toLowerCase(Locale.ROOT))).findAny();
60946117
if (foundEntry.isPresent()) {
60956118
int counter = 0;
60966119
String uniqueValue = value + "_" + counter;
@@ -8151,7 +8174,7 @@ protected boolean executePostProcessor(String[] commandArr) {
81518174
int exitValue = p.exitValue();
81528175
if (exitValue != 0) {
81538176
try (InputStreamReader inputStreamReader = new InputStreamReader(p.getErrorStream(), StandardCharsets.UTF_8);
8154-
BufferedReader br = new BufferedReader(inputStreamReader)) {
8177+
BufferedReader br = new BufferedReader(inputStreamReader)) {
81558178
StringBuilder sb = new StringBuilder();
81568179
String line;
81578180
while ((line = br.readLine()) != null) {

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void flatten(OpenAPI openAPI) {
107107

108108
flattenPaths();
109109
flattenComponents();
110+
flattenComponentResponses();
110111
}
111112

112113
/**
@@ -352,7 +353,7 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
352353
}
353354

354355
if (items == null) {
355-
LOGGER.debug("prefixItems in array schema is not supported at the moment: {}", schema.toString());
356+
LOGGER.debug("prefixItems in array schema is not supported at the moment: {}", schema.toString());
356357
return;
357358
}
358359
String schemaName = resolveModelName(items.getTitle(), modelPrefix + this.inlineSchemaOptions.get("ARRAY_ITEM_SUFFIX"));
@@ -568,6 +569,20 @@ private void flattenResponses(String modelName, Operation operation) {
568569
}
569570
}
570571

572+
/**
573+
* Flatten inline models in the responses section in the components.
574+
*/
575+
private void flattenComponentResponses() {
576+
Map<String, ApiResponse> apiResponses = openAPI.getComponents().getResponses();
577+
if (apiResponses == null) {
578+
return;
579+
}
580+
581+
for (Map.Entry<String, ApiResponse> entry : apiResponses.entrySet()) {
582+
flattenContent(entry.getValue().getContent(), null);
583+
}
584+
}
585+
571586
/**
572587
* Flattens properties of inline object schemas that belong to a composed schema into a
573588
* single flat list of properties. This is useful to generate a single or multiple

0 commit comments

Comments
 (0)