Closed kevinoid closed 3 years ago
Originally reported for OpenAPI 2.0 in #2564, fixed in #2571.
Hi, seems that you are running autores without parameter --v3
. OpenApi v3 should be only supported in autores v3. Anyway if you use parameter --v3
you will run into the following issue #3497
You also need to use an AutoRest extension that works with the v3 pipeline, @microsoft.azure/autorest.csharp@2.3.82
does not support it. Try adding this parameter --use:@autorest/csharp-v3@3.0.0-dev.20200512.1
. Note that the new v3-supporting C# generator is under development and not fully released yet.
Try adding this parameter
--use:@autorest/csharp-v3@3.0.0-dev.20200512.1
.
Thanks @daviwil! Running autorest --use:@autorest/csharp-v3@3.0.0-dev.20200512.1 --input-file=openapi.yaml
produces:
AutoRest code generation utility [cli version: 3.0.6187; node: v10.20.1, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Loading AutoRest core '/home/kevin/.autorest/@autorest_core@3.0.6246/node_modules/@autorest/core/dist' (3.0.6246)
Error: Unable to resolve package '@autorest/csharp-v3@3.0.0-dev.20200511.1'.
Presumably because @autorest/csharp-v3
isn't hosted on npmjs.com. autorest --use:@autorest/csharp-v3@https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200512.9/autorest-csharp-v3-3.0.0-dev.20200512.9.tgz --input-file=openapi.yaml
produces:
AutoRest code generation utility [cli version: 3.0.6187; node: v10.20.1, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Loading AutoRest core '/home/kevin/.autorest/@autorest_core@3.0.6246/node_modules/@autorest/core/dist' (3.0.6246)
Loading AutoRest extension '@autorest/csharp-v3' (@autorest/csharp-v3@https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200512.9/autorest-csharp-v3-3.0.0-dev.20200512.9.tgz->3.0.0-dev.20200512.9)
Loading AutoRest extension '@autorest/modelerfour' (4.13.351->4.13.351)
FATAL: System.UriFormatException: Invalid URI: The format of the URI could not be determined.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at AutoRest.CSharp.V3.AutoRest.Plugins.CSharpGen.Execute(IPluginCommunication autoRest) in D:\a\1\s\src\AutoRest.CSharp.V3\AutoRest\Plugins\CSharpGen.cs:line 114
at AutoRest.CSharp.V3.AutoRest.Plugins.PluginProcessor.Start(IPluginCommunication autoRest) in D:\a\1\s\src\AutoRest.CSharp.V3\AutoRest\Plugins\PluginProcessor.cs:line 36
Error: Plugin csharpgen reported failure.
Adding --v3 --csharp
changes the error to:
AutoRest code generation utility [cli version: 3.0.6187; node: v10.20.1, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
Loading AutoRest core '/home/kevin/.autorest/@autorest_core@3.0.6246/node_modules/@autorest/core/dist' (3.0.6246)
Loading AutoRest extension '@autorest/csharp-v3' (@autorest/csharp-v3@https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200512.9/autorest-csharp-v3-3.0.0-dev.20200512.9.tgz->3.0.0-dev.20200512.9)
Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.84)
Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)
Loading AutoRest extension '@autorest/modelerfour' (4.13.351->4.13.351)
Error: Cannot resolve pipeline stage 'openapi-document/identity'.
Could you give me a few more hints about how to generate C# with v3?
Feel free to ignore my previous comment. I was able to successfully generate code using:
mkdir -p assets && autorest --use:@autorest/csharp-v3@https://github.com/Azure/autorest.csharp/releases/download/3.0.0-dev.20200512.9/autorest-csharp-v3-3.0.0-dev.20200512.9.tgz --input-file=openapi.yaml --output-folder="file://$PWD/output" --namespace=MyNamespace --shared-source-folder="file://$PWD/assets"
I've been informed that the new C# generator probably won't work for general OpenAPI 3 spec generation at this point. The AutoRest team is focused primarily on getting AutoRest v3 generators working for Azure SDKs at this point before making them more broadly available.
Interesting that it worked for you though!
Good to know. Thanks again @daviwil!
@daviwil Running the risk of being too picky here, but is the following part of the readme description still accurate; seems like this is more of an AzureSDK generator rather than a general purpose OpenAPI (now v3) generator?
The AutoRest tool generates client libraries for accessing RESTful web services. Input to AutoRest is a spec that describes the REST API using the OpenAPI Specification format.
Autorest fails to generate code for an OpenAPI 3.0 document with a schema that uses a boolean value for
additionalProperties
. For example:Running
autorest --csharp --input-file=openapi.yaml
withautorest@3.0.6187
produces:Boolean values for
additionalProperties
work correctly in OpenAPI 2.0 documents.Thanks, Kevin
P.S. Note that the explicit mention of boolean values was removed from
additionalProperties
in JSON Schema Core draft-handrews-json-schema-02 (referenced by Schema Object in the current OpenAPI 3.1 draft), but it is still supported sincetrue
is an alias for{}
andfalse
for{"not":{}}
, as explained by Henry Andrews on the json-schema mailing list.