-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not generated C# client from AAS Repository OpenAPI document #285
Comments
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 |
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: This swagger definition was used: Submodel Repository Service Could you provide a working client generation example for this Swagger definition ? |
@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. |
As of version 2 milestone 3 of BaSyx, I can no longer use Kiota to generate an API from their AAS Environment application. I opened an issue here, and they referred me back to the IDTA specs. Feeding https://api.swaggerhub.com/apis/Plattform_i40/AssetAdministrationShell-API/V1.0RC03 to NSwag Studio give me this error:
I give up on NSwag again and try Kiota with this command:
It complains about external references:
So I follow the recommendation and use their Hidi tool to combine the specs:
That command spits out errors:
Part1-MetaModel-Schemas and Part2-API-Schemas do not contain "paths". Is that intentional, and is it valid OpenAPI? On this website I'm reading "The OpenAPI document MUST contain at least one paths field". |
Hi @sebbader-sap sorry for the ping. I wonder if you've seen my question above? |
Hi @arteeh, honestly, I saw it some time ago but simply hadn't any time to dig into it. However, we just noticed two nasty bugs in the V3.0.2_xyz versions. Can you try again with the (not yet officially released but already available) V3.0.3_xyz files? |
I think your bugfix did not affect my problem. Some more testing with the latest yaml's in the main branch: NSwag Studio stumbles over escape sequences in 'pattern' (line 182) in part 1 (not sure why it says JSON, the app says I can input YAML which I did. Maybe it internally converts to JSON first):
In Kiota I still get the paths error I mentioned:
Output:
Output:
They say 'generation completed successfully' but the output folder just has an empty useless client in it. Jetbrains Rider also has a code generator feature, tried that one on part 1 and it also gets stuck on paths:
When I manually run the underlying command with --skip-validate-spec I actually get promising code (only had to make a few manual changes to get it to build). It does choke when I GET an AAS from my BaSyx server due to a "type": null in a submodel reference where I think it should say ExternalReference or ModelReference. AasCore C# library errors on this as well, so I think that's a BaSyx problem, not an IDTA problem. |
@juileetikekar and @aorzelskiGH can you help here? |
I could imagine that the code generator has a problem as sometimes two or more regex patterns are valid for one string field and maybe the generator only expects zero or one... |
I guess it transforms the YAML first into JSON and then proceeds. |
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:
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, IList
1 allParameters, CodeGeneratorSettingsBase settings, IClientGenerator generator, TypeResolverBase typeResolver) in //src/NSwag.CodeGeneration/Models/ParameterModelBase.cs:line 52at 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.SelectListIterator
2.Fill(ReadOnlySpan1 source, Span
1 destination, Func2 func) at System.Linq.Enumerable.SelectListIterator
2.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.ClientGeneratorBase
3.GetOperations(OpenApiDocument document) in /_/src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 173 at NSwag.CodeGeneration.ClientGeneratorBase
3.GenerateAllClientTypes() in //src/NSwag.CodeGeneration/ClientGeneratorBase.cs:line 106at NSwag.CodeGeneration.ClientGeneratorBase
3.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
The text was updated successfully, but these errors were encountered: