Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ public static void convertExamples(OpenAPI openAPI, MediaType mediaType, String
}

private static void processRef(OpenAPI openAPI, String contentType, List<BoatExample> examples, String ref) {
if (ref.startsWith("#/components/schemas")) {
ref = StringUtils.substringAfterLast(ref, "/");
if (!examples.isEmpty()) return; // No auto-generated example from the schema if examples are already present.
if (!ref.startsWith("#/components/schemas")) return;

if (openAPI.getComponents().getSchemas() != null && openAPI.getComponents().getSchemas().get(ref) != null && openAPI.getComponents().getSchemas().get(ref).getExample() != null) {
Object example = openAPI.getComponents().getSchemas().get(ref).getExample();
BoatExample boatExample = new BoatExample("example", contentType, new Example().value(example), isJson(contentType));
examples.add(boatExample);
}
ref = StringUtils.substringAfterLast(ref, "/");

boolean hasValidRef = openAPI.getComponents().getSchemas() != null && openAPI.getComponents().getSchemas().get(ref) != null;

if (!hasValidRef) return;

Schema schema = openAPI.getComponents().getSchemas().get(ref);

if (schema.getExample() != null) {
Object example = schema.getExample();
BoatExample boatExample = new BoatExample("example", contentType, new Example().value(example), isJson(contentType));
examples.add(boatExample);
}
}

Expand Down