@@ -6687,6 +6687,145 @@ public async Task IndexerTypeIsAccurateAndBackwardCompatibleIndexersAreAddedAsyn
6687
6687
var actorsItemRequestBuilder = actorsItemRequestBuilderNamespace . FindChildByName < CodeClass > ( "actorItemRequestBuilder" ) ;
6688
6688
Assert . Equal ( actorsCollectionIndexer . ReturnType . Name , actorsItemRequestBuilder . Name ) ;
6689
6689
}
6690
+
6691
+ [ Fact ]
6692
+ public async Task IndexerSupportsUnionOfPrimitiveTypesForPathParametersAsync ( )
6693
+ {
6694
+ var tempFilePath = Path . GetTempFileName ( ) ;
6695
+ await using var fs = await GetDocumentStreamAsync ( @"openapi: 3.0.0
6696
+ info:
6697
+ title: Test API with Union Path Parameters
6698
+ version: 1.0.0
6699
+ servers:
6700
+ - url: https://api.example.com/v1
6701
+ paths:
6702
+ /keys/{ssh_key_identifier}:
6703
+ get:
6704
+ parameters:
6705
+ - name: ssh_key_identifier
6706
+ in: path
6707
+ required: true
6708
+ description: Either the ID or the fingerprint of an existing SSH key.
6709
+ schema:
6710
+ anyOf:
6711
+ - type: string
6712
+ - type: integer
6713
+ example: 512189
6714
+ responses:
6715
+ 200:
6716
+ description: Success!
6717
+ content:
6718
+ application/json:
6719
+ schema:
6720
+ $ref: '#/components/schemas/SSHKey'
6721
+ components:
6722
+ schemas:
6723
+ SSHKey:
6724
+ type: object
6725
+ properties:
6726
+ id:
6727
+ type: integer
6728
+ fingerprint:
6729
+ type: string
6730
+ key:
6731
+ type: string" ) ;
6732
+ var mockLogger = new Mock < ILogger < KiotaBuilder > > ( ) ;
6733
+ var builder = new KiotaBuilder ( mockLogger . Object , new GenerationConfiguration { ClientClassName = "TestClient" , OpenAPIFilePath = tempFilePath } , _httpClient ) ;
6734
+ var document = await builder . CreateOpenApiDocumentAsync ( fs ) ;
6735
+ var node = builder . CreateUriSpace ( document ! ) ;
6736
+ var codeModel = builder . CreateSourceModel ( node ) ;
6737
+
6738
+ var keysCollectionRequestBuilderNamespace = codeModel . FindNamespaceByName ( "ApiSdk.keys" ) ;
6739
+ Assert . NotNull ( keysCollectionRequestBuilderNamespace ) ;
6740
+ var keysCollectionRequestBuilder = keysCollectionRequestBuilderNamespace . FindChildByName < CodeClass > ( "keysRequestBuilder" ) ;
6741
+ var keysCollectionIndexer = keysCollectionRequestBuilder . Indexer ;
6742
+ Assert . NotNull ( keysCollectionIndexer ) ;
6743
+
6744
+ // Check that the indexer parameter type is a union type containing both string and integer
6745
+ var parameterType = keysCollectionIndexer . IndexParameter . Type ;
6746
+ Assert . IsType < CodeUnionType > ( parameterType ) ;
6747
+ var unionType = ( CodeUnionType ) keysCollectionIndexer . IndexParameter . Type ;
6748
+ Assert . Equal ( 2 , unionType . Types . Count ( ) ) ;
6749
+
6750
+ // Verify both types are present in the union
6751
+ Assert . Contains ( unionType . Types , t => t . Name . Equals ( "string" , StringComparison . OrdinalIgnoreCase ) ) ;
6752
+ Assert . Contains ( unionType . Types , t => t . Name . Equals ( "integer" , StringComparison . OrdinalIgnoreCase ) ) ;
6753
+
6754
+ // Verify description
6755
+ Assert . Equal ( "Either the ID or the fingerprint of an existing SSH key." , keysCollectionIndexer . IndexParameter . Documentation . DescriptionTemplate ) ;
6756
+ Assert . False ( keysCollectionIndexer . IndexParameter . Type . IsNullable ) ;
6757
+ Assert . False ( keysCollectionIndexer . Deprecation . IsDeprecated ) ;
6758
+ }
6759
+
6760
+ [ Fact ]
6761
+ public async Task IndexerSupportsUnionOfPrimitiveTypesForPathParametersWithOneOfAsync ( )
6762
+ {
6763
+ var tempFilePath = Path . GetTempFileName ( ) ;
6764
+ await using var fs = await GetDocumentStreamAsync ( @"openapi: 3.0.0
6765
+ info:
6766
+ title: Test API with OneOf Path Parameters
6767
+ version: 1.0.0
6768
+ servers:
6769
+ - url: https://api.example.com/v1
6770
+ paths:
6771
+ /keys/{ssh_key_identifier}:
6772
+ get:
6773
+ parameters:
6774
+ - name: ssh_key_identifier
6775
+ in: path
6776
+ required: true
6777
+ description: Either the ID or the fingerprint of an existing SSH key.
6778
+ schema:
6779
+ oneOf:
6780
+ - type: string
6781
+ - type: integer
6782
+ example: 512189
6783
+ responses:
6784
+ 200:
6785
+ description: Success!
6786
+ content:
6787
+ application/json:
6788
+ schema:
6789
+ $ref: '#/components/schemas/SSHKey'
6790
+ components:
6791
+ schemas:
6792
+ SSHKey:
6793
+ type: object
6794
+ properties:
6795
+ id:
6796
+ type: integer
6797
+ fingerprint:
6798
+ type: string
6799
+ key:
6800
+ type: string" ) ;
6801
+ var mockLogger = new Mock < ILogger < KiotaBuilder > > ( ) ;
6802
+ var builder = new KiotaBuilder ( mockLogger . Object , new GenerationConfiguration { ClientClassName = "TestClient" , OpenAPIFilePath = tempFilePath } , _httpClient ) ;
6803
+ var document = await builder . CreateOpenApiDocumentAsync ( fs ) ;
6804
+ var node = builder . CreateUriSpace ( document ! ) ;
6805
+ var codeModel = builder . CreateSourceModel ( node ) ;
6806
+
6807
+ var keysCollectionRequestBuilderNamespace = codeModel . FindNamespaceByName ( "ApiSdk.keys" ) ;
6808
+ Assert . NotNull ( keysCollectionRequestBuilderNamespace ) ;
6809
+ var keysCollectionRequestBuilder = keysCollectionRequestBuilderNamespace . FindChildByName < CodeClass > ( "keysRequestBuilder" ) ;
6810
+ var keysCollectionIndexer = keysCollectionRequestBuilder . Indexer ;
6811
+ Assert . NotNull ( keysCollectionIndexer ) ;
6812
+
6813
+ // Check that the indexer parameter type is a union type containing both string and integer
6814
+ var parameterType = keysCollectionIndexer . IndexParameter . Type ;
6815
+ Assert . IsType < CodeUnionType > ( parameterType ) ;
6816
+ var unionType = ( CodeUnionType ) keysCollectionIndexer . IndexParameter . Type ;
6817
+ Assert . Equal ( 2 , unionType . Types . Count ( ) ) ;
6818
+
6819
+ // Verify both types are present in the union
6820
+ Assert . Contains ( unionType . Types , t => t . Name . Equals ( "string" , StringComparison . OrdinalIgnoreCase ) ) ;
6821
+ Assert . Contains ( unionType . Types , t => t . Name . Equals ( "integer" , StringComparison . OrdinalIgnoreCase ) ) ;
6822
+
6823
+ // Verify description
6824
+ Assert . Equal ( "Either the ID or the fingerprint of an existing SSH key." , keysCollectionIndexer . IndexParameter . Documentation . DescriptionTemplate ) ;
6825
+ Assert . False ( keysCollectionIndexer . IndexParameter . Type . IsNullable ) ;
6826
+ Assert . False ( keysCollectionIndexer . Deprecation . IsDeprecated ) ;
6827
+ }
6828
+
6690
6829
[ Fact ]
6691
6830
public async Task MapsBooleanEnumToBooleanTypeAsync ( )
6692
6831
{
0 commit comments