diff --git a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/OpenApiClientCreatorService.java b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/OpenApiClientCreatorService.java index b941c81..00f61fa 100644 --- a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/OpenApiClientCreatorService.java +++ b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/OpenApiClientCreatorService.java @@ -55,7 +55,7 @@ public List getControllers(HttpServletRequest request) { addOperation(remapped, PathItem.HttpMethod.DELETE, entry.getKey(), entry.getValue().getDelete()); addOperation(remapped, PathItem.HttpMethod.PATCH, entry.getKey(), entry.getValue().getPatch()); } - return remapped.entrySet().stream().map(e -> new OpenApiController(e.getKey(), e.getValue())).collect(Collectors.toList()); + return remapped.entrySet().stream().map(e -> new OpenApiController(e.getKey(), e.getValue(), typescriptConverter)).collect(Collectors.toList()); } public void getTypescriptClients(ReactQueryVersion reactQueryVersion, HttpServletRequest request, HttpServletResponse response, String baseUrl, String groupName, String filename) { diff --git a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/OpenApiController.java b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/OpenApiController.java index 5127bb1..8897b54 100644 --- a/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/OpenApiController.java +++ b/commons-rest-openapi/src/main/java/io/rocketbase/commons/openapi/model/OpenApiController.java @@ -1,12 +1,14 @@ package io.rocketbase.commons.openapi.model; import io.rocketbase.commons.openapi.OpenApiControllerMethodExtraction; +import io.rocketbase.commons.openapi.OpenApiConverter; import io.rocketbase.commons.util.Nulls; import lombok.Data; import lombok.NoArgsConstructor; import org.apache.commons.lang3.StringUtils; import java.io.Serializable; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -19,17 +21,20 @@ public class OpenApiController implements Serializable { private String controllerBean; private List methods; + private OpenApiConverter openApiConverter; + public String getShortName() { return controllerBean.substring(controllerBean.lastIndexOf(".") + 1).replace("Controller", ""); } - public OpenApiController(String controllerBean, List methods) { + public OpenApiController(String controllerBean, List methods, OpenApiConverter openApiConverter) { this.controllerBean = controllerBean; this.methods = methods; // link this controller to methods for (OpenApiControllerMethodExtraction m : methods) { m.setController(this); } + this.openApiConverter = openApiConverter; } public Set getImportTypes() { @@ -52,6 +57,8 @@ protected String toKebabCase(String input) { public Set getFieldImports() { return methods.stream().filter(m -> m.hasOptionalFields() || m.hasRequiredFields()) .map(OpenApiControllerMethodExtraction::getShortInputType) + .filter(v -> !Nulls.notNull(openApiConverter, OpenApiConverter::getNativeTypes, Collections.emptySet()) + .contains(v.toLowerCase())) .collect(Collectors.toSet()); } diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityApi.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityApi.java index 877cc25..1ba4ef1 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityApi.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityApi.java @@ -49,5 +49,12 @@ ResponseEntity> loadActivities(@ParameterObject ) ResponseEntity findById(@PathVariable("id") String id); + @GetMapping( + path = "/hosted/{id}", + produces = MimeTypeUtils.APPLICATION_JSON_VALUE, + consumes = MimeTypeUtils.ALL_VALUE + ) + ResponseEntity findByHosted(@PathVariable("id") String id); + } diff --git a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityController.java b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityController.java index 7a18b9d..033cb74 100644 --- a/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityController.java +++ b/commons-rest-openapi/src/test/java/io/rocketbase/commons/openapi/sample/resource/ActivityController.java @@ -19,4 +19,9 @@ public ResponseEntity> loadActivities(Pageable pageable public ResponseEntity findById(String id) { return null; } + + @Override + public ResponseEntity findByHosted(String id) { + return null; + } }