0

I am looking for tool to create openapi specification from json file. For example, I want to convert this:

{
    "checked": false,
    "dimensions": {
        "width": 5,
        "height": 10
    },
    "id": 1,
    "name": "A green door",
    "price": 12.5,
}

to

  type: object
  title: The root schema
  description: The root schema comprises the entire JSON document.
  default: {}
  example: 
    - checked: false
      dimensions:
        width: 5
        height: 10
      id: 1
      name: A green door
      price: 12.5
      tags:
        - home
        - green
  required:
    - checked
    - dimensions
    - id
    - name
    - price
    - tags
  additionalProperties: true
  properties:
    checked:
      type: boolean
      title: The checked schema
      description: An explanation about the purpose of this instance.
      default: false
      example:
        - false
    dimensions:
      type: object
      title: The dimensions schema
      description: An explanation about the purpose of this instance.
      default: {}
      example:
        - width: 5
          height: 10
      required:
        - width
        - height
      additionalProperties: true
      properties:
        width:
          type: integer
          title: The width schema
          description: An explanation about the purpose of this instance.
          default: 0
          example:
            - 5
        height:
          type: integer
          title: The height schema
          description: An explanation about the purpose of this instance.
          default: 0
          example:
            - 10
    id:
      type: integer
      title: The id schema
      description: An explanation about the purpose of this instance.
      default: 0
      example:
        - 1
    name:
      type: string
      title: The name schema
      description: An explanation about the purpose of this instance.
      default: ''
      example:
        - A green door
    price:
      type: number
      title: The price schema
      description: An explanation about the purpose of this instance.
      default: 0
      example:
        - 12.5
2

I found the answer from the Stack Overflow question How to generate a Swagger #definition from sample JSON.

And I think SwagDefGen serve your request.

I tried and the generated Swagger file works when I import it in OpenAPI tools (i.e. studio.apicur.io) but it can only contain simple types, not complex types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.