Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

309 fail to execute a file #310

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>5.3.0</version>
<version>5.3.1</version>
<packaging>jar</packaging>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ public static String formatTypeOfString(final String format, final TimeType useT
String type = "String";
if (format != null) {
if (DATE_TIME.equalsIgnoreCase(format)) {
switch(useTimeType) {
case ZONED:
type = ZONED_DATE_TIME;
break;
default:
type = LOCAL_DATE_TIME;
if (Objects.requireNonNull(useTimeType) == TimeType.ZONED) {
type = ZONED_DATE_TIME;
} else {
type = LOCAL_DATE_TIME;
}

} else if (DATE.equalsIgnoreCase(format)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,19 @@ private void processModels(
final SpecFile specFile, final String fileModelToSave, final String modelPackage, final Map<String, JsonNode> basicSchemaMap,
final boolean overwrite) {
final Map<String, SchemaObject> builtSchemasMap = new HashMap<>();
basicSchemaMap.forEach((schemaName, basicSchema) ->
processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap)
);
basicSchemaMap.forEach((schemaName, basicSchema) -> {
if (ApiTool.hasType(basicSchema)) {
if (validType(ApiTool.getType(basicSchema))) {
processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap);
}
} else {
processModel(specFile, fileModelToSave, modelPackage, basicSchemaMap, overwrite, schemaName, basicSchema, builtSchemasMap);
}
});
}

private boolean validType(final String type) {
return !TypeConstants.NO_PROCESS_TYPE.contains(type);
}

private void processModel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ public final class TypeConstants {

public static final Set<String> NO_IMPORT_TYPE = Set.of(STRING, INTEGER, OBJECT);

public static final Set<String> NO_PROCESS_TYPE = Set.of(NUMBER,
BOOLEAN,
BIG_DECIMAL,
INTEGER,
DOUBLE,
FLOAT,
LONG,
STRING,
ENUM,
LOCALDATE,
LOCALDATETIME,
ZONEDDATE,
ZONEDDATETIME,
OFFSETDATE,
OFFSETDATETIME);
public static final Set<String> ALL_TYPES = Set.of(
NUMBER,
BOOLEAN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Objects;
import java.util.Set;

import com.sngular.api.generator.plugin.exception.GeneratorTemplateException;
import com.sngular.api.generator.plugin.openapi.exception.OverwritingApiFilesException;
import com.sngular.api.generator.plugin.openapi.model.AuthObject;
import com.sngular.api.generator.plugin.openapi.model.PathObject;
Expand Down Expand Up @@ -106,7 +107,7 @@ public final void fillTemplateRestClient(final String filePathToSave) throws IOE

}

public final void fillTemplateAuth(final String filePathToSave, final String authName) throws IOException, TemplateException {
public final void fillTemplateAuth(final String filePathToSave, final String authName) throws IOException {
final File fileToSave = new File(filePathToSave);
final var nameAuthClass = authName + JAVA_EXTENSION;
final String pathToSaveMainClass = fileToSave.toPath().resolve(nameAuthClass).toString();
Expand All @@ -116,7 +117,7 @@ public final void fillTemplateAuth(final String filePathToSave, final String aut

public final void fillTemplateCustom(
final String filePathToSave, final String annotationFileName, final String validatorFileName, final String annotationTemplate,
final String validatorTemplate) throws IOException, TemplateException {
final String validatorTemplate) throws IOException {
final File fileToSave = new File(filePathToSave);
final Path pathToValidatorPackage = fileToSave.toPath().resolve("customvalidator");
pathToValidatorPackage.toFile().mkdirs();
Expand Down Expand Up @@ -158,18 +159,20 @@ public final void calculateJavaEEPackage(final Integer springBootVersion) {
}
}

private void writeTemplateToFile(final String templateName, final Map<String, Object> root, final String path) throws IOException, TemplateException {
private void writeTemplateToFile(final String templateName, final Map<String, Object> root, final String path) throws IOException {
writeTemplateToFile(templateName, root, path, true);
}

private void writeTemplateToFile(final String templateName, final Map<String, Object> root, final String path, final boolean checkOverwrite) throws IOException,
TemplateException {
private void writeTemplateToFile(final String templateName, final Map<String, Object> root, final String path, final boolean checkOverwrite) throws IOException {
final Template template = cfg.getTemplate(templateName);

if (!Files.exists(Path.of(path)) || checkOverwrite) {
final FileWriter writer = new FileWriter(path);
template.process(root, writer);
writer.close();
try (FileWriter writer = new FileWriter(path)) {
template.process(root, writer);
} catch (IOException | TemplateException exception) {
final var schema = root.get("schema");
throw new GeneratorTemplateException(String.format(" Error processing template %s with object %s", templateName, ((SchemaObject) schema).getClassName()), exception);
}
} else {
throw new OverwritingApiFilesException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,18 @@ public final class OpenApiGeneratorFixtures {
.build()
);

static final List<SpecFile> TEST_CREATE_BASIC_DTO = List.of(
SpecFile
.builder()
.filePath("openapigenerator/testCreateBasicDTO/api-test.yml")
.apiPackage("com.sngular.multifileplugin.testCreateBasicDTO")
.modelPackage("com.sngular.multifileplugin.testCreateBasicDTO.model")
.clientPackage("com.sngular.multifileplugin.testCreateBasicDTO.client")
.modelNameSuffix("DTO")
.useLombokModelAnnotation(true)
.build()
);

static final List<SpecFile> TEST_ISSUE_FAKER = List.of(
SpecFile
.builder()
Expand Down Expand Up @@ -1281,6 +1293,30 @@ 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> validateCreateBasicDTO() {

final String DEFAULT_TARGET_API = "generated/com/sngular/multifileplugin/testCreateBasicDTO";

final String DEFAULT_MODEL_API = "generated/com/sngular/multifileplugin/testCreateBasicDTO/model";

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

final String COMMON_PATH = "openapigenerator/testCreateBasicDTO/";

final String ASSETS_PATH = COMMON_PATH + "assets/";

final List<String> expectedTestApiFile = List.of(
ASSETS_PATH + "TestApi.java"
);

final List<String> expectedTestApiModelFiles = List.of(
ASSETS_PATH + "model/AddressDTO.java",
ASSETS_PATH + "model/TestDTO.java"
);

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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ static Stream<Arguments> fileSpecToProcess() {
OpenApiGeneratorFixtures.validateValidationAnnotationsLombok(SPRING_BOOT_VERSION)),
Arguments.of("testCreateDTO", OpenApiGeneratorFixtures.TEST_CREATE_DTO,
OpenApiGeneratorFixtures.validateCreateDTO()),
Arguments.of("testCreateBasicDTO", OpenApiGeneratorFixtures.TEST_CREATE_BASIC_DTO,
OpenApiGeneratorFixtures.validateCreateBasicDTO()),
Arguments.of("testIssueFaker", OpenApiGeneratorFixtures.TEST_ISSUE_FAKER,
OpenApiGeneratorFixtures.validateIssueFaker()),
Arguments.of("testDateTime", OpenApiGeneratorFixtures.TEST_DATE_TIME,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
openapi: "3.0.0"
info:
contact:
name: Os3 Team
email: os3-info@sngular.com
version: 1.0.0
title: Testing example file
license:
name: MIT
description: Testing example file
servers:
- url: http://localhost:8080/v1
tags:
- name: testAdditionalProperties
description: Test service
paths:
/test:
summary: testCreateDTO
get:
summary: testCreateDTO
description: Test File for SCC MultiApi Plugin.
tags:
- test
operationId: testCreateDTO
responses:
'200':
$ref: '#/components/responses/testCreate'
components:
responses:
testCreate:
description: An object with additional properties
content:
application/json:
schema:
$ref: '#/components/schemas/test'
schemas:
test:
type: object
required:
- id
- age
- properties
properties:
id:
$ref: "#/components/schemas/strProperty"
age:
type: number
format: int32
properties:
$ref: "#/components/schemas/strProperty"
address:
type: object
required:
- country
- city
properties:
street:
$ref: "#/components/schemas/strProperty"
country:
$ref: "#/components/schemas/booleanProperty"
city:
$ref: "#/components/schemas/strProperty"
strProperty:
type: string
booleanProperty:
type: boolean
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.sngular.multifileplugin.testCreateBasicDTO;

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.testCreateBasicDTO.model.TestDTO;

public interface TestApi {

/**
* GET /test: testCreateDTO
* @return An object with additional properties; (status code 200)
*/

@Operation(
operationId = "testCreateDTO",
summary = "testCreateDTO",
tags = {"test"},
responses = {
@ApiResponse(responseCode = "200", description = "An object with additional properties", content = @Content(mediaType = "application/json", schema = @Schema(implementation = TestDTO.class)))
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/test",
produces = {"application/json"}
)

default ResponseEntity<TestDTO> testCreateDTO() {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sngular.multifileplugin.testCreateBasicDTO.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
import lombok.extern.jackson.Jacksonized;

@Data
public class AddressDTO {

@JsonProperty(value ="country")
@NonNull
private Boolean country;

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

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


@Builder
@Jacksonized
private AddressDTO(@NonNull Boolean country, @NonNull String city, String street) {
this.country = country;
this.city = city;
this.street = street;

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.sngular.multifileplugin.testCreateBasicDTO.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
import lombok.Builder;
import lombok.Data;
import lombok.NonNull;
import lombok.extern.jackson.Jacksonized;

@Data
public class TestDTO {

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

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

@JsonProperty(value ="address")
private AddressDTO address;

@JsonProperty(value ="age")
@NonNull
private BigDecimal age;


@Builder
@Jacksonized
private TestDTO(@NonNull String properties, @NonNull String id, AddressDTO address, @NonNull BigDecimal age) {
this.properties = properties;
this.id = id;
this.address = address;
this.age = age;

}

}
6 changes: 3 additions & 3 deletions scs-multiapi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}

group = 'com.sngular'
version = '5.3.0'
version = '5.3.1'

def SCSMultiApiPluginGroupId = group
def SCSMultiApiPluginVersion = version
Expand All @@ -30,7 +30,7 @@ dependencies {
shadow localGroovy()
shadow gradleApi()

implementation 'com.sngular:multiapi-engine:5.3.0'
implementation 'com.sngular:multiapi-engine:5.3.1'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3'
}
Expand Down Expand Up @@ -98,7 +98,7 @@ testing {

integrationTest(JvmTestSuite) {
dependencies {
implementation 'com.sngular:scs-multiapi-gradle-plugin:5.3.0'
implementation 'com.sngular:scs-multiapi-gradle-plugin:5.3.1'
implementation 'org.assertj:assertj-core:3.24.2'
}

Expand Down
Loading
Loading