Skip to content

Commit

Permalink
#251 Fix Parameter without description
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras committed Aug 21, 2023
1 parent d70f7cd commit 5bcaeba
Show file tree
Hide file tree
Showing 10 changed files with 425 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,13 @@ private static Set<SchemaFieldObject> processMap(
final Set<SchemaFieldObject> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,18 @@ public final class OpenApiGeneratorFixtures {
.build()
);

static final List<SpecFile> 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<SpecFile> TEST_DATE_TIME = List.of(
SpecFile
.builder()
Expand Down Expand Up @@ -1222,6 +1234,31 @@ static Function<Path, Boolean> validateCreateDTO() {
return (path) -> commonTest(path, expectedTestApiFile, expectedTestApiModelFiles, DEFAULT_TARGET_API, DEFAULT_MODEL_API, Collections.emptyList(), DEFAULT_EXCEPTION_API);
}

static Function<Path, Boolean> 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<String> expectedTestApiFile = List.of(
ASSETS_PATH + "FakerApi.java"
);

final List<String> 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<Path, Boolean> validateDateTime() {
final String DEFAULT_TARGET_API = "generated/com/sngular/multifileplugin/testDateTime";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ static Stream<Arguments> 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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
@@ -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<FakerSchemaDTO> generateSchema(@Parameter(name = "configurationDTO", description = "", required = true, schema = @Schema(description = "")) @Valid @RequestBody ConfigurationDTO configurationDTO) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

}
Original file line number Diff line number Diff line change
@@ -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<String, BigDecimal> configuration = new HashMap<String, BigDecimal>();

@JsonProperty(value ="numberToGenerate")
private Integer numberToGenerate;

@JsonProperty(value ="schema")
private SchemaDTO schema;


@Builder
@Jacksonized
private ConfigurationDTO(Map<String, BigDecimal> configuration, Integer numberToGenerate, SchemaDTO schema) {
this.configuration = configuration;
this.numberToGenerate = numberToGenerate;
this.schema = schema;

}

}
Original file line number Diff line number Diff line change
@@ -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;

}

}
Original file line number Diff line number Diff line change
@@ -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<FakerFieldDTO> properties = new ArrayList<FakerFieldDTO>();

@JsonProperty(value ="name")
@NonNull
private String name;

@JsonProperty(value ="id")
private String id;

@JsonProperty(value ="definitions")
private List<FakerFieldDTO> definitions = new ArrayList<FakerFieldDTO>();

@JsonProperty(value ="subjectName")
@NonNull
private String subjectName;

@JsonProperty(value ="requiredFields")
private List<String> requiredFields = new ArrayList<String>();

@JsonProperty(value ="original")
private Boolean original;


@Builder
@Jacksonized
private FakerSchemaDTO(String type, List<FakerFieldDTO> properties, @NonNull String name, String id, List<FakerFieldDTO> definitions, @NonNull String subjectName, List<String> 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;

}

}
Loading

0 comments on commit 5bcaeba

Please sign in to comment.