Skip to content

Commit 0126d59

Browse files
committed
identify file type in api response schemas.
1 parent 0ef7e8e commit 0126d59

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
import java.nio.charset.StandardCharsets;
8484
import java.util.ArrayList;
8585
import java.util.Arrays;
86+
import java.util.Collection;
8687
import java.util.Collections;
8788
import java.util.Comparator;
8889
import java.util.HashMap;
@@ -2338,6 +2339,9 @@ public CodegenResponse fromResponse(String responseCode, ApiResponse response) {
23382339
} else {
23392340
codegenResponse.baseType = codegenProperty.baseType;
23402341
}
2342+
if (isFileTypeSchema(responseSchema)) {
2343+
codegenResponse.getVendorExtensions().put(CodegenConstants.IS_FILE_EXT_NAME, Boolean.TRUE);
2344+
}
23412345
}
23422346
codegenResponse.dataType = codegenProperty.datatype;
23432347

@@ -4403,6 +4407,21 @@ protected void setParameterNullable(CodegenParameter parameter, CodegenProperty
44034407
parameter.nullable = property.nullable;
44044408
}
44054409

4410+
protected boolean isFileTypeSchema(Schema schema) {
4411+
final Schema fileTypeSchema;
4412+
if (StringUtils.isNotBlank(schema.get$ref())) {
4413+
fileTypeSchema = OpenAPIUtil.getSchemaFromRefSchema(schema, openAPI);
4414+
} else {
4415+
fileTypeSchema = schema;
4416+
}
4417+
if (fileTypeSchema.getProperties() != null) {
4418+
final Collection<Schema> propertySchemas = fileTypeSchema.getProperties().values();
4419+
return propertySchemas.stream().anyMatch(propertySchema -> "string".equalsIgnoreCase(propertySchema.getType())
4420+
&& "binary".equalsIgnoreCase(propertySchema.getFormat()));
4421+
}
4422+
return false;
4423+
}
4424+
44064425
@Override
44074426
public boolean needsUnflattenedSpec() {
44084427
return false;

0 commit comments

Comments
 (0)