Skip to content

Commit

Permalink
fix oas 3.1 extensions naming resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Jul 3, 2023
1 parent 7294019 commit fd61120
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2152,7 +2152,7 @@ protected Map<String, Object> resolveExtensions(Annotated a, Annotation[] annota
if (schema != null &&
schema.extensions() != null &&
schema.extensions().length > 0) {
return AnnotationsUtils.getExtensions(schema.extensions());
return AnnotationsUtils.getExtensions(openapi31, schema.extensions());
}
return null;
}
Expand Down Expand Up @@ -2346,7 +2346,7 @@ protected Map<String, Object> resolveExtensions(AnnotatedType a, io.swagger.v3.o
if (arraySchema != null &&
arraySchema.extensions() != null &&
arraySchema.extensions().length > 0) {
return AnnotationsUtils.getExtensions(arraySchema.extensions());
return AnnotationsUtils.getExtensions(openapi31, arraySchema.extensions());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ public static Optional<Schema> getSchemaFromAnnotation(
}

if (schema.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(schema.extensions());
Map<String, Object> extensions = AnnotationsUtils.getExtensions(openapi31, schema.extensions());
if (extensions != null) {
extensions.forEach(schemaObject::addExtension);
}
Expand Down Expand Up @@ -1739,7 +1739,8 @@ public static Map<String, Object> getExtensions(boolean openapi31, Extension...
final Map<String, Object> map = new HashMap<>();
for (Extension extension : extensions) {
final String name = extension.name();
final String key = name.length() > 0 ? StringUtils.prependIfMissing(name, "x-") : name;
String decoratedName = openapi31 ? name : StringUtils.prependIfMissing(name, "x-");
final String key = name.length() > 0 ? decoratedName : name;

for (ExtensionProperty property : extension.properties()) {
final String propertyName = property.name();
Expand All @@ -1755,12 +1756,15 @@ public static Map<String, Object> getExtensions(boolean openapi31, Extension...
} else {
processedValue = Json.mapper().readTree(propertyValue);
}
map.put(StringUtils.prependIfMissing(propertyName, "x-"), processedValue);
decoratedName = openapi31 ? propertyName : StringUtils.prependIfMissing(propertyName, "x-");
map.put(decoratedName, processedValue);
} catch (Exception e) {
map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue);
decoratedName = openapi31 ? propertyName : StringUtils.prependIfMissing(propertyName, "x-");
map.put(decoratedName, propertyValue);
}
} else {
map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue);
decoratedName = openapi31 ? propertyName : StringUtils.prependIfMissing(propertyName, "x-");
map.put(decoratedName, propertyValue);
}
} else {
Object value = map.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static Parameter applyAnnotations(
}

if (p.extensions().length > 0) {
Map<String, Object> extensionMap = AnnotationsUtils.getExtensions(p.extensions());
Map<String, Object> extensionMap = AnnotationsUtils.getExtensions(openapi31, p.extensions());
if (extensionMap != null && ! extensionMap.isEmpty()) {
extensionMap.forEach(parameter::addExtension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Optional<RequestBody> getRequestBody(io.swagger.v3.oas.annotations
isEmpty = false;
}
if (requestBody.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(requestBody.extensions());
Map<String, Object> extensions = AnnotationsUtils.getExtensions(openapi31, requestBody.extensions());
if (extensions != null) {
extensions.forEach(requestBodyObject::addExtension);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public static Optional<ApiResponses> getApiResponses(final io.swagger.v3.oas.ann
apiResponseObject.setDescription(response.description());
}
if (response.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(response.extensions());
Map<String, Object> extensions = AnnotationsUtils.getExtensions(openapi31, response.extensions());
if (extensions != null) {
extensions.forEach(apiResponseObject::addExtension);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public OpenAPI read(Class<?> cls,
// OpenApiDefinition extensions
if (openAPIDefinition.extensions().length > 0) {
openAPI.setExtensions(AnnotationsUtils
.getExtensions(openAPIDefinition.extensions()));
.getExtensions(config.isOpenAPI31(), openAPIDefinition.extensions()));
}

}
Expand Down

0 comments on commit fd61120

Please sign in to comment.