How to generate a Swagger #definition from sample JSON

后端 未结 3 1378
伪装坚强ぢ
伪装坚强ぢ 2021-01-04 10:37

Take the following #definition from the pet store example. Given a #definition section a JSON structure can be generated

e.g.

Is there something that can do

相关标签:
3条回答
  • 2021-01-04 11:19

    You can use this JSON-to-OpenAPI schema converter:
    https://roger13.github.io/SwagDefGen/

    (GitHub project)

    I haven't used it personally though, so I'm not sure how good it is.


    Since OpenAPI uses a subset of JSON Schema, you could also use one of the JSON Schema generators, however you may need to manually tweak the generated definition to make it OpenAPI-compatible.

    0 讨论(0)
  • 2021-01-04 11:19

    1 - Paste a response in http://www.mocky.io and get a link to your response

    2 - Go to https://inspector.swagger.io/ and make a call to your example response

    3 - Select the call from "History" and click "Create API definition"

    4 - The swagger definition will be available at https://app.swaggerhub.com/

    0 讨论(0)
  • 2021-01-04 11:32

    This works for me:

    Generate Swagger REST-client code (and POJO) from sample JSON:

    1. Go to apistudio.io:

      • Insert -> New Model.
      • CutNpaste your JSON.
      • [The Swagger YML file will be generated]
      • Download -> YAML.
    2. Go to editor.swagger.io:

      • CutNpaste the YML saved from last step.
      • Generate Client -> jaxrs-cxf-client (there are many other options).
    0 讨论(0)
提交回复
热议问题