OAS3.0: imodeler1 failure for boolean additionalProperties
See original GitHub issueAutorest 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 autorest@3.0.6187
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/@microsoft.azure_autorest-core@3.0.5537/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/@microsoft.azure_autorest-core@3.0.5537/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/@microsoft.azure_autorest-core@3.0.5537/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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
OpenAPI Specification - Version 3.0.3 - Swagger
properties - Property definitions MUST be a Schema Object and not a standard JSON Schema (inline or referenced). additionalProperties - Value can be...
Read more >Schema in a response allows additional properties
The schema you have defined allows additional properties, either intentionally or unintentionally. In JSON, by default, any object can also accept additional ......
Read more >Documentation for the spring Generator
If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true ( ...
Read more >OpenAPI Specification v3.0.3 | Introduction, Definitions, & More
additionalProperties - Value can be boolean or object. Inline or referenced schema MUST be of a Schema Object and not a standard JSON...
Read more >Additional properties not allowed: oneOf
choice/choice.boolean.output.json" }, { "$ref": "../. ... I have the same error : Additional properties not allowed: oneOf at #/properties/.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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?
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!