Skip to content

Commit 5377377

Browse files
committed
better handling of api response
1 parent 836d426 commit 5377377

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4331,7 +4331,7 @@ protected ApiResponse findMethodResponse(ApiResponses responses) {
43314331
if (code == null) {
43324332
return null;
43334333
}
4334-
return responses.get(code);
4334+
return ModelUtils.getReferencedApiResponse(openAPI, responses.get(code));
43354335
}
43364336

43374337
/**
@@ -4363,7 +4363,8 @@ protected void handleMethodResponse(Operation operation,
43634363
CodegenOperation op,
43644364
ApiResponse methodResponse,
43654365
Map<String, String> schemaMappings) {
4366-
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, methodResponse));
4366+
ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, methodResponse);
4367+
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, response));
43674368

43684369
if (responseSchema != null) {
43694370
CodegenProperty cm = fromProperty("response", responseSchema, false);
@@ -4416,7 +4417,7 @@ protected void handleMethodResponse(Operation operation,
44164417
}
44174418
op.returnProperty = cm;
44184419
}
4419-
addHeaders(methodResponse, op.responseHeaders);
4420+
addHeaders(response, op.responseHeaders);
44204421
}
44214422

44224423
/**
@@ -4482,7 +4483,7 @@ public CodegenOperation fromOperation(String path,
44824483
ApiResponse methodResponse = findMethodResponse(operation.getResponses());
44834484
for (Map.Entry<String, ApiResponse> operationGetResponsesEntry : operation.getResponses().entrySet()) {
44844485
String key = operationGetResponsesEntry.getKey();
4485-
ApiResponse response = operationGetResponsesEntry.getValue();
4486+
ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, operationGetResponsesEntry.getValue());
44864487
addProducesInfo(response, op);
44874488
CodegenResponse r = fromResponse(key, response);
44884489
Map<String, Header> headers = response.getHeaders();
@@ -4552,9 +4553,10 @@ public CodegenOperation fromOperation(String path,
45524553
List<Map<String, String>> examples = new ArrayList<>();
45534554

45544555
for (String statusCode : operation.getResponses().keySet()) {
4555-
ApiResponse apiResponse = operation.getResponses().get(statusCode);
4556+
ApiResponse apiResponse = ModelUtils.getReferencedApiResponse(openAPI, operation.getResponses().get(statusCode));
45564557
Schema schema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, apiResponse));
45574558
if (schema == null) {
4559+
// void response
45584560
continue;
45594561
}
45604562

@@ -5142,7 +5144,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
51425144
parameterModelName = getParameterDataType(parameter, parameterSchema);
51435145
CodegenProperty prop;
51445146
if (this instanceof RustServerCodegen) {
5145-
// for rust server, we need to do somethings special as it uses
5147+
// for rust server, we need to do something special as it uses
51465148
// $ref (e.g. #components/schemas/Pet) to determine whether it's a model
51475149
prop = fromProperty(parameter.getName(), parameterSchema, false);
51485150
} else if (getUseInlineModelResolver()) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
587587
}
588588

589589
for (Map.Entry<String, ApiResponse> responseEntry : operation.getResponses().entrySet()) {
590-
CodegenResponse r = fromResponse(responseEntry.getKey(), responseEntry.getValue());
590+
CodegenResponse r = fromResponse(responseEntry.getKey(), ModelUtils.getReferencedApiResponse(openAPI, responseEntry.getValue()));
591591
if (r.baseType != null &&
592592
!defaultIncludes.contains(r.baseType) &&
593593
!languageSpecificPrimitives.contains(r.baseType)) {
@@ -1056,6 +1056,7 @@ private Optional<OperationGrouping> extractOperationGrouping(CodegenOperation cg
10561056
* @return true if should be hidden, false otherwise
10571057
*/
10581058
private boolean shouldHideOperationResponse(ApiResponse resp) {
1059+
resp = ModelUtils.getReferencedApiResponse(openAPI, resp);
10591060
boolean hideOperationResponse = false;
10601061

10611062
if (Objects.nonNull(resp.getExtensions()) && !resp.getExtensions().isEmpty()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private void collectEnumSchemas(Operation operation) {
345345
if (operation.getResponses() != null) {
346346
for (Map.Entry<String, ApiResponse> operationGetResponsesEntry : operation.getResponses().entrySet()) {
347347
String s = operationGetResponsesEntry.getKey();
348-
ApiResponse apiResponse = operationGetResponsesEntry.getValue();
348+
ApiResponse apiResponse = ModelUtils.getReferencedApiResponse(openAPI, operationGetResponsesEntry.getValue());
349349
if (apiResponse.getContent() != null) {
350350
Content content = apiResponse.getContent();
351351
for (String p : content.keySet()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
475475
} else {
476476
original = operation.getResponses().get(rsp.code);
477477
}
478+
original = ModelUtils.getReferencedApiResponse(openAPI, original);
478479

479480
// Create a unique responseID for this response, if one is not already specified with the "x-response-id" extension
480481
if (!rsp.vendorExtensions.containsKey("x-response-id")) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
656656
} else {
657657
original = operation.getResponses().get(rsp.code);
658658
}
659+
original = ModelUtils.getReferencedApiResponse(openAPI, original);
659660
String[] words = rsp.message.split("[^A-Za-z ]");
660661

661662
// Create a unique responseID for this response.

0 commit comments

Comments
 (0)