diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java index 439e762..c182f24 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/GenerateClientTest.java @@ -31,6 +31,13 @@ public void downloadZip() throws Exception { log.info("downloaded: {}", destination.getAbsolutePath()); } + @Test + public void downloadOpenApiYaml() throws Exception { + File destination = new File("target/api-docs.yaml"); + download(new URL(baseUrl + "/v3/api-docs.yaml"), destination); + log.info("downloaded: {}", destination.getAbsolutePath()); + } + private static void download(URL url, File file) throws IOException { ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/dto/Tile.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/dto/Tile.java index ce56eec..e0e9f71 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/dto/Tile.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/dto/Tile.java @@ -1,5 +1,6 @@ package io.rocketbase.commons.openapi.sample.dto; +import io.hypersistence.tsid.TSID; import lombok.*; import java.io.Serializable; @@ -12,7 +13,7 @@ @Data public class Tile implements Serializable { - private String id; + private TSID id; private TileType type; diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java index 09ea727..5150bf6 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileApi.java @@ -1,5 +1,6 @@ package io.rocketbase.commons.openapi.sample.resource; +import io.hypersistence.tsid.TSID; import io.rocketbase.commons.dto.PageableResult; import io.rocketbase.commons.generator.InfiniteHook; import io.rocketbase.commons.generator.QueryHook; @@ -54,5 +55,5 @@ ResponseEntity> loadTiles(@ParameterObject consumes = MimeTypeUtils.ALL_VALUE ) Tile get(@Parameter(description = "id of tile", required = true) - @PathVariable("id") String id); + @PathVariable("id") TSID id); } diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileController.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileController.java index 0594dbd..ded0920 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileController.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/TileController.java @@ -1,5 +1,6 @@ package io.rocketbase.commons.openapi.sample.resource; +import io.hypersistence.tsid.TSID; import io.rocketbase.commons.dto.PageableResult; import io.rocketbase.commons.openapi.sample.dto.Tile; import io.rocketbase.commons.openapi.sample.dto.UserPreference; @@ -19,7 +20,7 @@ public ResponseEntity> loadTiles(Pageable pageable, Optiona } @Override - public Tile get(String id) { + public Tile get(TSID id) { return null; } } diff --git a/commons-rest-tsid/src/main/java/io/rocketbase/commons/config/CommonsRestTsidAutoConfiguration.java b/commons-rest-tsid/src/main/java/io/rocketbase/commons/config/CommonsRestTsidAutoConfiguration.java index 23fee60..a03459a 100644 --- a/commons-rest-tsid/src/main/java/io/rocketbase/commons/config/CommonsRestTsidAutoConfiguration.java +++ b/commons-rest-tsid/src/main/java/io/rocketbase/commons/config/CommonsRestTsidAutoConfiguration.java @@ -4,6 +4,7 @@ import io.hypersistence.tsid.TSID; import io.rocketbase.commons.controller.exceptionhandler.TsidDecodeExceptionHandler; import io.rocketbase.commons.exception.TsidDecodeException; +import io.rocketbase.commons.tsid.TsidConverter; import io.rocketbase.commons.tsid.TsidModule; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -11,6 +12,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.convert.converter.Converter; import org.springframework.format.Formatter; import org.springframework.util.StringUtils; import org.springframework.web.bind.WebDataBinder; @@ -36,6 +38,11 @@ public Module tsidModule() { return new TsidModule(); } + @Bean + public Converter tsidConverter() { + return new TsidConverter(); + } + @RestControllerAdvice public static class Advice { diff --git a/commons-rest-tsid/src/main/java/io/rocketbase/commons/tsid/TsidConverter.java b/commons-rest-tsid/src/main/java/io/rocketbase/commons/tsid/TsidConverter.java new file mode 100644 index 0000000..3c3ec69 --- /dev/null +++ b/commons-rest-tsid/src/main/java/io/rocketbase/commons/tsid/TsidConverter.java @@ -0,0 +1,14 @@ +package io.rocketbase.commons.tsid; + +import io.hypersistence.tsid.TSID; +import org.springframework.core.convert.converter.Converter; +import org.springframework.lang.Nullable; + +public class TsidConverter implements Converter { + + @Nullable + @Override + public TSID convert(String value) { + return TSID.isValid(value) ? TSID.from(value) : null; + } +}