From 5bcaeba4ab6df1d8d6f7fe60800d456ef28beeab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Enrique=20Garc=C3=ADa=20Maci=C3=B1eiras?= Date: Mon, 21 Aug 2023 12:54:33 +0200 Subject: [PATCH] #251 Fix Parameter without description --- .../openapi/utils/MapperContentUtil.java | 6 +- .../openapi/OpenApiGeneratorFixtures.java | 37 +++++ .../plugin/openapi/OpenApiGeneratorTest.java | 2 + .../testIssueFaker/api-test.yml | 128 ++++++++++++++++++ .../testIssueFaker/assets/FakerApi.java | 49 +++++++ .../assets/model/ConfigurationDTO.java | 33 +++++ .../assets/model/FakerFieldDTO.java | 33 +++++ .../assets/model/FakerSchemaDTO.java | 55 ++++++++ .../testIssueFaker/assets/model/FieldDTO.java | 29 ++++ .../assets/model/SchemaDTO.java | 55 ++++++++ 10 files changed, 425 insertions(+), 2 deletions(-) create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/api-test.yml create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/FakerApi.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java create mode 100644 multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java diff --git a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java index f4f8cbd8..d72a76a3 100644 --- a/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java +++ b/multiapi-engine/src/main/java/com/sngular/api/generator/plugin/openapi/utils/MapperContentUtil.java @@ -539,11 +539,13 @@ private static Set processMap( final Set fieldObjectArrayList = new HashSet<>(); if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema))) { - ApiTool.getProperties(schema).forEachRemaining( + if (ApiTool.hasProperties(schema)) { + ApiTool.getProperties(schema).forEachRemaining( processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir)); + } } - if (ApiTool.hasProperties(schema)) { + if (ApiTool.hasAdditionalProperties(schema)) { fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, ADDITIONAL_PROPERTIES, baseDir)); } diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java index aee81bf7..d8d49358 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorFixtures.java @@ -364,6 +364,18 @@ public final class OpenApiGeneratorFixtures { .build() ); + static final List TEST_ISSUE_FAKER = List.of( + SpecFile + .builder() + .filePath("openapigenerator/testIssueFaker/api-test.yml") + .apiPackage("com.sngular.multifileplugin.testIssueFaker") + .modelPackage("com.sngular.multifileplugin.testIssueFaker.model") + .clientPackage("com.sngular.multifileplugin.testIssueFaker.client") + .modelNameSuffix("DTO") + .useLombokModelAnnotation(true) + .build() + ); + static final List TEST_DATE_TIME = List.of( SpecFile .builder() @@ -1222,6 +1234,31 @@ static Function validateCreateDTO() { return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API); } + static Function validateIssueFaker() { + + final String DEFAULT_TARGET_API = "generated/com/sngular/multifileplugin/testIssueFaker"; + + final String DEFAULT_MODEL_API = "generated/com/sngular/multifileplugin/testIssueFaker/model"; + + final String COMMON_PATH = "openapigenerator/testIssueFaker/"; + + final String ASSETS_PATH = COMMON_PATH + "assets/"; + + final List expectedTestApiFile = List.of( + ASSETS_PATH + "FakerApi.java" + ); + + final List expectedTestApiModelFiles = List.of( + ASSETS_PATH + "model/ConfigurationDTO.java", + ASSETS_PATH + "model/FakerFieldDTO.java", + ASSETS_PATH + "model/FakerSchemaDTO.java", + ASSETS_PATH + "model/FieldDTO.java", + ASSETS_PATH + "model/SchemaDTO.java" + ); + + return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), null); + } + static Function validateDateTime() { final String DEFAULT_TARGET_API = "generated/com/sngular/multifileplugin/testDateTime"; diff --git a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java index 1e71c069..f6df7337 100644 --- a/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java +++ b/multiapi-engine/src/test/java/com/sngular/api/generator/plugin/openapi/OpenApiGeneratorTest.java @@ -90,6 +90,8 @@ static Stream fileSpecToProcess() { OpenApiGeneratorFixtures.validateValidationAnnotationsLombok(SPRING_BOOT_VERSION)), Arguments.of("testCreateDTO", OpenApiGeneratorFixtures.TEST_CREATE_DTO, OpenApiGeneratorFixtures.validateCreateDTO()), + Arguments.of("testIssueFaker", OpenApiGeneratorFixtures.TEST_ISSUE_FAKER, + OpenApiGeneratorFixtures.validateIssueFaker()), Arguments.of("testDateTime", OpenApiGeneratorFixtures.TEST_DATE_TIME, OpenApiGeneratorFixtures.validateDateTime()), Arguments.of("testDateTimeZoned", OpenApiGeneratorFixtures.TEST_DATE_TIME_ZONED, diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/api-test.yml b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/api-test.yml new file mode 100644 index 00000000..4efe1219 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/api-test.yml @@ -0,0 +1,128 @@ +openapi: 3.0.2 +info: + title: Faker API Service + version: "1.0" +servers: +- url: https://localhost/v1 +paths: + /faker/generate-schemas: + post: + tags: + - SchemaGenerator + operationId: generateSchema + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Configuration' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/FakerSchema' + '400': + description: Bad Request + '404': + description: Not found + +components: + schemas: + Schema: + type: object + required: + - subjectName + - name + properties: + id: + type: string + subjectName: + type: string + name: + type: string + type: + type: string + original: + type: boolean + requiredFields: + type: array + items: + type: string + properties: + type: array + items: + $ref: '#/components/schemas/Field' + definitions: + type: array + items: + $ref: '#/components/schemas/Field' + FakerSchema: + type: object + required: + - subjectName + - name + - value + properties: + id: + type: string + subjectName: + type: string + name: + type: string + type: + type: string + original: + type: boolean + requiredFields: + type: array + items: + type: string + properties: + type: array + items: + $ref: '#/components/schemas/FakerField' + definitions: + type: array + items: + $ref: '#/components/schemas/FakerField' + FakerField: + type: object + required: + - name + - type + - value + properties: + name: + type: string + type: + type: string + value: + type: object + Field: + type: object + required: + - name + - type + properties: + name: + type: string + type: + type: string + + Configuration: + type: object + properties: + configuration: + type: object + additionalProperties: + type: number + example: + "ES": 0.8 + "US": 0.2 + numberToGenerate: + type: integer + example: 100 + schema: + $ref: '#/components/schemas/Schema' \ No newline at end of file diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/FakerApi.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/FakerApi.java new file mode 100644 index 00000000..617783dd --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/FakerApi.java @@ -0,0 +1,49 @@ +package com.sngular.multifileplugin.testIssueFaker; + +import java.util.Optional; +import java.util.List; +import java.util.Map; +import javax.validation.Valid; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.springframework.http.MediaType; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.NativeWebRequest; + +import com.sngular.multifileplugin.testIssueFaker.model.ConfigurationDTO; +import com.sngular.multifileplugin.testIssueFaker.model.FakerSchemaDTO; + +public interface FakerApi { + + /** + * POST /faker/generate-schemas + * @param configurationDTO (required) + * @return OK; (status code 200) Bad Request; (status code 400) Not found; (status code 404) + */ + + @Operation( + operationId = "generateSchema", + tags = {"SchemaGenerator"}, + responses = { + @ApiResponse(responseCode = "200", description = "OK", content = @Content(mediaType = "application/json", schema = @Schema(implementation = FakerSchemaDTO.class))), + @ApiResponse(responseCode = "400", description = "Bad Request"), + @ApiResponse(responseCode = "404", description = "Not found") + } + ) + @RequestMapping( + method = RequestMethod.POST, + value = "/faker/generate-schemas", + produces = {"application/json"} + ) + + default ResponseEntity generateSchema(@Parameter(name = "configurationDTO", description = "", required = true, schema = @Schema(description = "")) @Valid @RequestBody ConfigurationDTO configurationDTO) { + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java new file mode 100644 index 00000000..72579169 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/ConfigurationDTO.java @@ -0,0 +1,33 @@ +package com.sngular.multifileplugin.testIssueFaker.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.math.BigDecimal; +import java.util.Map; +import java.util.HashMap; +import lombok.Builder; +import lombok.Data; +import lombok.extern.jackson.Jacksonized; + +@Data +public class ConfigurationDTO { + + @JsonProperty(value ="configuration") + private Map configuration = new HashMap(); + + @JsonProperty(value ="numberToGenerate") + private Integer numberToGenerate; + + @JsonProperty(value ="schema") + private SchemaDTO schema; + + + @Builder + @Jacksonized + private ConfigurationDTO(Map configuration, Integer numberToGenerate, SchemaDTO schema) { + this.configuration = configuration; + this.numberToGenerate = numberToGenerate; + this.schema = schema; + + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java new file mode 100644 index 00000000..a25e56bd --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerFieldDTO.java @@ -0,0 +1,33 @@ +package com.sngular.multifileplugin.testIssueFaker.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; + +@Data +public class FakerFieldDTO { + + @JsonProperty(value ="value") + private Object value; + + @JsonProperty(value ="type") + @NonNull + private String type; + + @JsonProperty(value ="name") + @NonNull + private String name; + + + @Builder + @Jacksonized + private FakerFieldDTO(Object value, @NonNull String type, @NonNull String name) { + this.value = value; + this.type = type; + this.name = name; + + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java new file mode 100644 index 00000000..88e127ec --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FakerSchemaDTO.java @@ -0,0 +1,55 @@ +package com.sngular.multifileplugin.testIssueFaker.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; + +@Data +public class FakerSchemaDTO { + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @JsonProperty(value ="name") + @NonNull + private String name; + + @JsonProperty(value ="id") + private String id; + + @JsonProperty(value ="definitions") + private List definitions = new ArrayList(); + + @JsonProperty(value ="subjectName") + @NonNull + private String subjectName; + + @JsonProperty(value ="requiredFields") + private List requiredFields = new ArrayList(); + + @JsonProperty(value ="original") + private Boolean original; + + + @Builder + @Jacksonized + private FakerSchemaDTO(String type, List properties, @NonNull String name, String id, List definitions, @NonNull String subjectName, List requiredFields, Boolean original) { + this.type = type; + this.properties = properties; + this.name = name; + this.id = id; + this.definitions = definitions; + this.subjectName = subjectName; + this.requiredFields = requiredFields; + this.original = original; + + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java new file mode 100644 index 00000000..feb917d3 --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/FieldDTO.java @@ -0,0 +1,29 @@ +package com.sngular.multifileplugin.testIssueFaker.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; + +@Data +public class FieldDTO { + + @JsonProperty(value ="type") + @NonNull + private String type; + + @JsonProperty(value ="name") + @NonNull + private String name; + + + @Builder + @Jacksonized + private FieldDTO(@NonNull String type, @NonNull String name) { + this.type = type; + this.name = name; + + } + +} diff --git a/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java new file mode 100644 index 00000000..f15a7c2d --- /dev/null +++ b/multiapi-engine/src/test/resources/openapigenerator/testIssueFaker/assets/model/SchemaDTO.java @@ -0,0 +1,55 @@ +package com.sngular.multifileplugin.testIssueFaker.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import java.util.ArrayList; +import lombok.Builder; +import lombok.Data; +import lombok.NonNull; +import lombok.extern.jackson.Jacksonized; + +@Data +public class SchemaDTO { + + @JsonProperty(value ="type") + private String type; + + @JsonProperty(value ="properties") + private List properties = new ArrayList(); + + @JsonProperty(value ="name") + @NonNull + private String name; + + @JsonProperty(value ="id") + private String id; + + @JsonProperty(value ="definitions") + private List definitions = new ArrayList(); + + @JsonProperty(value ="subjectName") + @NonNull + private String subjectName; + + @JsonProperty(value ="requiredFields") + private List requiredFields = new ArrayList(); + + @JsonProperty(value ="original") + private Boolean original; + + + @Builder + @Jacksonized + private SchemaDTO(String type, List properties, @NonNull String name, String id, List definitions, @NonNull String subjectName, List requiredFields, Boolean original) { + this.type = type; + this.properties = properties; + this.name = name; + this.id = id; + this.definitions = definitions; + this.subjectName = subjectName; + this.requiredFields = requiredFields; + this.original = original; + + } + +}