Swagger-editor: multiple $ref under items

Created on 7 Oct 2016  路  16Comments  路  Source: swagger-api/swagger-editor

Hi,
I could not find a similar issue

 dpf_templates:
        type: array
        items:
          $ref: '#/definitions/Dpf_template_VCF'
          $ref: '#/definitions/Dpf_template_Json'

definitions:
  Dpf_template_VCF:



  Dpf_template_Json:

  • 2.2.5:
  • Browser/OS:

Is this possible? Swagger Ui gives me an error when running this.
Any help would be really appreciated. Thanks.

question

All 16 comments

Instead of adding them both, use allOf.

dpf_templates:
  type:
    allOf:
      - $ref: '#/definitions/Dpf_template_VCF'
      - $ref: '#/definitions/Dpf_template_Json'

definitions:
  Dpf_template_VCF:


  Dpf_template_Json:

@saharj , thaks for the prompt reply,
Still does not work,

image

UI shows this:

image

Also, I should mention more about schema.

paths:
  /dpf_templates:
    get:
      description: >
         tags:
        responses:
          '200':
        description: OK
        schema:
          $ref: '#/definitions/Dpf_Tepmlates'

which further references it from definitions:

definitions:
  Dpf_Tepmlates:
    type: object
    properties:
      _links:
        type: object
        properties:
          curies:
            type: array
            items:
              $ref: _hal.yaml#/Curie
          self:
            $ref: _hal.yaml#/Self
      dpf_templates:
        type:
          allof:
            - $ref: '#/definitions/Dpf_template_VCF'
            - $ref: '#/definitions/Dpf_template_Json'

 Dpf_template_VCF:

Dpf_template_Json:

Your allOf syntax is wrong, and you spelled allOf wrong (computers are very picky about this stuff)

definitions:
  foo:
    allOf:
    - $ref: '#/definitions/bar'
    - $ref: '#/definitions/baz'
  bar:
    properties:
      bar:
        type: string
  baz:
    properties:
      bar:
        type: string

What about:

definitions:
  allOf:
  - $ref: '#/externalDefinitions/bar'
  - $ref: '#/externalDefinitions/baz'

This works in swaggerui, but fails in redoc, fails in the online validator, and fails in the swagger editor.

You can't use allOf directly under definitions - it's invalid by the spec.

Any suggestions on how to include a list of definitions from 2 separate files? Why does swagger ui allow it and load the lists from both files fine?

It's a bug in swagger-ui (or rather swagger-js) - it will try to interpret allOf (and other keywords) in places they're not allowed.

There's no way to include a list of definitions from 2 separate files (or even one file for that matter), but I'm not really seeing the need for it either.

My use case is I have a separate models.yml, with a few groups (shared, departments, and mobile).

In the departments api it should list shared and departments.
in the separate mobile swagger spec, it lists shared and mobile.

I tried this:

definitions:

  allOf:
  - $ref: 'models.yml#/shared'

  - newMessage:


  - payloadWrapperForQueues:

  - joinFlightRequest:

and it gets me to a bizarre situation where the models are listed fine, but cannot be referenced under #/definitions/modelName

Yeah, what you're doing there is defining a model called allOf, not exactly what you want.

Just reference the external models from where they are needed.

That wouldn't list them at the bottom of swagger-ui.

I liked the fact that it wouldn't list models that were included from a separate file, as it let you easily hide sub-models (pieces that are reused, but not standalone models).

That indeed wouldn't list them. You can file a request to have an option to list all models, including referenced ones. Right now, to make it work, you'd need to 'redefine' them individually under definitions by creating a model for each and referencing the external files.

I guess this is the only way (re-write every include):

definitions:

  config:
    $ref: 'models.yml#/shared/config'
  incomingMessage:
    $ref: 'models.yml#/shared/incomingMessage'

  newMessage:

This seems really weird.

I agree, but if you want them to appear in the models, right now it's the only way.

Doing this seems to generate a lot of superfluous warnings:

Swagger Warning
Extra JSON Reference properties will be ignored: title
Jump to line XXX

There is no "title" in the code to be ignored..

Can't help without actually seeing the definition(s) and we're polluting this issue already...

It doesnt seem to have anything to do with the definition. I guess its creating some virtual "title" attribute whenever I do a ref, and then ignoring it. This is in Editor2 (the only one that supports multiple files) so maybe its just and old bug. Thanks for your help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

freak4pc picture freak4pc  路  3Comments

variable picture variable  路  4Comments

jennaprice picture jennaprice  路  4Comments

bluesh55 picture bluesh55  路  3Comments

fchebbo picture fchebbo  路  5Comments