Skip to content

Commit

Permalink
feat:openapi3 文件处理
Browse files Browse the repository at this point in the history
  • Loading branch information
lixingzhi authored and shalousun committed Mar 5, 2023
1 parent f8a62fc commit 091a575
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,27 @@ public Map<String, Object> buildParametersSchema(ApiParam apiParam) {
Map<String, Object> schema = new HashMap<>(10);
String openApiType = DocUtil.javaTypeToOpenApiTypeConvert(apiParam.getType());
schema.put("type", openApiType);
if ("object".equals(openApiType) || "string".equals(openApiType)) {
if ("file".equals(apiParam.getType())) {
schema.put("format", "binary");
schema.put("type", "string");
} else if ("enum".equals(apiParam.getType())) {
if ("file".equals(apiParam.getType())) {
schema.put("format", "binary");
schema.put("type", "string");
} else if ("object".equals(openApiType)) {
if ("enum".equals(apiParam.getType())) {
schema.put("enum", apiParam.getEnumValues());
} else if (ARRAY.equals(apiParam.getType())) {
if (CollectionUtil.isNotEmpty(apiParam.getEnumValues())) {
schema.put("type", "string");
schema.put("items", apiParam.getEnumValues());
} else {
schema.put("type", ARRAY);
Map<String, String> map = new HashMap<>(4);
map.put("type", "string");
map.put("format", "string");
schema.put("items", map);
}
}
} else if (ARRAY.equals(apiParam.getType())) {
if (CollectionUtil.isNotEmpty(apiParam.getEnumValues())) {
schema.put("type", "string");
schema.put("items", apiParam.getEnumValues());
} else {
schema.put("type", ARRAY);
Map<String, String> map = new HashMap<>(4);
map.put("type", "string");
map.put("format", "string");
schema.put("items", map);
}
} else {
schema.put("type", "integer");
schema.put("format", "int16".equals(apiParam.getType()) ? "int32" : apiParam.getType());
schema.put("type", apiParam.getType());
schema.put("format", "integer");
}
return schema;
}
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/com/power/doc/builder/openapi/OpenApiBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Map<String, Object> buildPathUrlsRequest(ApiConfig apiConfig, ApiMethodDo
request.put("parameters", buildParameters(apiMethodDoc));
request.put("responses", buildResponses(apiConfig, apiMethodDoc));
request.put("deprecated", apiMethodDoc.isDeprecated());
String operationId = apiMethodDoc.getUrl().replace(apiMethodDoc.getServerUrl(),"");
String operationId = apiMethodDoc.getUrl().replace(apiMethodDoc.getServerUrl(), "");
request.put("operationId", String.join("", OpenApiSchemaUtil.getPatternResult("[A-Za-z0-9{}]*", operationId)));

return request;
Expand Down Expand Up @@ -239,26 +239,30 @@ List<Map<String, Object>> buildParameters(ApiMethodDoc apiMethodDoc) {
Map<String, Object> getStringParams(ApiParam apiParam, boolean hasItems) {
Map<String, Object> parameters;
parameters = new HashMap<>(20);
boolean isFile = "file".equalsIgnoreCase(apiParam.getType());
if (!hasItems) {
parameters.put("name", apiParam.getField());
parameters.put("description", apiParam.getDesc());
parameters.put("required", apiParam.isRequired());
parameters.put("example", StringUtil.removeQuotes(apiParam.getValue()));
parameters.put("in", "query");
parameters.put("schema", buildParametersSchema(apiParam));
} else {
if (isFile) {
parameters.put("type", "string");
parameters.put("format", "binary");
if (OBJECT.equals(apiParam.getType()) ||
(ARRAY.equals(apiParam.getType()) && apiParam.isHasItems())) {
parameters.put("type", "object");
parameters.put("description", "(complex POJO please use @RequestBody)");
} else {
parameters.put("type", apiParam.getType());
String desc = apiParam.getDesc();
if (desc.contains(PARAM_TYPE_FILE)) {
parameters.put("type", PARAM_TYPE_FILE);
} else if (desc.contains("string")) {
parameters.put("type", "string");
} else {
parameters.put("type", "integer");
}
}
parameters.putAll(buildParametersSchema(apiParam));
}
if (isFile) {
parameters.put("in", "formData");
} else {
parameters.put("in", "query");
}
parameters.put("schema", buildParametersSchema(apiParam));

return parameters;
}

Expand Down

0 comments on commit 091a575

Please sign in to comment.