[REQ] Generate data model with default value mapping from openapi.examples
Is your feature request related to a problem? Please describe.
Hi team, currently one of the key feature that I find extremely powerful is of course the data model generation, which is extremely helpful and speed up development process. However, part of the process is testing, and reusing that data model to do testing is a norm, and data mapping can be tedious work. I'd like to speed up that testing process.
Describe the solution you'd like
Since OpenAPI have a examples field available, my solution to speed up the process is to leverage that as a part of the data model generation. Of course, this can be optional under new parameter like --include-examples to prevent too much unwanted generation. The implementation that I had in mind would start from reading those examples under object reference and create additional static method/extensions to be matching with existing examples.
For instance
// static method approach
var exampleResponse = DataModel.PrepareDefaultExamples();
var exampleResponse = DataModel.PrepareScenarioAExamples();
Describe alternatives you've considered
N/A
Additional context
I've been taking a look on how mock server can be generated from OpenAPI specs like wiremock, it also leverage the examples from openapi specs as well. Although, implementing this feature in the generator tools can have much more impact and supporting testing more multiple layer like unit test or integration test, and hopefully resulting in a better maintain documentation.
This is a great idea — generating example/default values for models is very useful.
I’d like to extend this concept further. For Kotlin, it would be amazing to generate a full fake/mock client that implements all API interfaces and returns example or schema-derived data.
I’ve opened a separate feature request specifically for this here: Kotlin fake mock library on OpenAPI examples.