@@ -17,77 +17,87 @@ let AllOfSchema = __SOURCE_DIRECTORY__ + "/Schemas/named-object-alias-allof.json
1717let NamespacedSchema =
1818 __ SOURCE_ DIRECTORY__ + " /Schemas/named-object-alias-namespaced.json"
1919
20+ [<Literal>]
21+ let MultipleAliasesSchema =
22+ __ SOURCE_ DIRECTORY__ + " /Schemas/named-object-alias-multiple.json"
23+
2024type OneOfApi = OpenApiClientProvider< OneOfSchema, SsrfProtection= false >
2125type AnyOfApi = OpenApiClientProvider< AnyOfSchema, SsrfProtection= false >
2226type AllOfApi = OpenApiClientProvider< AllOfSchema, SsrfProtection= false >
2327type NamespacedApi = OpenApiClientProvider< NamespacedSchema, SsrfProtection= false >
28+ type MultipleAliasesApi = OpenApiClientProvider< MultipleAliasesSchema, SsrfProtection= false >
2429
25- let private oneOfClient = OneOfApi.Client()
26- let private anyOfClient = AnyOfApi.Client()
27- let private allOfClient = AllOfApi.Client()
28- let private namespacedClient = NamespacedApi.Client()
29-
30- // These helpers are compile-time assertions that operation responses expose the child property.
31- let private getOneOfChildValue () =
32- task {
33- let! response = oneOfClient.GetParent()
34- return response.ChildValue
35- }
36-
37- let private getAnyOfChildValue () =
38- task {
39- let! response = anyOfClient.GetParent()
40- return response.ChildValue
41- }
42-
43- let private getAllOfChildValue () =
44- task {
45- let! response = allOfClient.GetParent()
46- return response.ChildValue
47- }
48-
49- let private getNamespacedValue () =
50- task {
51- let! response = namespacedClient.GetParent()
52- return response.Value
53- }
54-
55- let private getResponseType ( client : obj ) =
30+ let private getResponseType ( clientType : System.Type ) operationName =
5631 let methodInfo =
57- client.GetType () .GetMethods()
58- |> Array.filter( fun candidate -> candidate.Name = " GetParent " )
32+ clientType .GetMethods()
33+ |> Array.filter( fun candidate -> candidate.Name = operationName )
5934 |> Array.exactlyOne
6035
6136 methodInfo.ReturnType.GetGenericArguments() |> Array.exactlyOne
6237
38+ let private getGeneratedTypeNames ( generatedType : System.Type ) =
39+ generatedType.DeclaringType.GetNestedTypes()
40+ |> Array.map( fun nestedType -> nestedType.Name)
41+
6342[<Fact>]
6443let ``oneOf named component alias response resolves to child object type`` () =
65- getResponseType oneOfClient
44+ getResponseType typeof < OneOfApi.Client > " GetParent "
6645 |> shouldEqual typeof< OneOfApi.Parent_ Child>
6746
6847 let response = OneOfApi.Parent_ Child( " oneOf" )
6948 response.ChildValue |> shouldEqual " oneOf"
7049
50+ let generatedTypeNames = getGeneratedTypeNames typeof< OneOfApi.Parent_ Child>
51+ generatedTypeNames |> shouldNotContain " Parent"
52+
53+ generatedTypeNames
54+ |> Array.filter( fun typeName -> typeName = " Parent_Child" )
55+ |> Array.length
56+ |> shouldEqual 1
57+
7158[<Fact>]
7259let ``anyOf named component alias response resolves to child object type`` () =
73- getResponseType anyOfClient
60+ getResponseType typeof < AnyOfApi.Client > " GetParent "
7461 |> shouldEqual typeof< AnyOfApi.Parent_ Child>
7562
7663 let response = AnyOfApi.Parent_ Child( " anyOf" )
7764 response.ChildValue |> shouldEqual " anyOf"
7865
7966[<Fact>]
8067let ``allOf named component alias response resolves to child object type`` () =
81- getResponseType allOfClient
68+ getResponseType typeof < AllOfApi.Client > " GetParent "
8269 |> shouldEqual typeof< AllOfApi.Parent_ Child>
8370
8471 let response = AllOfApi.Parent_ Child( " allOf" )
8572 response.ChildValue |> shouldEqual " allOf"
8673
8774[<Fact>]
8875let ``namespaced aliases with equal leaf names register the child object only once`` () =
89- getResponseType namespacedClient
76+ getResponseType typeof < NamespacedApi.Client > " GetParent "
9077 |> shouldEqual typeof< NamespacedApi.B.Parent>
9178
9279 let response = NamespacedApi.B.Parent( " namespaced" )
9380 response.Value |> shouldEqual " namespaced"
81+
82+ [<Fact>]
83+ let ``multiple aliases and alias chains resolve to their object types`` () =
84+ getResponseType typeof< MultipleAliasesApi.Client> " GetParentA"
85+ |> shouldEqual typeof< MultipleAliasesApi.Child>
86+
87+ getResponseType typeof< MultipleAliasesApi.Client> " GetParentB"
88+ |> shouldEqual typeof< MultipleAliasesApi.Child>
89+
90+ getResponseType typeof< MultipleAliasesApi.Client> " GetAliasChain"
91+ |> shouldEqual typeof< MultipleAliasesApi.AliasC>
92+
93+ let child = MultipleAliasesApi.Child( " shared" )
94+ child.Value |> shouldEqual " shared"
95+
96+ let chained = MultipleAliasesApi.AliasC( " chained" )
97+ chained.ChainValue |> shouldEqual " chained"
98+
99+ let generatedTypeNames = getGeneratedTypeNames typeof< MultipleAliasesApi.Child>
100+ generatedTypeNames |> shouldNotContain " ParentA"
101+ generatedTypeNames |> shouldNotContain " ParentB"
102+ generatedTypeNames |> shouldNotContain " AliasA"
103+ generatedTypeNames |> shouldNotContain " AliasB"
0 commit comments