autorest: allOf as schema reference is not allowed

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.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 18 (9 by maintainers)

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