Skip to content

Commit

Permalink
better handling of api response
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Oct 28, 2024
1 parent 836d426 commit 5377377
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4331,7 +4331,7 @@ protected ApiResponse findMethodResponse(ApiResponses responses) {
if (code == null) {
return null;
}
return responses.get(code);
return ModelUtils.getReferencedApiResponse(openAPI, responses.get(code));
}

/**
Expand Down Expand Up @@ -4363,7 +4363,8 @@ protected void handleMethodResponse(Operation operation,
CodegenOperation op,
ApiResponse methodResponse,
Map<String, String> schemaMappings) {
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, methodResponse));
ApiResponse response = ModelUtils.getReferencedApiResponse(openAPI, methodResponse);
Schema responseSchema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, response));

if (responseSchema != null) {
CodegenProperty cm = fromProperty("response", responseSchema, false);
Expand Down Expand Up @@ -4416,7 +4417,7 @@ protected void handleMethodResponse(Operation operation,
}
op.returnProperty = cm;
}
addHeaders(methodResponse, op.responseHeaders);
addHeaders(response, op.responseHeaders);
}

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

for (String statusCode : operation.getResponses().keySet()) {
ApiResponse apiResponse = operation.getResponses().get(statusCode);
ApiResponse apiResponse = ModelUtils.getReferencedApiResponse(openAPI, operation.getResponses().get(statusCode));
Schema schema = unaliasSchema(ModelUtils.getSchemaFromResponse(openAPI, apiResponse));
if (schema == null) {
// void response
continue;
}

Expand Down Expand Up @@ -5142,7 +5144,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
parameterModelName = getParameterDataType(parameter, parameterSchema);
CodegenProperty prop;
if (this instanceof RustServerCodegen) {
// for rust server, we need to do somethings special as it uses
// for rust server, we need to do something special as it uses
// $ref (e.g. #components/schemas/Pet) to determine whether it's a model
prop = fromProperty(parameter.getName(), parameterSchema, false);
} else if (getUseInlineModelResolver()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
}

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

if (Objects.nonNull(resp.getExtensions()) && !resp.getExtensions().isEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private void collectEnumSchemas(Operation operation) {
if (operation.getResponses() != null) {
for (Map.Entry<String, ApiResponse> operationGetResponsesEntry : operation.getResponses().entrySet()) {
String s = operationGetResponsesEntry.getKey();
ApiResponse apiResponse = operationGetResponsesEntry.getValue();
ApiResponse apiResponse = ModelUtils.getReferencedApiResponse(openAPI, operationGetResponsesEntry.getValue());
if (apiResponse.getContent() != null) {
Content content = apiResponse.getContent();
for (String p : content.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
} else {
original = operation.getResponses().get(rsp.code);
}
original = ModelUtils.getReferencedApiResponse(openAPI, original);

// Create a unique responseID for this response, if one is not already specified with the "x-response-id" extension
if (!rsp.vendorExtensions.containsKey("x-response-id")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
} else {
original = operation.getResponses().get(rsp.code);
}
original = ModelUtils.getReferencedApiResponse(openAPI, original);
String[] words = rsp.message.split("[^A-Za-z ]");

// Create a unique responseID for this response.
Expand Down

0 comments on commit 5377377

Please sign in to comment.