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

Bug#11899 ignore unknown jackson annotation #12471

Open
wants to merge 1 commit into
base: 3.0.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.swagger.codegen.v3.service;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.DefaultGenerator;
import io.swagger.codegen.config.CodegenConfigurator;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import io.swagger.v3.oas.models.OpenAPI;
Expand All @@ -15,7 +18,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

public class GeneratorServiceTest {

Expand Down Expand Up @@ -210,6 +218,32 @@ public void testGeneratorService_notNullJacksonAnnotationJava_True() throws IOEx
}
}

@Test
public void testIgnoreUnknownJacksonAnnotationJava_True() throws IOException {
String path = getTmpFolder().getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-9203.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("ignoreUnknownJacksonAnnotation", true)
);

List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
for (File f: files) {
String relPath = f.getAbsolutePath().substring(path.length());
if ("/src/main/java/io/swagger/client/model/OrderLineAudit.java".equals(relPath)) {
Assert.assertTrue(FileUtils.readFileToString(f).contains("@JsonIgnoreProperties(ignoreUnknown = true)"));
Assert.assertTrue(FileUtils.readFileToString(f).contains("import com.fasterxml.jackson.annotation.JsonIgnoreProperties;"));
}
}
}

@Test(description = "test generator service with java enum parameters in type")
public void testGeneratorService_WithEnumParametersType() throws IOException {

Expand Down Expand Up @@ -264,6 +298,33 @@ public void testGeneratorService_notNullJacksonAnnotationJava_False() throws IOE
}
}

@Test(description = "test generator service with java")
public void testGeneratorService_ignoreUnknownJacksonAnnotationJava_False() throws IOException {

String path = getTmpFolder().getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("java")
.spec(loadSpecAsNode("3_0_0/issue-9203.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("ignoreUnknownJacksonAnnotation", false)
);

List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
for (File f: files) {
String relPath = f.getAbsolutePath().substring(path.length());
if ("/src/main/java/io/swagger/client/model/OrderLineAudit.java".equals(relPath)) {
Assert.assertFalse(FileUtils.readFileToString(f).contains("@JsonIgnoreProperties(ignoreUnknown = true)"));
Assert.assertFalse(FileUtils.readFileToString(f).contains("import com.fasterxml.jackson.annotation.JsonIgnoreProperties"));
}
}
}


@Test(description = "test generator service with spring")
public void testGeneratorService_notNullJacksonAnnotationSpring_True() throws IOException {
Expand Down Expand Up @@ -292,6 +353,33 @@ public void testGeneratorService_notNullJacksonAnnotationSpring_True() throws IO
}
}

@Test(description = "test generator service with spring")
public void testGeneratorService_ignoreUnknownJacksonAnnotationSpring_True() throws IOException {

String path = getTmpFolder().getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("spring")
.spec(loadSpecAsNode("3_0_0/issue-9203.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("ignoreUnknownJacksonAnnotation", true)
);

List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
for (File f: files) {
String relPath = f.getAbsolutePath().substring(path.length());
if ("/src/main/java/io/swagger/client/model/OrderLineAudit.java".equals(relPath)) {
Assert.assertTrue(FileUtils.readFileToString(f).contains("@JsonIgnoreProperties(ignoreUnknown = true)"));
Assert.assertTrue(FileUtils.readFileToString(f).contains("import com.fasterxml.jackson.annotation.JsonIgnoreProperties"));
}
}
}

@Test(description = "test generator service with spring")
public void testGeneratorService_notNullJacksonAnnotationSpring_False() throws IOException {

Expand Down Expand Up @@ -319,6 +407,33 @@ public void testGeneratorService_notNullJacksonAnnotationSpring_False() throws I
}
}

@Test(description = "test generator service with spring")
public void testGeneratorService_ignoreUnknownJacksonAnnotationSpring_False() throws IOException {

String path = getTmpFolder().getAbsolutePath();
GenerationRequest request = new GenerationRequest();
request
.codegenVersion(GenerationRequest.CodegenVersion.V3)
.type(GenerationRequest.Type.CLIENT)
.lang("spring")
.spec(loadSpecAsNode("3_0_0/issue-9203.yaml", true, false))
.options(
new Options()
.outputDir(path)
.addAdditionalProperty("ignoreUnknownJacksonAnnotation", false)
);

List<File> files = new GeneratorService().generationRequest(request).generate();
Assert.assertFalse(files.isEmpty());
for (File f: files) {
String relPath = f.getAbsolutePath().substring(path.length());
if ("/src/main/java/io/swagger/client/model/OrderLineAudit.java".equals(relPath)) {
Assert.assertFalse(FileUtils.readFileToString(f).contains("@JsonIgnoreProperties(ignoreUnknown = true)"));
Assert.assertFalse(FileUtils.readFileToString(f).contains("import com.fasterxml.jackson.annotation.JsonIgnoreProperties"));
}
}
}

@Test(description = "test generator oneOf ComposedSchema Properties")
public void testGenerator_FlattenInlineComposedSchema() throws IOException {

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@
</repositories>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<swagger-codegen-generators-version>1.0.52</swagger-codegen-generators-version>
<swagger-codegen-generators-version>1.0.53-SNAPSHOT</swagger-codegen-generators-version>
<swagger-core-version>2.2.22</swagger-core-version>
<swagger-core-version-v1>1.6.14</swagger-core-version-v1>
<swagger-parser-version>2.1.22</swagger-parser-version>
Expand Down