swagger-api / swagger-converter

OpenAPI/Swagger 2.0 to OpenAPI 3.0 Converter WebService
https://converter.swagger.io
Apache License 2.0
116 stars 29 forks source link

Convert schema, property and array examples #32

Closed hkosova closed 6 years ago

hkosova commented 7 years ago

Spec: https://gist.githubusercontent.com/hkosova/94b866556692cd099a8720e9b4362b4f/raw/fb668ac8e383b7bf372fb85b03f928386c56ed5f/schema-examples.yaml

definitions:
  User:
    type: object
    properties:
      id:
        type: integer
        readOnly: true
        example: 42
      name:
        type: string
        example: Arthur Dent
      friend_ids:
        type: array
        items:
          type: integer
          example: 8
        example: [3, 4, 5]
    required:
      - id
      - name
    example:
      id: 1
      name: Trillian

  ArrayOfUsers:
    type: array
    items:
      $ref: '#/definitions/User'
    example:
      - id: -1
        name: Marvin the Paranoid Android
      - id: 1000000
        name: Zaphod Beeblebrox
        friends: [15]

Converted spec: http://oai.swagger.io/api/convert?url=https://gist.githubusercontent.com/hkosova/94b866556692cd099a8720e9b4362b4f/raw/fb668ac8e383b7bf372fb85b03f928386c56ed5f/schema-examples.yaml

Expected result:

"components": {
  "schemas": {
    "User": {
      "required": [
        "id",
        "name"
      ],
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "readOnly": true,
          "example": 42  // <------------
        },
        "name": {
          "type": "string",
          "example": "Arthur Dent"  // <------------
        },
        "friend_ids": {
          "type": "array",
          "items": {
            "type": "integer",
            "example": 8    // <------------
          },
          "example": [3, 4, 5]   // <------------
        }
      }
    },
    "ArrayOfUsers": {
      "type": "array",
      "items": {
        "$ref": "#/components/schemas/User"
      },
      "example": [   // <------------
        {
          "id": -1,
          "name": "Marvin the Paranoid Android"
        },
        {
          "id": 1000000,
          "name": "Zaphod Beeblebrox",
          "friends": [15]
        }
      ]
    }
  }
}
ralphdoe commented 6 years ago

Fixed!