Skip to content
Merged
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 @@ -4307,6 +4307,13 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
if (original.getTitle() != null) {
property.setTitle(original.getTitle());
}
// the example was computed above against the inner (allOf/$ref) schema, which does
// not carry the example declared as a sibling of the allOf/$ref. Restore it here so
// that e.g. `allOf: [ $ref ]` with a sibling `example` keeps the declared example
// instead of falling back to the literal "null".
if (original.getExample() != null) {
property.example = toExampleValue(original);
}
}

// override defaultValue if it's not set and defaultToEmptyContainer is set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,22 @@ public void testTitleProperty() {
assertEquals("Ref-Property-Title", codegen.fromProperty("refProperty", (Schema) testProperties.get("refProperty")).title);
}

@Test
public void testAllOfSingleRefSiblingExample() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/property-title.yaml");
new InlineModelResolver().flatten(openAPI);
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);

final Map testProperties = Collections.unmodifiableMap(openAPI.getComponents().getSchemas().get("ModelWithTitledProperties").getProperties());

// a plain property keeps its example
assertEquals("Simple-Property-Example", codegen.fromProperty("simpleProperty", (Schema) testProperties.get("simpleProperty")).example);
// an `allOf: [ $ref ]` property must keep the example declared as a sibling of the allOf,
// instead of falling back to the literal "null" computed against the inner $ref schema
assertEquals("Ref-Property-Example", codegen.fromProperty("refProperty", (Schema) testProperties.get("refProperty")).example);
}

@Test
public void testDeprecatedRef() {
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/model-deprecated.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ components:
simpleProperty:
type: string
title: Simple-Property-Title
example: Simple-Property-Example
refProperty:
type: string
title: Ref-Property-Title
example: Ref-Property-Example
allOf:
- $ref: '#/components/schemas/RefObject'
type: object
Expand Down
Loading