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 @@ -14,6 +14,9 @@ It currently consists of

# Release Notes
BOAT is still under development and subject to change.
## 0.17.60
* Allow references to parent directory of the spec itself, to be able to refer to common examples in a common lib.
* Fix tests... petshop example moved.
## 0.17.59
* Fix bug where java-spring generator puts `@Valid` annoation on return type of Api methods, cause service to blame
client for invalid generated response with a 400 status.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void processMediaType(MediaType mediaType, String relativePath, boolean d
}

private void putComponentExample(String key, Example example) {
log.debug("Put Component Example: [{}], [{}]", key, example);
getComponentExamplesFromOpenAPI().put(key, example);
}

Expand Down Expand Up @@ -155,7 +156,6 @@ private void fixInlineExamples(ExampleHolder exampleHolder, String relativePath,
return;
}

URI resolvedUri;
Optional<String> fragment;
if (refPath.contains("#") && !refPath.startsWith("#/components/examples")) {
fragment = Optional.of(StringUtils.substringAfter(refPath, "#"));
Expand All @@ -164,11 +164,12 @@ private void fixInlineExamples(ExampleHolder exampleHolder, String relativePath,
fragment = Optional.empty();
}

resolvedUri = resolveUri(relativePath, refPath);
URI resolvedUri = resolveUri(relativePath, refPath);
try {
String content = readContent(Paths.get(resolvedUri));

if (fragment.isPresent()) {
log.debug("Read content from [{}], finding fragment [{}]", resolvedUri, fragment.get());
String exampleName = StringUtils.substringAfterLast(fragment.get(), "/");
// resolve fragment from json node
JsonNode jsonNode = yamlObjectMapper.readTree(content);
Expand All @@ -178,19 +179,22 @@ private void fixInlineExamples(ExampleHolder exampleHolder, String relativePath,
processInLineExample(exampleHolder,relativePath,exampleNode, exampleName);

} else {
log.debug("Read content from [{}], set content and dereference", resolvedUri);
exampleHolder.setContent(content);
dereferenceExample(exampleHolder);
}
if (derefenceExamples) {
log.debug("Read content from [{}], not setting content and dereference because...", resolvedUri);
dereferenceExample(exampleHolder);
}

} catch (IOException e) {
throw new TransformerException("Unable to fix inline examples", e);
throw new TransformerException("Unable to fix inline examples from " + resolvedUri, e);
}
}

private void processInLineExample(ExampleHolder exampleHolder, String relativePath, JsonNode exampleNode, String exampleName) throws IOException {
log.debug("Process inline example [{}], [{}], [{}], [{}]", exampleHolder, relativePath, exampleNode, exampleName);
if (exampleNode.has("$ref")) {
String refPath = exampleNode.get("$ref").asText();
exampleHolder.replaceRef(refPath);
Expand Down Expand Up @@ -227,17 +231,23 @@ private String readContent(Path path) throws IOException {
}

private URI resolveUri(String relativePath, String refPath) {
URI resolvedUri;
if (relativePath == null) {
resolvedUri = rootUri.resolve(StringUtils.strip(refPath, "./"));
return rootUri.resolve(removeLeadingDotSlash(refPath));
} else {
resolvedUri = rootUri.resolve(checkTrailingSlash(relativePath.replace("\\", "/")))
return rootUri.resolve(checkTrailingSlash(relativePath.replace("\\", "/")))
.resolve(refPath.replace("\\", "/"));
}
return resolvedUri;
}

private String removeLeadingDotSlash(String path) {
if (StringUtils.startsWith(path,"./")) {
return StringUtils.substring(path, 2);
}
return path;
}

private void dereferenceExample(ExampleHolder exampleHolder) {
log.debug("dereferenceExample: '{}'", exampleHolder);
String rootName = exampleHolder.getExampleName();
int count = 0;
while (existsButNotMatching(cache.get(makeCountedName(rootName, count)), exampleHolder)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.responses.ApiResponses;
import io.swagger.v3.parser.models.RefFormat;
import lombok.extern.slf4j.Slf4j;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
Expand All @@ -26,12 +31,9 @@
import java.util.Collections;
import java.util.Map;
import java.util.function.Function;
import lombok.extern.slf4j.Slf4j;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -87,7 +89,7 @@ void testBundleExamples() throws OpenAPILoaderException, IOException {
@Test
void testBundleHttp() throws OpenAPILoaderException, IOException {

String url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore.yaml";
String url = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass//petstore.yaml";
OpenAPI openAPI = OpenAPILoader.load(url);
OpenAPI openAPIUnproccessed = openAPI;

Expand All @@ -105,8 +107,9 @@ void testBundleNonExistingFiles() throws OpenAPILoaderException, IOException {
try {
bundler.transform(openAPI, Collections.EMPTY_MAP);
fail("Expected TransformerException");
}catch (TransformerException e){
assertEquals("Unable to fix inline examples",e.getMessage());
} catch (TransformerException e){
assertTrue(e.getMessage().startsWith("Unable to fix inline examples from file"));
assertTrue(e.getMessage().endsWith("notexist.json"));
}

}
Expand Down
2 changes: 1 addition & 1 deletion boat-maven-plugin/src/it/example/boat-doc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<goal>doc</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/api-with-examples.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/api-with-examples.yaml</inputSpec>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<generatorName>boat-angular</generatorName>
<output>${project.basedir}/target/http-module</output>
<reservedWordsMappings>delete=delete,function=function,new=new</reservedWordsMappings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<generatorName>java</generatorName>
<library>native</library>
<configOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<goal>generate-rest-template-embedded</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<modelPackage>com.backbase.oss.boat.example.petstore.model</modelPackage>
<apiPackage>com.backbase.oss.boat.example.petstore.api</apiPackage>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
<goal>generate-webclient-embedded</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<modelPackage>com.backbase.oss.boat.example.petstore.model</modelPackage>
<apiPackage>com.backbase.oss.boat.example.petstore.api</apiPackage>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateApiTests>false</generateApiTests>
<generateApis>false</generateApis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<goal>generate-spring-boot-embedded</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<modelPackage>com.backbase.oss.boat.example.petstore.model</modelPackage>
<apiPackage>com.backbase.oss.boat.example.petstore.api</apiPackage>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<goal>generate-spring-boot-embedded</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<modelPackage>com.backbase.oss.boat.example.petstore.model</modelPackage>
<apiPackage>com.backbase.oss.boat.example.petstore.api</apiPackage>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateApiTests>false</generateApiTests>
<generateApis>true</generateApis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml</inputSpec>
<generatorName>spring</generatorName>
<generateApiTests>false</generateApiTests>
<generateApis>true</generateApis>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<goal>doc</goal>
</goals>
<configuration>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/api-with-examples.yaml</inputSpec>
<inputSpec>https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore.yaml</inputSpec>
</configuration>
</execution>
<execution>
Expand Down