@@ -77,10 +77,13 @@ let private anyOfSingleRefSchema =
7777}"""
7878
7979[<Fact>]
80- let ``allOf single $ref resolves to the referenced type without creating a new object type`` () =
80+ let ``allOf single $ref resolves to exactly one referenced type`` () =
8181 let types = compileV3Schema allOfSingleRefSchema false
82- // PetRef collapses into Pet via ReleaseNameReservation; the referenced type is present.
83- types |> List.exists( fun t -> t.Name = " Pet" ) |> shouldEqual true
82+ // PetRef collapses into Pet via ReleaseNameReservation; the referenced type is registered once.
83+ types
84+ |> List.filter( fun t -> t.Name = " Pet" )
85+ |> List.length
86+ |> shouldEqual 1
8487
8588[<Fact>]
8689let ``allOf single $ref does not produce a separate wrapper type`` () =
@@ -89,126 +92,32 @@ let ``allOf single $ref does not produce a separate wrapper type``() =
8992 types |> List.exists( fun t -> t.Name = " PetRef" ) |> shouldEqual false
9093
9194[<Fact>]
92- let ``oneOf single $ref resolves to the referenced type`` () =
93- let types = compileV3Schema oneOfSingleRefSchema false
94- types |> List.exists( fun t -> t.Name = " Dog" ) |> shouldEqual true
95-
96- [<Fact>]
97- let ``oneOf single $ref does not produce a separate wrapper type`` () =
95+ let ``oneOf single $ref resolves to exactly one referenced type`` () =
9896 let types = compileV3Schema oneOfSingleRefSchema false
99- types |> List.exists( fun t -> t.Name = " DogRef" ) |> shouldEqual false
100-
101- [<Fact>]
102- let ``anyOf single $ref resolves to the referenced type`` () =
103- let types = compileV3Schema anyOfSingleRefSchema false
104- types |> List.exists( fun t -> t.Name = " Cat" ) |> shouldEqual true
105-
106- [<Fact>]
107- let ``anyOf single $ref does not produce a separate wrapper type`` () =
108- let types = compileV3Schema anyOfSingleRefSchema false
109- types |> List.exists( fun t -> t.Name = " CatRef" ) |> shouldEqual false
110-
111- // ── Named component alias to another named object component (issue #477) ─────
112- //
113- // When a named component schema is a single-ref oneOf/anyOf/allOf wrapper that
114- // resolves to another named object component, the resolved ProvidedTypeDefinition
115- // must appear in the type list exactly once. Before the fix, registerInNsAndInDef
116- // would register the same PTD a second time (once for the target, once for the
117- // alias), causing "duplicate entry '<name>' in type index table" during assembly emit.
118-
119- let private namedAliasOneOfSchema =
120- """ {
121- "openapi": "3.0.0",
122- "info": { "title": "Test", "version": "1.0.0" },
123- "paths": {},
124- "components": {
125- "schemas": {
126- "Parent": {
127- "oneOf": [ { "$ref": "#/components/schemas/Parent_Child" } ]
128- },
129- "Parent_Child": {
130- "type": "object",
131- "required": ["childValue"],
132- "properties": {
133- "childValue": { "type": "string" }
134- }
135- }
136- }
137- }
138- }"""
139-
140- let private namedAliasAllOfSchema =
141- """ {
142- "openapi": "3.0.0",
143- "info": { "title": "Test", "version": "1.0.0" },
144- "paths": {},
145- "components": {
146- "schemas": {
147- "MyAlias": {
148- "allOf": [ { "$ref": "#/components/schemas/MyObject" } ]
149- },
150- "MyObject": {
151- "type": "object",
152- "properties": { "value": { "type": "integer" } }
153- }
154- }
155- }
156- }"""
157-
158- let private namedAliasAnyOfSchema =
159- """ {
160- "openapi": "3.0.0",
161- "info": { "title": "Test", "version": "1.0.0" },
162- "paths": {},
163- "components": {
164- "schemas": {
165- "AliasAnyOf": {
166- "anyOf": [ { "$ref": "#/components/schemas/TargetObject" } ]
167- },
168- "TargetObject": {
169- "type": "object",
170- "properties": { "name": { "type": "string" } }
171- }
172- }
173- }
174- }"""
175-
176- [<Fact>]
177- let ``oneOf named alias to object component does not produce duplicate provided type`` () =
178- // Regression test for issue #477: Parent aliases Parent_Child via oneOf.
179- // The resolved ProvidedTypeDefinition must appear exactly once.
180- let types = compileV3Schema namedAliasOneOfSchema false
18197
18298 types
183- |> List.filter( fun t -> t.Name = " Parent_Child " )
99+ |> List.filter( fun t -> t.Name = " Dog " )
184100 |> List.length
185101 |> shouldEqual 1
186102
187103[<Fact>]
188- let ``oneOf named alias to object component exposes the target type`` () =
189- let types = compileV3Schema namedAliasOneOfSchema false
190-
191- types
192- |> List.exists( fun t -> t.Name = " Parent_Child" )
193- |> shouldEqual true
104+ let ``oneOf single $ref does not produce a separate wrapper type`` () =
105+ let types = compileV3Schema oneOfSingleRefSchema false
106+ types |> List.exists( fun t -> t.Name = " DogRef" ) |> shouldEqual false
194107
195108[<Fact>]
196- let ``allOf named alias to object component does not produce duplicate provided type`` () =
197- let types = compileV3Schema namedAliasAllOfSchema false
109+ let ``anyOf single $ ref resolves to exactly one referenced type``() =
110+ let types = compileV3Schema anyOfSingleRefSchema false
198111
199112 types
200- |> List.filter( fun t -> t.Name = " MyObject " )
113+ |> List.filter( fun t -> t.Name = " Cat " )
201114 |> List.length
202115 |> shouldEqual 1
203116
204117[<Fact>]
205- let ``anyOf named alias to object component does not produce duplicate provided type`` () =
206- let types = compileV3Schema namedAliasAnyOfSchema false
207-
208- types
209- |> List.filter( fun t -> t.Name = " TargetObject" )
210- |> List.length
211- |> shouldEqual 1
118+ let ``anyOf single $ref does not produce a separate wrapper type`` () =
119+ let types = compileV3Schema anyOfSingleRefSchema false
120+ types |> List.exists( fun t -> t.Name = " CatRef" ) |> shouldEqual false
212121
213122// ── Required vs optional properties ──────────────────────────────────────────
214123
0 commit comments