allOf as schema reference is not allowed
See original GitHub issueI discovered a problem with my Swagger spec which is generated with NSwag.
The problem applies to parameters and schema properties. It happens if the parameter or property has a “description” (which belongs only to the parameter/property) and needs a reference to another type from the “definitions”. The problem is that $ref is only allowed as only property (we also have a “description”). This is why NSwag generates the “description” and the $ref in an “allOf”.
See sample:
definitions:
ContentOwnershipTransferRequest:
type: object
additionalProperties: false
properties:
contentId:
type: string
description: The content id.
transferUserId:
type: string
description: The id of the user to whom the content document has to be transfered to.
ContentDetail:
type: object
description: A content detail.
additionalProperties: false
required:
- contentType
- entityType
- trashed
properties:
audit:
description: Audit data with information regarding document creation and modification.
allOf:
- $ref: '#/definitions/StoreAudit'
My questions are:
- Is this “valid” Swagger?
- If not, how can this problem be solved so that the Swagger spec is valid?
- Can this be fixed in AutoRest so that the reference is correctly resolved? (I currently get a Key not found in SwaggerModeler.cs, line 130)
Btw: I’m the developer of NSwag.
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (9 by maintainers)
Top Results From Across the Web
Could not resolve schema reference '#foo'. Path 'not.allOf[0 ...
I would call this a bug in the implementation. Your schema is valid for JSON Schema draft-07 , but not JSON Schema draft...
Read more >oneOf, anyOf, allOf, not - Swagger
Note the inline or referenced schema must be a schema object, not a standard JSON Schema. Now, to validation. The following JSON object...
Read more >Schema name no longer appears correctly when referenced ...
Schema name no longer appears correctly when referenced in allOf + oneOf - it just shows as the name of the model all...
Read more >Circular reference is not allowed
For example, a schema object in allOf must not reference the schema holding the allOf property. Same applies to oneOf , anyOf and...
Read more >OpenAPI Specification
null is not supported as a type (see nullable for an alternative solution). Models are defined using the Schema Object, which is an...
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
No the fixes are additional problems… and should probably looked at by Java guys (I’m a .NET guy so maybe I also did something wrong, but the missing imports are surely a bug).
Fair points regarding the fixes, will look into/discuss it 🙂 Regarding 2, I think that is one of the odd decisions that were once made (I think not having
properties
at all is interpreted as the intent to use the actual typeobject
; havingproperties: {}
on the other hand encodes the empty class, which then for some reason was decided to not be generated - and now we have customers depending on that, but maybe--generate-empty-classes=true
helps). 3 looks like a bug indeed, will check and summon a fix.