forked from loafle/openapi-generator-original
fix incorrect JsonProperty in pojo constructor (#18421)
This commit is contained in:
parent
58aad760f0
commit
d71df6ab85
@ -62,7 +62,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi
|
|||||||
{{#jsonb}}@JsonbCreator{{/jsonb}}{{#jackson}}@JsonCreator{{/jackson}}
|
{{#jsonb}}@JsonbCreator{{/jsonb}}{{#jackson}}@JsonCreator{{/jackson}}
|
||||||
public {{classname}}(
|
public {{classname}}(
|
||||||
{{#readOnlyVars}}
|
{{#readOnlyVars}}
|
||||||
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nillable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(JSON_PROPERTY_{{nameInSnakeCase}}{{#required}}, required = true{{/required}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
{{#jsonb}}@JsonbProperty(value = "{{baseName}}"{{^required}}, nillable = true{{/required}}){{/jsonb}}{{#jackson}}@JsonProperty(value = JSON_PROPERTY_{{nameInSnakeCase}}{{#required}}, required = true{{/required}}){{/jackson}} {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||||
{{/readOnlyVars}}
|
{{/readOnlyVars}}
|
||||||
) {
|
) {
|
||||||
{{#readOnlyVars}}
|
{{#readOnlyVars}}
|
||||||
|
@ -1899,6 +1899,38 @@ public class JavaClientCodegenTest {
|
|||||||
.containsWithNameAndAttributes("JsonbProperty", ImmutableMap.of("value", "\"c\""));
|
.containsWithNameAndAttributes("JsonbProperty", ImmutableMap.of("value", "\"c\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMicroprofileGenerateCorrectJacksonGenerator_issue18336() throws Exception {
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
properties.put(JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0");
|
||||||
|
properties.put(CodegenConstants.SERIALIZATION_LIBRARY, JavaClientCodegen.SERIALIZATION_LIBRARY_JACKSON);
|
||||||
|
|
||||||
|
File output = Files.createTempDirectory("test").toFile();
|
||||||
|
output.deleteOnExit();
|
||||||
|
|
||||||
|
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||||
|
|
||||||
|
.setAdditionalProperties(properties)
|
||||||
|
.setGeneratorName("java")
|
||||||
|
.setLibrary(JavaClientCodegen.MICROPROFILE)
|
||||||
|
.setInputSpec("src/test/resources/bugs/issue_18336.yaml")
|
||||||
|
.setOutputDir(output.getAbsolutePath().replace("\\", "/"));
|
||||||
|
|
||||||
|
final ClientOptInput clientOptInput = configurator.toClientOptInput();
|
||||||
|
DefaultGenerator generator = new DefaultGenerator();
|
||||||
|
Map<String, File> files = generator.opts(clientOptInput).generate().stream()
|
||||||
|
.collect(Collectors.toMap(File::getName, Function.identity()));
|
||||||
|
|
||||||
|
JavaFileAssert.assertThat(files.get("Pet.java"))
|
||||||
|
.assertConstructor("String")
|
||||||
|
.assertConstructorAnnotations()
|
||||||
|
.containsWithName("JsonCreator")
|
||||||
|
.toConstructor()
|
||||||
|
.hasParameter("name")
|
||||||
|
.assertParameterAnnotations()
|
||||||
|
.containsWithNameAndAttributes("JsonProperty", ImmutableMap.of("value", "JSON_PROPERTY_NAME", "required", "true"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testJavaClientDefaultValues_issueNoNumber() throws Exception {
|
public void testJavaClientDefaultValues_issueNoNumber() throws Exception {
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
openapi: 3.0.0
|
||||||
|
info:
|
||||||
|
title: "OpenAPI Definition"
|
||||||
|
version: "0.0.1"
|
||||||
|
paths:
|
||||||
|
/pets:
|
||||||
|
get:
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: "Return Pet with name"
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Pet'
|
||||||
|
|
||||||
|
components:
|
||||||
|
schemas:
|
||||||
|
Pet:
|
||||||
|
type: object
|
||||||
|
required:
|
||||||
|
- name
|
||||||
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
readOnly: true
|
Loading…
x
Reference in New Issue
Block a user