RaGe
RaGe

Reputation: 23707

Generate request-example in Swagger codegen

I'm attempting to write a new language module for swagger codegen. In my generated client, I would like to include an example request. An instance of this can be seen in swagger UI under "Example Value"

enter image description here

The text itself doesn't seem to be contained in swagger spec for this service, but is constructed from the request object model, recursively de-referencing sub models.

Is there a straightforward way to generate this string within the codegen library? If I have to borrow code from SwaggerUI instead, is there a java implementation I can look at?

Upvotes: 1

Views: 1565

Answers (1)

fehguy
fehguy

Reputation: 6824

You are correct, the UI is generating an example value for the model based on the schema. You can use the io.swagger.codegen.examples.ExampleGenerator in your code to generate models and set them in the object before generating templates.

Upvotes: 3

Related Questions