Autorest: OAS3.0: imodeler1 failure for boolean additionalProperties

Created on 6 Mar 2020  路  8Comments  路  Source: Azure/autorest

Autorest fails to generate code for an OpenAPI 3.0 document with a schema that uses a boolean value for additionalProperties. For example:

openapi: '3.0.3'
info:
  title: OpenApi 3 example with boolean additionalProperties
  version: '1.0.0'
components:
  schemas:
    ExampleObject:
      description: Schema which forbids additional properties
      type: object
      properties:
        prop1:
          type: string
      additionalProperties: false
paths:
  /example:
    get:
      operationId: getExample
      responses:
        default:
          description: Get example object
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ExampleObject'

Running autorest --csharp --input-file=openapi.yaml with [email protected] produces:

AutoRest code generation utility [cli version: 3.0.6187; node: v10.16.3, max-memory: 8192 gb]
(C) 2018 Microsoft Corporation.
https://aka.ms/autorest
   Loading AutoRest core      '/home/kevin/.autorest/@[email protected]/node_modules/@microsoft.azure/autorest-core/dist' (3.0.5537)
   Loading AutoRest extension '@microsoft.azure/autorest.csharp' (~2.3.79->2.3.82)
   Loading AutoRest extension '@microsoft.azure/autorest.modeler' (2.3.55->2.3.55)
FATAL: Error parsing swagger file. Error converting value True to type 'AutoRest.Modeler.Model.Schema'. Path 'components.schemas.ExampleObject.additionalProperties', line 1, position 584.
FATAL: AutoRest.Core.Logging.CodeGenerationException: Error parsing swagger file. Error converting value True to type 'AutoRest.Modeler.Model.Schema'. Path 'components.schemas.ExampleObject.additionalProperties', line 1, position 584.
   at AutoRest.Modeler.SwaggerParser.Parse(String swaggerDocument) in /opt/vsts/work/1/s/src/SwaggerParser.cs:line 52
   at AutoRest.Modeler.Program.<ProcessInternal>d__2.MoveNext() in /opt/vsts/work/1/s/src/Program.cs:line 58
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NewPlugin.<Process>d__15.MoveNext()
/home/kevin/.autorest/@[email protected]/node_modules/@microsoft.azure/autorest-core/dist/lib/pipeline/pipeline.js - FAILURE {}
Process() cancelled due to exception : Plugin imodeler1 reported failure. / Error: Plugin imodeler1 reported failure.
    at /home/kevin/.autorest/@[email protected]/node_modules/@microsoft.azure/autorest-core/dist/lib/pipeline/plugins/external.js:26:19
  Error: Plugin imodeler1 reported failure.

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 since true is an alias for {} and false for {"not":{}}, as explained by Henry Andrews on the json-schema mailing list.

All 8 comments

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/[email protected] does not support it. Try adding this parameter --use:@autorest/[email protected]. Note that the new v3-supporting C# generator is under development and not fully released yet.

Try adding this parameter --use:@autorest/[email protected].

Thanks @daviwil! Running autorest --use:@autorest/[email protected] --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/@[email protected]/node_modules/@autorest/core/dist' (3.0.6246)
  Error: Unable to resolve package '@autorest/[email protected]'.

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/@[email protected]/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/@[email protected]/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.

Was this page helpful?
0 / 5 - 0 ratings