Just to clarify - do you want to generate an example of JSON payload based on a schema definition? Or do you need a mock server that would return sample responses? Or something else?
Thank you for your response.
I wanted to generate an example of JSON payload based on a method return type, same as swagger generate the response example.
You can use the Swagger Inflector Java library, specifically its ExampleBuilder class, to generate JSON examples. Here's sample code:
swagger-inflector, only works when the schema is defined, Here is more details about my query.
I have an API "/hello" defined below.
and Person class like below.
I wanted to generate a response example like below.
swagger-inflector, only works when the schema is defined
ExampleBuilder does not necessarily need a named schema; it can use any schema, including those defined inline - you just need to pass in the appropriate parameters. And the parser has methods to get the response schema for a specific path, HTTP method, and response code
In your case, to generate an example for the path /hello, method GET, and HTTP status 200 you can use:
Model responseSchema = swagger.getPath("/hello")
.getResponseSchema(); Example example = ExampleBuilder.fromModel(null, responseSchema, definitions, new HashSet<String>());
The rest of the code is the same as here.