2014-10-09 11 views
5

Mam trudny czas próbuje dowiedzieć się, jak mogę zagnieździć modele w Swagger 2.0.Właściwość odniesienia do modelu na swagger 2.0 (zagnieżdżanie)

Obecnie mam:

SomeModel: 
properties: 
    prop1: 
    type: string 
    prop2: 
    type: integer 
    prop3: 
    type: 
     $ref: OtherModel 

OtherModel: 
    properties: 
    otherProp: 
     type: string 

Próbowałem wiele innych sposobów:

prop3: 
    $ref: OtherModel 
# or 
prop3: 
    schema: 
    $ref: OtherModel 
# or 
prop3: 
    type: 
    schema: 
     $ref: OtherModel 

Żadne z powyższych wydają się działać.

Jednak z tablicami działa dobrze:

prop3: 
    type: array 
    items: 
    $ref: OtherModel 

Odpowiedz

16

Prawidłowy sposób modelować byłoby:

SomeModel: 
properties: 
    prop1: 
    type: string 
    prop2: 
    type: integer 
    prop3: 
    $ref: OtherModel 

OtherModel: 
    properties: 
    otherProp: 
     type: string 
+0

można rzucić okiem na http://stackoverflow.com/questions/35127186/swagger-2-x-reference-model-from-other-file Czy istnieje problem stosując zamiast JSON z yaml? – Gobliins

1

wierzę przykład Rona powinien brzmieć:

definitions: 

    OtherModel: 
     properties: 
      otherProp: 
      type: string 

    SomeModel: 
     properties: 
      prop1: 
      type: string 
      prop2: 
      type: integer 
      prop3: 
      type: object 
      $ref: #/definitions/OtherModel 
4

I Wierzę, że przykład Herc powinien być

definicje:

OtherModel: 
    properties: 
     otherProp: 
     type: string 

SomeModel: 
    properties: 
     prop1: 
     type: string 
     prop2: 
     type: integer 
     prop3: 
     type: object 
     $ref: '#/definitions/OtherModel' 
+0

Coś musi się zmienić w specyfikacji, ponieważ twoja odpowiedź działa dla mnie, podczas gdy zaakceptowana odpowiedź nie działa. Nie potrzebowałem 'type: object' dla' prop3' – chrisan

Powiązane problemy