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 @@ -16,6 +16,9 @@ It currently consists of
# Release Notes
BOAT is still under development and subject to change.

## 0.17.70
Fix: Examples of responses defined in components/responses were not inlined by the ExamplesProcessor.

## 0.17.69
Update query parameter handling in Swift5 template (#1177)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.media.Content;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.parser.models.RefFormat;
import io.swagger.v3.parser.util.RefUtils;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -62,7 +63,13 @@ public void processExamples() {
.map(e -> ExampleHolder.of(e.getKey(), e.getValue(), true))
.forEach(this::fixInlineExamples);

if (openAPI.getComponents().getResponses() != null) {
log.debug("Processing examples in component/responses");
openAPI.getComponents().getResponses().values().forEach(this::processResponse);
}


log.debug("Processing examples in Paths");
openAPI.getPaths()
.forEach((path, pathItem) -> {
log.debug("Processing examples in Path: {}", path);
Expand All @@ -74,23 +81,28 @@ public void processExamples() {
processMediaType(mediaType, null, false);
});
}
operation.getResponses().forEach((responseCode, apiResponse) -> {
log.debug("Processing Response Body Examples for Response Code: {}", responseCode);
if (apiResponse.getContent() != null) {
apiResponse.getContent().forEach((contentType, mediaType) -> {
log.debug("Processing Response Body Examples for Content Type: {}", contentType);
processMediaType(mediaType, null, false);
});
}
operation.getResponses().forEach((responseCode, apiResponse) -> {
log.debug("Processing Response Body Examples for: {}:{} {}", httpMethod, path, responseCode);
processResponse(apiResponse);
});
});
});
}

public void processContent(Content content, String relativePath) {
public void processResponse(ApiResponse response) {
if (response.getContent() != null) {
response.getContent().forEach((contentType, mediaType) -> {
log.debug("Processing Response Body Examples for Content Type: {}", contentType);
processMediaType(mediaType, null, false);
});
} else {
log.warn("Content is null for: {}", response);
}
}

public void processContent(Content content, String relativePath) {
content.forEach((s, mediaType) -> {
log.debug("Processing Consent for: {} with relative path: {}", s, relativePath);
log.debug("Processing Content for: {} with relative path: {}", s, relativePath);
processMediaType(mediaType, relativePath, true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void testBundleExamples() throws OpenAPILoaderException, IOException {

new Bundler(input).transform(openAPI, Collections.emptyMap());
log.info(Yaml.pretty(openAPI.getComponents().getExamples()));
assertThat("Should not contain any json reference", Yaml.pretty(openAPI).indexOf(".json"), is(-1));
assertEquals(openAPIUnproccessed, openAPI);
}

Expand Down
2 changes: 1 addition & 1 deletion boat-engine/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
<root level="INFO">
<appender-ref ref="COLOR"/>
</root>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ paths:
$ref: '#/components/examples/example-in-components'
in-component-1:
$ref: '#/components/examples/example-in-components-1'
'400':
$ref: '#/components/responses/ResponseWithAFileReferenceToExample'
components:
schemas:
UserPostRequest:
Expand All @@ -182,6 +184,16 @@ components:
pattern: ^[0-9].*$
minLength: 1
maxLength: 30
responses:
ResponseWithAFileReferenceToExample:
description: A 400 response with a reference to an example file.
content:
application/json:
schema:
$ref: 'schemas/post-user-response.json'
example:
$ref: 'examples/user-post-response.json'

examples:
example-in-components:
$ref: './examples/user-post-response.json'
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

<slf4j.version>1.7.30</slf4j.version>
<swagger-core.version>2.2.40</swagger-core.version>
<swagger-parser.version>2.1.6</swagger-parser.version>
<swagger-parser.version>2.1.35</swagger-parser.version>
<snakeyaml.version>2.5</snakeyaml.version>
<jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
</properties>
Expand Down Expand Up @@ -211,7 +211,7 @@
<dependency>
<groupId>io.swagger.parser.v3</groupId>
<artifactId>swagger-parser</artifactId>
<version>2.1.35</version>
<version>${swagger-parser.version}</version>
<exclusions>
<exclusion>
<groupId>javax.validation</groupId>
Expand Down