Skip to content

Commit

Permalink
[Java][microprofile] fix constructor creation (#12627)
Browse files Browse the repository at this point in the history
  • Loading branch information
borsch authored Jul 3, 2022
1 parent b97a4ad commit d36daba
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,34 @@ public void testMicroprofileRestClientVersion_3_0() throws Exception {
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();
Expand Down
53 changes: 53 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_12622.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
}

0 comments on commit d36daba

Please sign in to comment.