Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ The project is very much Work In Progress and will be published on maven central

# Release Notes
BOAT is still under development and subject to change.
## 0.14.11
* *Boat Scaffold*
* References to /examples/foo now are also dereferenced
## 0.14.10
* *Boat Scaffold*
* Makes sure to URLDecode paths while dereferencing examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

@Slf4j
@UtilityClass
@SuppressWarnings("java:S3740")
@SuppressWarnings({"java:S3740", "java:S125"})
public class BoatExampleUtils {

private static final String PATHS_REF_PREFIX = "#/paths";
Expand All @@ -42,7 +42,7 @@ public static void convertExamples(OpenAPI openAPI, MediaType mediaType, String

if (mediaType.getExamples() != null) {
mediaType.getExamples().forEach((key, example) -> {
log.debug("Adding example: {} to examples with content type: {} and responseCode: {} ", key, contentType, responseCode);
log.info("Adding example: {} to examples with content type: {} and responseCode: {} ", key, contentType, responseCode);
BoatExample boatExample = new BoatExample(key, contentType, example, isJson(contentType));
examples.add(boatExample);
});
Expand Down Expand Up @@ -175,6 +175,24 @@ private static void resolvePathsExamples(
return;
}

/* This could be a ref to /example or to /examples/foo in the case of responses.
* responses:
200:
description: OK
examples:
application/json: { "id": 38, "title": "T-shirt" }
text/csv: >
id,title
38,T-shirt
*
*
* */
if (refParts[7].equals("examples")) {
Example example = mediaType.getExamples().get(refParts[8]);
boatExample.setExample(example);
return;
}

Example example = new Example().value(mediaType.getExample());
log.warn("Incorrect example reference found! Replacing Example ref: {} used in: {} with example from components", ref, name);
boatExample.setExample(example);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ paths:
$ref: "#/components/schemas/Error"
example:
$ref: "#/paths/~1pets~1%7BpetId%7D/get/responses/default/content/application~1json/example"
'202':
description: Expected response to a valid request
content:
application/json:
examples:
example:
summary: This is an example referenced in a horrible path
value: foo
default:
description: unexpected error
content:
Expand Down Expand Up @@ -106,6 +114,18 @@ paths:
$ref: "#/components/schemas/Pet"
example:
$ref: "#/paths/~1pets/get/responses/default/content/application~1json/example"
'400':
description: Expected response to a valid request
content:
application/json:
example:
$ref: "#/paths/~1pets/post/responses/202/content/application~1json/examples/example"
application/xml:
examples:
Inexistent:
$ref: "#/paths/~1pets/post/responses/202/content/application~1json/examples/theinexistentexample"
AnotheOne:
$ref: "#/paths/~1pets/post/responses/202/content/application~1json/examples/example"
'500':
description: InternalServerError
content:
Expand Down