Skip to content

Commit b3244e9

Browse files
Fix child constructor no longer has invalid access to parent field (#23205)
* Fix fix that child constructor was invalid when having readonly field in parent * add classType field * fix test * update samples --------- Co-authored-by: bdurca <rca@bankdata.dk>
1 parent 3e0a9f7 commit b3244e9

File tree

173 files changed

+627
-554
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+627
-554
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/microprofile/pojo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi
5252
{{{.}}}
5353
{{/vendorExtensions.x-field-extra-annotation}}
5454
{{#isContainer}}
55-
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
55+
protected {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
5656
{{/isContainer}}
5757
{{^isContainer}}
58-
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
58+
protected {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
5959
{{/isContainer}}
6060
{{/vars}}
6161
{{>additional_properties}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/microprofile/JavaMicroprofileServerCodegenTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,31 @@ public void testGeneratedApiExceptionMapperDoesNotHaveProviderAnnotationWhenDisa
235235
.assertTypeAnnotations()
236236
.doesNotContainWithName("Provider");
237237
}
238+
239+
@Test
240+
public void testClientCanAccessFieldInParent() throws Exception {
241+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
242+
output.deleteOnExit();
243+
244+
OpenAPI openAPI = new OpenAPIParser()
245+
.readLocation("src/test/resources/bugs/issue_23034.yaml", null, new ParseOptions()).getOpenAPI();
246+
247+
codegen.setOutputDir(output.getAbsolutePath());
248+
codegen.additionalProperties().put(JavaClientCodegen.MICROPROFILE_GLOBAL_EXCEPTION_MAPPER, "false");
249+
250+
ClientOptInput input = new ClientOptInput()
251+
.openAPI(openAPI)
252+
.config(codegen);
253+
254+
List<File> files = new DefaultGenerator().opts(input).generate();
255+
256+
Map<String, File> filesMap = files.stream()
257+
.collect(Collectors.toMap(File::getName, Function.identity()));
258+
259+
validateJavaSourceFiles(files);
260+
261+
JavaFileAssert.assertThat(filesMap.get("Parent.java"))
262+
.fileContains("protected String parentField;");
263+
}
238264
}
239265

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
openapi: 3.0.4
3+
info:
4+
title: Reproduce
5+
version: 'v1'
6+
components:
7+
schemas:
8+
Child:
9+
required:
10+
- childField1
11+
type: object
12+
allOf:
13+
- $ref: "#/components/schemas/Parent"
14+
properties:
15+
childField1:
16+
type: string
17+
18+
Parent:
19+
required:
20+
- classType
21+
- parentField
22+
type: object
23+
properties:
24+
parentField:
25+
type: string
26+
readOnly: true
27+
classType:
28+
description: Identifier of discriminator mapping class.
29+
enum:
30+
- Child
31+
type: string
32+
discriminator:
33+
propertyName: classType
34+
mapping:
35+
Child: "#/components/schemas/Child"
36+
paths:
37+
'/v1/reproduce':
38+
get:
39+
responses:
40+
'200':
41+
content:
42+
application/json:
43+
schema:
44+
type: array
45+
items:
46+
$ref: '#/components/schemas/Child'
47+
description: 'reproduce'

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/Category.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public class Category {
3636

3737
public static final String JSON_PROPERTY_ID = "id";
3838

39-
private Long id;
39+
protected Long id;
4040

4141
public static final String JSON_PROPERTY_NAME = "name";
4242

43-
private String name;
43+
protected String name;
4444

4545

4646
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/ModelApiResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class ModelApiResponse {
3838

3939
public static final String JSON_PROPERTY_CODE = "code";
4040

41-
private Integer code;
41+
protected Integer code;
4242

4343
public static final String JSON_PROPERTY_TYPE = "type";
4444

45-
private String type;
45+
protected String type;
4646

4747
public static final String JSON_PROPERTY_MESSAGE = "message";
4848

49-
private String message;
49+
protected String message;
5050

5151

5252
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/Order.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ public class Order {
4141

4242
public static final String JSON_PROPERTY_ID = "id";
4343

44-
private Long id;
44+
protected Long id;
4545

4646
public static final String JSON_PROPERTY_PET_ID = "petId";
4747

48-
private Long petId;
48+
protected Long petId;
4949

5050
public static final String JSON_PROPERTY_QUANTITY = "quantity";
5151

52-
private Integer quantity;
52+
protected Integer quantity;
5353

5454
public static final String JSON_PROPERTY_SHIP_DATE = "shipDate";
5555

56-
private Date shipDate;
56+
protected Date shipDate;
5757

5858
public enum StatusEnum {
5959

@@ -92,11 +92,11 @@ public static StatusEnum fromValue(String value) {
9292
* Order Status
9393
*/
9494

95-
private StatusEnum status;
95+
protected StatusEnum status;
9696

9797
public static final String JSON_PROPERTY_COMPLETE = "complete";
9898

99-
private Boolean complete = false;
99+
protected Boolean complete = false;
100100

101101

102102
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/Pet.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ public class Pet {
4545

4646
public static final String JSON_PROPERTY_ID = "id";
4747

48-
private Long id;
48+
protected Long id;
4949

5050
public static final String JSON_PROPERTY_CATEGORY = "category";
5151

52-
private Category category;
52+
protected Category category;
5353

5454
public static final String JSON_PROPERTY_NAME = "name";
5555

56-
private String name;
56+
protected String name;
5757

5858
public static final String JSON_PROPERTY_PHOTO_URLS = "photoUrls";
5959

60-
private List<String> photoUrls = new ArrayList<>();
60+
protected List<String> photoUrls = new ArrayList<>();
6161

6262
public static final String JSON_PROPERTY_TAGS = "tags";
6363

64-
private List<Tag> tags = null;
64+
protected List<Tag> tags = null;
6565

6666
public enum StatusEnum {
6767

@@ -100,7 +100,7 @@ public static StatusEnum fromValue(String value) {
100100
* pet status in the store
101101
*/
102102

103-
private StatusEnum status;
103+
protected StatusEnum status;
104104

105105

106106
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/Tag.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public class Tag {
3636

3737
public static final String JSON_PROPERTY_ID = "id";
3838

39-
private Long id;
39+
protected Long id;
4040

4141
public static final String JSON_PROPERTY_NAME = "name";
4242

43-
private String name;
43+
protected String name;
4444

4545

4646
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-mutiny/src/main/java/org/openapitools/client/model/User.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,38 @@ public class User {
4242

4343
public static final String JSON_PROPERTY_ID = "id";
4444

45-
private Long id;
45+
protected Long id;
4646

4747
public static final String JSON_PROPERTY_USERNAME = "username";
4848

49-
private String username;
49+
protected String username;
5050

5151
public static final String JSON_PROPERTY_FIRST_NAME = "firstName";
5252

53-
private String firstName;
53+
protected String firstName;
5454

5555
public static final String JSON_PROPERTY_LAST_NAME = "lastName";
5656

57-
private String lastName;
57+
protected String lastName;
5858

5959
public static final String JSON_PROPERTY_EMAIL = "email";
6060

61-
private String email;
61+
protected String email;
6262

6363
public static final String JSON_PROPERTY_PASSWORD = "password";
6464

65-
private String password;
65+
protected String password;
6666

6767
public static final String JSON_PROPERTY_PHONE = "phone";
6868

69-
private String phone;
69+
protected String phone;
7070

7171
public static final String JSON_PROPERTY_USER_STATUS = "userStatus";
7272
/**
7373
* User Status
7474
*/
7575

76-
private Integer userStatus;
76+
protected Integer userStatus;
7777

7878

7979
/**

samples/client/petstore/java/microprofile-rest-client-3.0-jackson-with-xml/src/main/java/org/openapitools/client/model/Category.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public class Category {
4747

4848
public static final String JSON_PROPERTY_ID = "id";
4949
@XmlElement(name = "id")
50-
private Long id;
50+
protected Long id;
5151

5252
public static final String JSON_PROPERTY_NAME = "name";
5353
@XmlElement(name = "name")
54-
private String name;
54+
protected String name;
5555

5656

5757
/**

0 commit comments

Comments
 (0)