question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allOf as schema reference is not allowed

See original GitHub issue

I 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:

  1. Is this “valid” Swagger?
  2. If not, how can this problem be solved so that the Swagger spec is valid?
  3. 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:closed
  • Created 6 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
RicoSutercommented, Oct 17, 2017

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).

0reactions
olydiscommented, Oct 23, 2017

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 type object; having properties: {} 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found