Closed pakrym closed 4 years ago
The autorest --csharp --v3
part is still being worked on. But there is a way to use V3 generator in your repo.
You can use the V3 generator outside of azure-sdk-for-net by referencing the
<PackageReference Include="AutoRest.CSharp.V3" Version="1.0.0-alpha.20201013.3" />
from https://azuresdkartifacts.blob.core.windows.net/azure-sdk-tools/index.json feed.
Adding autorest.md file that poins to you swagger (remove space in between ```)
Run `dotnet build /t:GenerateCode` in src directory to re-generate.
`` ` yaml
input-file:
- https://github.com/Azure/azure-rest-api-specs/blob/615259b6d33d3029de2d6e403ffe0c12776da1d4/specification/keyvault/data-plane/Microsoft.KeyVault/stable/7.1/storage.json
`` `
And running dotnet build /t:GenerateCode
Thanks for this, I will give it a go next week! Cheers!
Hi @pakrym , I did have a go with new C# generator (Version="1.0.0-alpha.20201021.2"). I tested with following autorest.md YAML:
input-file:
- https://github.com/OpenBankingUK/client-registration-api-specs/blob/e211e5eef8b9dfd907760b42723c31632a226e1d/dist/client-registration-openapi.yaml
output-folder: .
csharp:
namespace: FinnovationLabs.OpenBanking.Library.Connector.ObModels.ClientRegistration.V3p2
use-datetimeoffset: true
The generator has a problem with the csharp
YAML options in autorest.md as shown above; they create this error:
EXEC : error : Cannot resolve pipeline stage 'openapi-document/identity'. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\AutoRest.CSharp.V3.targets(33,5): error MSB3073: The command "npx autorest@https://github.com/Azure/autorest/releases/download/autorest-3.0.6250/autorest-3.0.6250.tgz --skip-upgrade-check --version=3.0.6324 C:\Repos\Tmp\AutoRestTest\src/autorest.md --use=C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../tools/netcoreapp3.0/any/ --output-folder=C:\Repos\Tmp\AutoRestTest\src --namespace=AutoRestTest --shared-source-folders="C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../content/Azure.Core.Shared/;C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../content/Generator.Shared/"" exited with code 1. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
But even removing these creates a failure with above document:
EXEC : warning (PreCheck/SchemaMissingType): The schema 'components┬╖1sjd0h8┬╖responses┬╖obclientregistration1┬╖content┬╖application-json┬╖schema' with an undefined type and 'allOf'/'anyOf'/'oneOf' is a bit ambigious. This has been auto-corrected to 'type:object' [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (PreCheck/EmptyParentSchemaWarning): Schema 'components┬╖1sjd0h8┬╖responses┬╖obclientregistration1┬╖content┬╖application-json┬╖schema' has an allOf list with an empty object schema as a parent, removing it. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (PreCheck/CheckDuplicateSchemas): Checking for duplicate schemas, this could take a (long) while. Run with --verbose for more detail. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (Interpretations): Generating 'operationId' for 'post' operation on path '/register' [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (Interpretations): Generating 'operationId' for 'get' operation on path '/register/{ClientId}' [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (Interpretations): Generating 'operationId' for 'put' operation on path '/register/{ClientId}' [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (Interpretations): Generating 'operationId' for 'delete' operation on path '/register/{ClientId}' [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : warning (Modeler/MissingType): The schema 'components┬╖fj9vuw┬╖responses┬╖obclientregistration1┬╖content┬╖application-json┬╖schema┬╖allof┬╖1' has no type or format information whatsoever. Location: [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : error (): Duplicate Operation 'Optional' detected. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : error (): Duplicate object schemas with 'RegistrationError' name detected. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
FATAL : error : 2 errors occured -- cannot continue. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
EXEC : error : Plugin checker reported failure. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\AutoRest.CSharp.V3.targets(33,5): error MSB3073: The command "npx autorest@https://github.com/Azure/autorest/releases/download/autorest-3.0.6250/autorest-3.0.6250.tgz --skip-upgrade-check --version=3.0.6324 C:\Repos\Tmp\AutoRestTest\src/autorest.md --use=C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../tools/netcoreapp3.0/any/ --output-folder=C:\Repos\Tmp\AutoRestTest\src --namespace=AutoRestTest --shared-source-folders="C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../content/Azure.Core.Shared/;C:\Users\mark\.nuget\packages\autorest.csharp.v3\1.0.0-alpha.20201021.2\build\../content/Generator.Shared/"" exited with code 1. [C:\Repos\Tmp\AutoRestTest\src\AutoRestTest.csproj]
8 Warning(s)
5 Error(s)
Do you have any tips? 😀
You seem to have some duplicated schemas defined, are you sure every one of those are defined only once?
Thanks for quick response.
This is actually a file from a public standard (not my file) but seems to cause a problem because of multiple optional endpoints (three of them) and a claimed duplicate RegistrationError
schema definition (seems not to be correct as can be verified by quick text search here ).
Just to add, the Swagger 2.0 version of the same file works with the C# v2 generator so I think the file is okay. Also it previews fine in VS Code using the Swagger Viewer extension.
So maybe there are a few issues to be ironed out with the new generator unless I've made a mistake somewhere? Also can you make any comment about support for csharp
options in autorest.md?
The V2 generator pipeline wasn't as strict as V3 and some swagger that worked before would contain errors. Feel free to file an issue in https://github.com/Azure/autorest/ repo that contains the duplicate checking logic.
I don't have an answer as to why having the csharp
section makes generation fail.
Okay, thanks very much for your help, appreciated. I've raised this issue: https://github.com/Azure/autorest/issues/3621.
Hi @pakrym ,
I see this has been closed; is there any indication when
autorest --csharp --v3
will use the V3 C# generator?Waiting very patiently and excitedly for this. 😀
BR, Mark