mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 05:59:24 +00:00
Add primitive type support (#1835)
This commit is contained in:
committed by
William Cheng
parent
03711d572f
commit
dec852ca9f
@@ -75,8 +75,7 @@ public class ExampleGenerator {
|
||||
}
|
||||
|
||||
if (responseSchema.getExample() != null && !(responseSchema.getExample() instanceof Map)) {
|
||||
LOGGER.warn("example value (array/primitive) not handled at the moment: " + responseSchema.getExample());
|
||||
return null;
|
||||
return generate(responseSchema.getExample(), new ArrayList<>(producesInfo));
|
||||
}
|
||||
|
||||
if (ModelUtils.isArraySchema(responseSchema)) { // array of schema
|
||||
@@ -190,6 +189,34 @@ public class ExampleGenerator {
|
||||
return output;
|
||||
}
|
||||
|
||||
private List<Map<String, String>> generate(Object example, List<String> mediaTypes) {
|
||||
List<Map<String, String>> output = new ArrayList<>();
|
||||
if (examples != null) {
|
||||
if (mediaTypes == null) {
|
||||
// assume application/json for this
|
||||
mediaTypes = Collections.singletonList(MIME_TYPE_JSON);
|
||||
}
|
||||
for (String mediaType : mediaTypes) {
|
||||
Map<String, String> kv = new HashMap<>();
|
||||
kv.put(CONTENT_TYPE, mediaType);
|
||||
if ((mediaType.startsWith(MIME_TYPE_JSON) || mediaType.contains("*/*"))) {
|
||||
kv.put(EXAMPLE, Json.pretty(example));
|
||||
output.add(kv);
|
||||
} else if (mediaType.startsWith(MIME_TYPE_XML)) {
|
||||
// TODO
|
||||
LOGGER.warn("XML example value of (array/primitive) is not handled at the moment: " + example);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (output.size() == 0) {
|
||||
Map<String, String> kv = new HashMap<>();
|
||||
kv.put(OUTPUT, NONE);
|
||||
output.add(kv);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private Object resolvePropertyToExample(String propertyName, String mediaType, Schema property, Set<String> processedModels) {
|
||||
LOGGER.debug("Resolving example for property {}...", property);
|
||||
if (property.getExample() != null) {
|
||||
|
||||
Reference in New Issue
Block a user