Skip to content

Commit

Permalink
272 openapi issue build maps (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
jemacineiras authored Aug 29, 2023
1 parent e829981 commit a50bb7e
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 33 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# SCS MultiApi Plugin

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/9a486e91e2b245d8abe2e523c95bdf9a)](https://www.codacy.com/gh/sngular/scs-multiapi-plugin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=sngular/scs-multiapi-plugin&utm_campaign=Badge_Grade)
[![Maven Central](https://img.shields.io/maven-central/v/com.sngular/scs-multiapi-maven-plugin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.sngular%22%20AND%20a:%22scs-multiapi-maven-plugin%22)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/4a9be5a4b6ab48afba293b2315edd47e)](https://app.codacy.com/gh/sngular/scs-multiapi-plugin/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)[![Maven Central](https://img.shields.io/maven-central/v/com.sngular/scs-multiapi-maven-plugin.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.sngular%22%20AND%20a:%22scs-multiapi-maven-plugin%22)

This is a plugin designed to help developers automatizing the creation of
code classes from YML files based on AsyncApi and OpenAPI. It is presented in 2 flavours
Expand Down Expand Up @@ -61,7 +60,7 @@ As commented above, they both could be used at the same time, setting a double
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>4.3.12</version>
<version>4.9.8</version>
<executions>
<execution>
<id>asyncapi</id>
Expand Down Expand Up @@ -115,7 +114,7 @@ Apply the plugin in the `build.gradle` file and invoke the task.
```groovy
plugins {
id 'java'
id 'com.sngular.scs-multiapi-gradle-plugin' version '4.3.12'
id 'com.sngular.scs-multiapi-gradle-plugin' version '4.9.8'
openapimodel {
Expand Down Expand Up @@ -154,7 +153,7 @@ which the plugin is designed.
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>4.3.12</version>
<version>4.9.8</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down Expand Up @@ -577,7 +576,7 @@ file. Here is an example of a basic configuration:
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>4.3.12</version>
<version>4.9.8</version>
<executions>
<execution>
<goals>
Expand Down
2 changes: 1 addition & 1 deletion multiapi-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>4.9.9</version>
<version>4.9.11</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,12 @@ private static Set<SchemaFieldObject> processMap(
final Map<String, SchemaObject> compositedSchemas, final List<String> antiLoopList, final Path baseDir) {
final Set<SchemaFieldObject> fieldObjectArrayList = new HashSet<>();

if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema))) {
ApiTool.getProperties(schema).forEachRemaining(
processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
if (TypeConstants.OBJECT.equalsIgnoreCase(ApiTool.getType(schema)) && ApiTool.hasProperties(schema)) {
ApiTool.getProperties(schema).forEachRemaining(processProperties(totalSchemas, compositedSchemas, fieldObjectArrayList, specFile, schema, antiLoopList, baseDir));
}

if (ApiTool.hasProperties(schema)) {
fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas,
antiLoopList, ADDITIONAL_PROPERTIES, baseDir));
if (ApiTool.hasAdditionalProperties(schema)) {
fieldObjectArrayList.addAll(processAdditionalProperties(fieldName, schema, specFile, totalSchemas, compositedSchemas, antiLoopList, ADDITIONAL_PROPERTIES, baseDir));
}

return fieldObjectArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import com.sngular.api.generator.plugin.openapi.model.TypeConstants.TimeType;
import com.sngular.api.generator.plugin.openapi.parameter.SpecFile;
import com.sngular.api.generator.test.utils.TestUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;

@Slf4j
public final class OpenApiGeneratorFixtures {

final static String GENERATED = "generated";
Expand Down Expand Up @@ -364,6 +366,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 @@ -1126,8 +1140,6 @@ static Function<Path, Boolean> validateValidationAnnotations(int springBootVersi

final String DEFAULT_EXCEPTION_API = "generated/com/sngular/multifileplugin/testapi/model/exception";

final String DEFAULT_CUSTOMVALIDATOR_API = "generated/com/sngular/multifileplugin/testapi/model/customvalidator";

final String COMMON_PATH = "openapigenerator/testValidationAnnotations/";

final String ASSETS_PATH = COMMON_PATH + "assets/";
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 Expand Up @@ -1372,8 +1409,9 @@ private static Boolean commonTest(
assertThat(targetModelException).isNotEmptyDirectory();
TestUtils.validateFiles(expectedExceptionFiles, targetModelException);
}
} catch (IOException e) {
} catch (IOException | NullPointerException e) {
result = Boolean.FALSE;
log.error(e.getLocalizedMessage());
}
return result;
}
Expand All @@ -1389,8 +1427,9 @@ private static Boolean customValidatorTest(final Path resultPath, final List<Str
assertThat(targetCustomValidatorFolder).isNotEmptyDirectory();
TestUtils.validateFiles(expectedValidatorFiles, targetCustomValidatorFolder);
}
} catch (IOException e) {
} catch (IOException | NullPointerException e) {
result = Boolean.FALSE;
log.error(e.getLocalizedMessage());
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ static void setup() {

static Stream<Arguments> fileSpecToProcess() {
return Stream.of(
Arguments.of("testAllOf", OpenApiGeneratorFixtures.TEST_ALL_OF, OpenApiGeneratorFixtures.validateAllOf()),
Arguments.of("testComplexAnyOf", OpenApiGeneratorFixtures.TEST_COMPLEX_ANY_OF, OpenApiGeneratorFixtures.validateComplexAnyOf()),
Arguments.of("testAllOfLombok", OpenApiGeneratorFixtures.TEST_ALL_OF_LOMBOK, OpenApiGeneratorFixtures.validateAllOfLombok()),
Arguments.of("testOverWriteModelTrue", OpenApiGeneratorFixtures.TEST_OVER_WRITE_MODEL_TRUE, OpenApiGeneratorFixtures.validateOverwriteModeTrue()),
Arguments.of("testApiClientGeneration", OpenApiGeneratorFixtures.TEST_API_CLIENT_GENERATION, OpenApiGeneratorFixtures.validateApiClientGeneration()),
Arguments.of("testInlineSchemaCreation", OpenApiGeneratorFixtures.TEST_INLINE_SCHEMA_CREATION, OpenApiGeneratorFixtures.validateInlineSchemaCreation()),
Arguments.of("testAllOf", OpenApiGeneratorFixtures.TEST_ALL_OF,
OpenApiGeneratorFixtures.validateAllOf()),
Arguments.of("testComplexAnyOf", OpenApiGeneratorFixtures.TEST_COMPLEX_ANY_OF,
OpenApiGeneratorFixtures.validateComplexAnyOf()),
Arguments.of("testAllOfLombok", OpenApiGeneratorFixtures.TEST_ALL_OF_LOMBOK,
OpenApiGeneratorFixtures.validateAllOfLombok()),
Arguments.of("testOverWriteModelTrue", OpenApiGeneratorFixtures.TEST_OVER_WRITE_MODEL_TRUE,
OpenApiGeneratorFixtures.validateOverwriteModeTrue()),
Arguments.of("testApiClientGeneration", OpenApiGeneratorFixtures.TEST_API_CLIENT_GENERATION,
OpenApiGeneratorFixtures.validateApiClientGeneration()),
Arguments.of("testInlineSchemaCreation", OpenApiGeneratorFixtures.TEST_INLINE_SCHEMA_CREATION,
OpenApiGeneratorFixtures.validateInlineSchemaCreation()),
Arguments.of("testApiParametersWithContentGeneration", OpenApiGeneratorFixtures.TEST_PARAMETER_WITH_CONTENT_GENERATION,
OpenApiGeneratorFixtures.validateParametersWithSchemaGeneration()),
Arguments.of("testApiPathWithSpecialCharGeneration", OpenApiGeneratorFixtures.TEST_PATH_WITH_SLASH_GENERATION,
Expand Down Expand Up @@ -92,16 +98,22 @@ 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,
OpenApiGeneratorFixtures.validateDateTimeZoned()),
Arguments.of("testDateTimeOffset", OpenApiGeneratorFixtures.TEST_DATE_TIME_OFFSET,
OpenApiGeneratorFixtures.validateDateTimeOffset()),
Arguments.of("testListString", OpenApiGeneratorFixtures.TEST_LIST_STRING, OpenApiGeneratorFixtures.validateListString()),
Arguments.of("testReferenceFile", OpenApiGeneratorFixtures.TEST_REFERENCE_FILE, OpenApiGeneratorFixtures.validateReferenceFile()),
Arguments.of("testQueryParam", OpenApiGeneratorFixtures.TEST_QUERY_PARAM, OpenApiGeneratorFixtures.validateQueryParam()),
Arguments.of("testApiWithNoComponents", OpenApiGeneratorFixtures.TEST_API_WITH_NO_COMPONENTS, OpenApiGeneratorFixtures.validateApiWithNoComponents()),
Arguments.of("testListString", OpenApiGeneratorFixtures.TEST_LIST_STRING,
OpenApiGeneratorFixtures.validateListString()),
Arguments.of("testReferenceFile", OpenApiGeneratorFixtures.TEST_REFERENCE_FILE,
OpenApiGeneratorFixtures.validateReferenceFile()),
Arguments.of("testQueryParam", OpenApiGeneratorFixtures.TEST_QUERY_PARAM,
OpenApiGeneratorFixtures.validateQueryParam()),
Arguments.of("testApiWithNoComponents", OpenApiGeneratorFixtures.TEST_API_WITH_NO_COMPONENTS,
OpenApiGeneratorFixtures.validateApiWithNoComponents()),
Arguments.of("testRestrictionSchema", OpenApiGeneratorFixtures.TEST_RESTRICTION_SCHEMA,
OpenApiGeneratorFixtures.validateRestrictionsSchema())
);
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);
}

}
Loading

0 comments on commit a50bb7e

Please sign in to comment.