forked from loafle/openapi-generator-original
[Java][microprofile] fix constructor creation (#12627)
This commit is contained in:
@@ -72,7 +72,7 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi
|
||||
@JsonbCreator
|
||||
public {{classname}}(
|
||||
{{#readOnlyVars}}
|
||||
@JsonbProperty("{{baseName}}") {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
@JsonbProperty(value = "{{baseName}}"{{^required}}, nillable = true{{/required}}) {{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}
|
||||
{{/readOnlyVars}}
|
||||
) {
|
||||
{{#readOnlyVars}}
|
||||
|
||||
@@ -1513,6 +1513,34 @@ public class JavaClientCodegenTest {
|
||||
output.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMicroprofileGenerateCorrectJsonbCreator_issue12622() throws Exception {
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put(JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0");
|
||||
|
||||
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_12622.json")
|
||||
.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("Foo.java"))
|
||||
.printFileContent()
|
||||
.fileContains(
|
||||
"@JsonbProperty(value = \"b\", nillable = true) String b",
|
||||
"@JsonbProperty(value = \"c\") Integer c"
|
||||
);
|
||||
}
|
||||
|
||||
public void testExtraAnnotations(String library) throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
output.deleteOnExit();
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"openapi": "3.0.1",
|
||||
"info": {
|
||||
"title": "Bug Report",
|
||||
"version": "1.0.0"
|
||||
},
|
||||
"paths": {
|
||||
"/foo": {
|
||||
"get": {
|
||||
"operationId": "getFoo",
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/Foo"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": "get foo"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Foo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"a": {
|
||||
"type": "string"
|
||||
},
|
||||
"b": {
|
||||
"type": "string",
|
||||
"readOnly": true
|
||||
},
|
||||
"c": {
|
||||
"type": "integer",
|
||||
"readOnly": true
|
||||
},
|
||||
"d:": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"c",
|
||||
"d"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user