How to generate JSON examples from OpenAPI/Swagger model definition?

前端 未结 2 448
花落未央
花落未央 2020-12-10 08:37

I\'m building a fuzzer for a REST API that has an OpenAPI (Swagger) definition.

I want to test all available path from the OpenAPI definition, generate data to test

2条回答
  •  时光说笑
    2020-12-10 09:14

    My experience:

    1. go to http://editor.swagger.io
    2. File -> Import file (to load my own Swagger description)
    3. Generate client -> Java (in my case)
    4. Download and extract the client
    5. Import it's model package into any simple project, instantiate and fill model's classes with the data you need
    6. Marshall the instantiated objects into the JSON (My case - Gson, because the generated model is annotated by Gson annotations)
    7. Profit

    In short: generating client (java-client in my case) based on Swagger definition, filling it's model and marshalling the result.

提交回复
热议问题