admin-shell-io / aas-specs-api

Repository of the Asset Administration Shell Specification DTA-01002 API
https://industrialdigitaltwin.org/
Creative Commons Attribution 4.0 International
9 stars 4 forks source link

Could not generated C# client from AAS Repository OpenAPI document #285

Open huf1 opened 1 month ago

huf1 commented 1 month ago

What happens?

I'm trying to generate a C# client with NSwag from the provided AAS Repository document, but it fails with an error message. Steps to reproduce:

  1. https://app.swaggerhub.com/apis/Plattform_i40/AssetAdministrationShellRepositoryServiceSpecification/V3.0.1_SSP-001 -> Download API -> JSON Resolved
  2. Run command: dotnet-nswag.exe openapi2csclient /className:AaSRepositoryClient /namespace:AasRepositoryClient /GenerateExceptionClasses:false /input:"C:\temp\AasRepositorySpec.json" /output:"C:\temp\AasRepositoryClient.cs"

Error message: System.InvalidOperationException: The properties 'modelType' are defined multiple times.

StackTrace: System.InvalidOperationException: The properties 'modelType' are defined multiple times. at NJsonSchema.JsonSchema.get_ActualProperties() at NSwag.CodeGeneration.Models.ParameterModelBase..ctor(String parameterName, String variableName, String typeName, OpenApiParameter parameter, IList1 allParameters, CodeGeneratorSettingsBase settings, IClientGenerator generator, TypeResolverBase typeResolver) in //src/NSwag.CodeGeneration/Models/ParameterModelBase.cs:line 52 at NSwag.CodeGeneration.CSharp.Models.CSharpParameterModel..ctor(String parameterName, String variableName, String variableIdentifier, String typeName, OpenApiParameter parameter, IList`1 allParameters, CodeGeneratorSettingsBase settings, IClientGenerator generator, TypeResolverBase typeResolver) in //src/NSwag.CodeGeneration.CSharp/Models/CSharpParameterModel.cs:line 40 at NSwag.CodeGeneration.CSharp.Models.CSharpOperationModel.<>c__DisplayClass5_0.<.ctor>b_5(OpenApiParameter parameter) in //src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs:line 76 at System.Linq.Enumerable.SelectListIterator2.Fill(ReadOnlySpan1 source, Span1 destination, Func2 func) at System.Linq.Enumerable.SelectListIterator2.ToList() at NSwag.CodeGeneration.CSharp.Models.CSharpOperationModel..ctor(OpenApiOperation operation, CSharpGeneratorBaseSettings settings, CSharpGeneratorBase generator, CSharpTypeResolver resolver) in /_/src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs:line 74 at NSwag.CodeGeneration.CSharp.CSharpClientGenerator.CreateOperationModel(OpenApiOperation operation, ClientGeneratorBaseSettings settings) in /_/src/NSwag.CodeGeneration.CSharp/CSharpClientGenerator.cs:line 81 at NSwag.CodeGeneration.ClientGeneratorBase3.GetOperations(OpenApiDocument document) in //src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 173 at NSwag.CodeGeneration.ClientGeneratorBase`3.GenerateAllClientTypes() in //src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 106 at NSwag.CodeGeneration.ClientGeneratorBase3.GenerateFile(ClientGeneratorOutputType outputType) in /_/src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 73 at NSwag.Commands.CodeGeneration.OpenApiToCSharpClientCommand.RunAsync() in /_/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs:line 292 at NSwag.Commands.CodeGeneration.OpenApiToCSharpClientCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs:line 270 at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input) at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input) at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 65

Toolchain: NSwag - NSwag command line tool for .NET Core Net80, toolchain v14.0.7.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))

Why is this wrong?

Generating C# client should work with an OpenAPI supporting tool like NSwag.

How should it be fixed?

Client generation is essential for developing against this or even other specificated APIs

sebbader-sap commented 1 month ago

The provided files are 100% correct OpenAPI. I don't know NSwag but it looks like a problem on their side. Not all OpenAPI generators are able to deal with the expressiveness of the OpenAPI specification, might be the case here too.

However, you may want to have a look at this C# SDK: https://github.com/aas-core-works/aas-core3.0-csharp

mrumurm commented 2 weeks ago

We tried different generators(swagger codegen / openapi-generator / swagger hub download ) and it was not possible to generate a client without Errors / Problems.

We also tried to generate for different Languages like C#, GO, JAVA.

Also while trying to download the JAVA Client swaggerhub even didnt create the Package and showed this error: Bildschirmfoto 2024-06-12 um 10 05 54

This swagger definition was used: Submodel Repository Service

Could you provide a working client generation example for this Swagger definition ?

arteeh commented 2 weeks ago

@mrumurm Maybe try Kiota as the code generator. I haven't tested it much but it seems to work okay with the spec provided by BaSyx.

But I do agree that these openapi specs don't seem to be very generator-friendly.