diff --git a/README.md b/README.md index eda064f8b..b36478348 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/boat-engine/src/main/java/com/backbase/oss/boat/transformers/bundler/ExamplesProcessor.java b/boat-engine/src/main/java/com/backbase/oss/boat/transformers/bundler/ExamplesProcessor.java index 98b8a4708..e8fac1748 100644 --- a/boat-engine/src/main/java/com/backbase/oss/boat/transformers/bundler/ExamplesProcessor.java +++ b/boat-engine/src/main/java/com/backbase/oss/boat/transformers/bundler/ExamplesProcessor.java @@ -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); } @@ -155,7 +156,6 @@ private void fixInlineExamples(ExampleHolder exampleHolder, String relativePath, return; } - URI resolvedUri; Optional fragment; if (refPath.contains("#") && !refPath.startsWith("#/components/examples")) { fragment = Optional.of(StringUtils.substringAfter(refPath, "#")); @@ -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); @@ -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); @@ -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)) { diff --git a/boat-engine/src/test/java/com/backbase/oss/boat/transformers/BundlerTests.java b/boat-engine/src/test/java/com/backbase/oss/boat/transformers/BundlerTests.java index 8fb590300..137c1f681 100644 --- a/boat-engine/src/test/java/com/backbase/oss/boat/transformers/BundlerTests.java +++ b/boat-engine/src/test/java/com/backbase/oss/boat/transformers/BundlerTests.java @@ -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; @@ -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.*; @@ -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; @@ -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")); } } diff --git a/boat-maven-plugin/src/it/example/boat-doc/pom.xml b/boat-maven-plugin/src/it/example/boat-doc/pom.xml index 00605471a..c7768441a 100644 --- a/boat-maven-plugin/src/it/example/boat-doc/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-doc/pom.xml @@ -28,7 +28,7 @@ doc - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/api-with-examples.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/api-with-examples.yaml diff --git a/boat-maven-plugin/src/it/example/boat-generate/angular/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/angular/pom.xml index d67d97b9f..6e7f93c2f 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/angular/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/angular/pom.xml @@ -41,7 +41,7 @@ generate - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml boat-angular ${project.basedir}/target/http-module delete=delete,function=function,new=new diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-clients/java/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-clients/java/pom.xml index cad7fb755..225944b0a 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-clients/java/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-clients/java/pom.xml @@ -67,7 +67,7 @@ generate - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml java native diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-clients/rest-template-embedded/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-clients/rest-template-embedded/pom.xml index c2c53875d..5811a57a0 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-clients/rest-template-embedded/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-clients/rest-template-embedded/pom.xml @@ -84,7 +84,7 @@ generate-rest-template-embedded - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml com.backbase.oss.boat.example.petstore.model com.backbase.oss.boat.example.petstore.api diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-clients/webclient-embedded/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-clients/webclient-embedded/pom.xml index fb8f8afc1..9e19da339 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-clients/webclient-embedded/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-clients/webclient-embedded/pom.xml @@ -95,7 +95,7 @@ generate-webclient-embedded - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml com.backbase.oss.boat.example.petstore.model com.backbase.oss.boat.example.petstore.api diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-server/models/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-server/models/pom.xml index 977ed476c..d642577db 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-server/models/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-server/models/pom.xml @@ -90,7 +90,7 @@ generate - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml spring false false diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-boot-3/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-boot-3/pom.xml index 639f6db8d..9e679d9c7 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-boot-3/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-boot-3/pom.xml @@ -54,7 +54,7 @@ generate-spring-boot-embedded - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml com.backbase.oss.boat.example.petstore.model com.backbase.oss.boat.example.petstore.api diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-embedded/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-embedded/pom.xml index fab960ab1..0a3de8107 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-embedded/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-server/spring-embedded/pom.xml @@ -54,7 +54,7 @@ generate-spring-boot-embedded - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml com.backbase.oss.boat.example.petstore.model com.backbase.oss.boat.example.petstore.api diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-server/webflux/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-server/webflux/pom.xml index d7bc1a342..7425f03ba 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-server/webflux/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-server/webflux/pom.xml @@ -51,7 +51,7 @@ generate - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml spring false true diff --git a/boat-maven-plugin/src/it/example/boat-generate/java-server/webmvc/pom.xml b/boat-maven-plugin/src/it/example/boat-generate/java-server/webmvc/pom.xml index 41fa80fb4..63a8afefd 100644 --- a/boat-maven-plugin/src/it/example/boat-generate/java-server/webmvc/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-generate/java-server/webmvc/pom.xml @@ -45,7 +45,7 @@ generate - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/petstore-expanded.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore-expanded.yaml spring false true diff --git a/boat-maven-plugin/src/it/example/boat-multiple-executions/pom.xml b/boat-maven-plugin/src/it/example/boat-multiple-executions/pom.xml index 9927f1c01..49c5317d8 100644 --- a/boat-maven-plugin/src/it/example/boat-multiple-executions/pom.xml +++ b/boat-maven-plugin/src/it/example/boat-multiple-executions/pom.xml @@ -28,7 +28,7 @@ doc - https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/tests/v3.0/pass/api-with-examples.yaml + https://raw.githubusercontent.com/OAI/OpenAPI-Specification/refs/heads/main/_archive_/schemas/v3.0/pass/petstore.yaml