Skip to content

Commit

Permalink
Merge pull request swagger-api#1217 from swagger-api/issue-1174
Browse files Browse the repository at this point in the history
identify file type in api response schemas.
  • Loading branch information
HugoMario authored Nov 25, 2023
2 parents 1f0254f + 01bc481 commit a0a349a
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -2338,6 +2339,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
} else {
codegenResponse.baseType = codegenProperty.baseType;
}
if (isFileTypeSchema(responseSchema)) {
codegenResponse.getVendorExtensions().put(CodegenConstants.IS_FILE_EXT_NAME, Boolean.TRUE);
}
}
codegenResponse.dataType = codegenProperty.datatype;

Expand Down Expand Up @@ -4403,6 +4407,21 @@ protected void setParameterNullable(CodegenParameter parameter, CodegenProperty
parameter.nullable = property.nullable;
}

protected boolean isFileTypeSchema(Schema schema) {
final Schema fileTypeSchema;
if (StringUtils.isNotBlank(schema.get$ref())) {
fileTypeSchema = OpenAPIUtil.getSchemaFromRefSchema(schema, openAPI);
} else {
fileTypeSchema = schema;
}
if (fileTypeSchema.getProperties() != null) {
final Collection<Schema> propertySchemas = fileTypeSchema.getProperties().values();
return propertySchemas.stream().anyMatch(propertySchema -> "string".equalsIgnoreCase(propertySchema.getType())
&& "binary".equalsIgnoreCase(propertySchema.getFormat()));
}
return false;
}

@Override
public boolean needsUnflattenedSpec() {
return false;
Expand Down

0 comments on commit a0a349a

Please sign in to comment.