Supporting models with composition in API Studio

sgilson
Participant V

I am using API Studio and want to support models with composition. I have a baseType model, and a complexType model that includes all of the baseType model:

  baseType:
    type: object
    required:
      - reviewDescription
      - rating
      - userID
      - truckID
    properties:
      reviewDescription:
        type: string
        format: string
      rating:
        type: integer
        format: int8
      userID:
        type: integer
        format: int64
      truckID:
        type: integer
        format: int64
  complexType:
    allOf:
    - $ref: '#/definitions/baseType'
    - type: object
    required:
    - id
    properties:
      id:
        type: integer
        format: int64

I would expect complexType to appear in API Studio as a single level object, in the form:

complexType {
	id: integer *
	reviewDescription: string *
	rating:	integer *
	userID:	integer *
	truckID: integer *
}

But instead, it appears in API Studio as if all of the properties inherited from baseType are in a nested property called baseType. Here is how the two objects appear in API Studio:

1374-screen-shot-2015-10-22-at-84013-am.png

How do I access the properties in complexType defined by baseType?

Solved Solved
0 3 360
1 ACCEPTED SOLUTION

Not applicable

Hi,

I think you're missing some indentations around your definitions block. I tried to fix it for you. Check it out here:

swagger: "2.0"
info:
  version: "0.0.1"
  title: Swagger API
  
paths: {}

definitions:
  
  
  baseType:
    type: object
    required:
      - reviewDescription
      - rating
      - userID
      - truckID
    properties:
      reviewDescription:
        type: string
        format: string
      rating:
        type: integer
        format: int8
      userID:
        type: integer
        format: int64
      truckID:
        type: integer
        format: int64
        
        
  complexType:
    allOf:
      - 
        $ref: '#/definitions/baseType'
      - 
        type: object
        required:  [id]
        properties:
          id:
            type: integer
            format: int64

http://playground.apistudio.io/8fe7d42f-cb75-45d1-a64f-94b9fae37646

View solution in original post

3 REPLIES 3

Not applicable

Hi,

I think you're missing some indentations around your definitions block. I tried to fix it for you. Check it out here:

swagger: "2.0"
info:
  version: "0.0.1"
  title: Swagger API
  
paths: {}

definitions:
  
  
  baseType:
    type: object
    required:
      - reviewDescription
      - rating
      - userID
      - truckID
    properties:
      reviewDescription:
        type: string
        format: string
      rating:
        type: integer
        format: int8
      userID:
        type: integer
        format: int64
      truckID:
        type: integer
        format: int64
        
        
  complexType:
    allOf:
      - 
        $ref: '#/definitions/baseType'
      - 
        type: object
        required:  [id]
        properties:
          id:
            type: integer
            format: int64

http://playground.apistudio.io/8fe7d42f-cb75-45d1-a64f-94b9fae37646

Thanks, the display of complexData still looks odd though. Are all of the properties at the same level in the object? Now id looks like it is at a different level from the other four:

1377-screen-shot-2015-10-22-at-63235-pm.png

They are on the same level. The view doesn't merge them. It shows "all of" as an indication that this is an "allOf" case.