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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5006,4 +5006,41 @@ public void testSingleRequestParameter_hasSingleParamTrue() {
// When & Then
assertThat(codegenOperation.getHasSingleParam()).isTrue();
}

@Test
public void testRefSiblingMergingOnAllAliasForms() {
// 1) load & flatten
OpenAPI openAPI = TestUtils.parseFlattenSpec(
"src/test/resources/3_1/issue_20304.yaml"
);
new InlineModelResolver().flatten(openAPI);

// 2) prepare codegen
DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);

// 3) grab all five wrapper props
Map<String, Schema> props = openAPI.getComponents()
.getSchemas()
.get("ModelWithTitledProperties")
.getProperties();

// 4) for each case: [propertyName, expectedTitle, expectedDescription]
String[][] cases = {
{"simpleProperty", "Simple-Property-Title", "Simple-Property-Description"},
{"allOfRefProperty", "All-Of-Ref-Property-Title", "All-Of-Ref-Property-Description"},
{"arrayRefProperty", "Array-Ref-Property-Title", "Array-Ref-Property-Description"},
{"mapRefProperty", "Map-Ref-Property-Title", "Map-Ref-Property-Description"},
{"objectRefProperty", "Object-Ref-Property-Title", "Object-Ref-Property-Description"}
};

for (String[] c : cases) {
// required flag is irrelevant for merging siblings
CodegenProperty cp = codegen.fromProperty(c[0], props.get(c[0]), true);

// assert that our override‐siblings came through
assertEquals(c[1], cp.getTitle(), c[0] + " → title");
assertEquals(c[2], cp.getDescription(), c[0] + " → description");
}
}
}
59 changes: 59 additions & 0 deletions modules/openapi-generator/src/test/resources/3_1/issue_20304.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# src/test/resources/3_1/issue_20304_siblings.yaml
openapi: 3.1.0
info:
title: Test siblings
version: 1.0.0
components:
schemas:
ModelWithTitledProperties:
type: object
properties:
# 1) simple $ref
simpleProperty:
$ref: '#/components/schemas/Inner'
title: Simple-Property-Title
description: Simple-Property-Description

# 2) allOf wrapping a $ref
allOfRefProperty:
allOf:
- $ref: '#/components/schemas/Inner'
title: All-Of-Ref-Property-Title
description: All-Of-Ref-Property-Description

# 3) array alias
arrayRefProperty:
$ref: '#/components/schemas/ArrayOfInner'
title: Array-Ref-Property-Title
description: Array-Ref-Property-Description

# 4) map alias
mapRefProperty:
$ref: '#/components/schemas/MapOfInner'
title: Map-Ref-Property-Title
description: Map-Ref-Property-Description

# 5) object-model alias
objectRefProperty:
$ref: '#/components/schemas/ObjectInner'
title: Object-Ref-Property-Title
description: Object-Ref-Property-Description

Inner:
type: string

ArrayOfInner:
type: array
items:
$ref: '#/components/schemas/Inner'

MapOfInner:
type: object
additionalProperties:
$ref: '#/components/schemas/Inner'

ObjectInner:
type: object
properties:
foo:
type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"

[dependencies]
serde = { version = "^1.0", features = ["derive"] }
serde_with = { version = "^3.8", default-features = false, features = ["base64", "std", "macros"] }
serde_json = "^1.0"
serde_repr = "^0.1"
url = "^2.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Parent {
#[serde(rename = "child", skip_serializing_if = "Option::is_none")]
pub child: Option<std::collections::HashMap<String, serde_json::Value>>,
#[serde(rename = "child", default, with = "::serde_with::rust::double_option", skip_serializing_if = "Option::is_none")]
pub child: Option<Option<std::collections::HashMap<String, serde_json::Value>>>,
}

impl Parent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,8 @@ components:
ref_array_prefix_items:
description: |
An item that was added to the queue.
items: {}
items:
type: object
maxItems: 5
minItems: 3
type: array
Expand Down
4 changes: 0 additions & 4 deletions samples/client/petstore/java/okhttp-gson/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,6 @@ components:
Address:
additionalProperties:
type: integer
default: []
type: object
Animal:
discriminator:
Expand Down Expand Up @@ -2258,7 +2257,6 @@ components:
StringBooleanMap:
additionalProperties:
type: boolean
default: []
type: object
FileSchemaTestClass:
example:
Expand Down Expand Up @@ -2597,7 +2595,6 @@ components:
- $ref: "#/components/schemas/GrandparentAnimal"
type: object
ArrayOfEnums:
default: []
items:
$ref: "#/components/schemas/OuterEnum"
type: array
Expand Down Expand Up @@ -2744,7 +2741,6 @@ components:
- type: boolean
description: Values of scalar type using anyOf
Array:
default: []
description: Values of array type
items:
$ref: "#/components/schemas/Scalar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ components:
requiredObjectHeader:
type: boolean
optionalObjectHeader:
format: int32
type: integer
required:
- requiredObjectHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ components:
requiredObjectHeader:
type: boolean
optionalObjectHeader:
format: int32
type: integer
required:
- requiredObjectHeader
Expand Down
Loading