use of io.swagger.v3.oas.annotations.extensions.ExtensionProperty in project swagger-core by swagger-api.
the class AnnotationsUtils method getExtensions.
public static Map<String, Object> getExtensions(Extension... extensions) {
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;
for (ExtensionProperty property : extension.properties()) {
final String propertyName = property.name();
final String propertyValue = property.value();
JsonNode processedValue = null;
final boolean propertyAsJson = property.parseValue();
if (StringUtils.isNotBlank(propertyName) && StringUtils.isNotBlank(propertyValue)) {
if (key.isEmpty()) {
if (propertyAsJson) {
try {
processedValue = Json.mapper().readTree(propertyValue);
map.put(StringUtils.prependIfMissing(propertyName, "x-"), processedValue);
} catch (Exception e) {
map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue);
}
} else {
map.put(StringUtils.prependIfMissing(propertyName, "x-"), propertyValue);
}
} else {
Object value = map.get(key);
if (!(value instanceof Map)) {
value = new HashMap<String, Object>();
map.put(key, value);
}
@SuppressWarnings("unchecked") final Map<String, Object> mapValue = (Map<String, Object>) value;
if (propertyAsJson) {
try {
processedValue = Json.mapper().readTree(propertyValue);
mapValue.put(propertyName, processedValue);
} catch (Exception e) {
mapValue.put(propertyName, propertyValue);
}
} else {
mapValue.put(propertyName, propertyValue);
}
}
}
}
}
return map;
}
Aggregations