Skip to content

Commit 4b91c94

Browse files
author
Nicolas Torres
committed
Does not create example from schema if there are examples present
1 parent e0949ba commit 4b91c94

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

boat-scaffold/src/main/java/com/backbase/oss/codegen/doc/BoatExampleUtils.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ public static void convertExamples(OpenAPI openAPI, MediaType mediaType, String
5959
}
6060

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

65-
if (openAPI.getComponents().getSchemas() != null && openAPI.getComponents().getSchemas().get(ref) != null && openAPI.getComponents().getSchemas().get(ref).getExample() != null) {
66-
Object example = openAPI.getComponents().getSchemas().get(ref).getExample();
67-
BoatExample boatExample = new BoatExample("example", contentType, new Example().value(example), isJson(contentType));
68-
examples.add(boatExample);
69-
}
65+
ref = StringUtils.substringAfterLast(ref, "/");
66+
67+
boolean hasValidRef = openAPI.getComponents().getSchemas() != null && openAPI.getComponents().getSchemas().get(ref) != null;
68+
69+
if (!hasValidRef) return;
70+
71+
Schema schema = openAPI.getComponents().getSchemas().get(ref);
72+
73+
if (schema.getExample() != null) {
74+
Object example = schema.getExample();
75+
BoatExample boatExample = new BoatExample("example", contentType, new Example().value(example), isJson(contentType));
76+
examples.add(boatExample);
7077
}
7178
}
7279

0 commit comments

Comments
 (0)