Skip to content
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
Expand Up @@ -52,10 +52,10 @@ public class {{classname}} {{#parent}}extends {{{.}}}{{/parent}}{{#vendorExtensi
{{{.}}}
{{/vendorExtensions.x-field-extra-annotation}}
{{#isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
protected {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
{{/isContainer}}
{{^isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
protected {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
{{/isContainer}}
{{/vars}}
{{>additional_properties}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,31 @@ public void testGeneratedApiExceptionMapperDoesNotHaveProviderAnnotationWhenDisa
.assertTypeAnnotations()
.doesNotContainWithName("Provider");
}

@Test
public void testClientCanAccessFieldInParent() throws Exception {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
output.deleteOnExit();

OpenAPI openAPI = new OpenAPIParser()
.readLocation("src/test/resources/bugs/issue_23034.yaml", null, new ParseOptions()).getOpenAPI();

codegen.setOutputDir(output.getAbsolutePath());
codegen.additionalProperties().put(JavaClientCodegen.MICROPROFILE_GLOBAL_EXCEPTION_MAPPER, "false");

ClientOptInput input = new ClientOptInput()
.openAPI(openAPI)
.config(codegen);

List<File> files = new DefaultGenerator().opts(input).generate();

Map<String, File> filesMap = files.stream()
.collect(Collectors.toMap(File::getName, Function.identity()));

validateJavaSourceFiles(files);

JavaFileAssert.assertThat(filesMap.get("Parent.java"))
.fileContains("protected String parentField;");
}
}

47 changes: 47 additions & 0 deletions modules/openapi-generator/src/test/resources/bugs/issue_23034.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
openapi: 3.0.4
info:
title: Reproduce
version: 'v1'
components:
schemas:
Child:
required:
- childField1
type: object
allOf:
- $ref: "#/components/schemas/Parent"
properties:
childField1:
type: string

Parent:
required:
- classType
- parentField
type: object
properties:
parentField:
type: string
readOnly: true
classType:
description: Identifier of discriminator mapping class.
enum:
- Child
type: string
discriminator:
propertyName: classType
mapping:
Child: "#/components/schemas/Child"
paths:
'/v1/reproduce':
get:
responses:
'200':
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Child'
description: 'reproduce'