starlight-openapi
starlight-openapi copied to clipboard
[Feature Request]Auto-generate JSON example from schema when no explicit example is provided
Is your feature request related to a problem?
This feature request might also be related to issue #43 in the repository. starlight-openapi like Swagger UI or Redocly automatically generate and display example JSON based on the schema definition when no explicit example is provided. I would like this tool to support a similar feature, so users can easily understand request and response structures even without manually defined examples.
Describe the solution you'd like
I would like the tool to automatically generate a JSON example from the schema when no explicit example is provided. If an example is explicitly defined, that should take precedence. Additionally, it would be helpful to have a configuration flag to enable or disable this auto-generation behavior.
Describe alternatives you've considered
I have considered manually writing examples for each schema. However, this can be time-consuming and error-prone, especially when dealing with large APIs. In the case of simple APIs, detailed examples may not always be necessary, but having at least a basic example in JSON format greatly improves usability for consumers. Auto-generating these examples based on the schema can help reduce manual work while still offering helpful guidance to developers.
Additional Context
Swagger
Redocly
The values in these examples will vary depending on the schema definition, and the default values differ between Swagger and Redocly. However, as long as the values fall within the valid range defined by the schema, I believe that’s acceptable.
Thanks for the feedback.
I think indeed it's quite related to #43 except that it's expanded to another part of the UI. Like I said in the other issue, I think indeed this could be possible to implement this enhancement at some point altho quite a few questions remain, e.g. how would this work, where and how would it be displayed, etc.
Personally, I think it's best to have such examples in the specification itself, as on top of having controlled and consistent examples for everyone, it also allows for anyone no matter the tool they use, from the raw OpenAPI spec to any other tool, to benefit from it.
Thank you for your response, and I really appreciate this library — it's been very helpful. You're right, that does make sense. When migrating existing OpenAPI specifications, it would be convenient if examples could be automatically generated from the schema when they are missing. However, I also believe that API providers should ideally provide realistic examples themselves. I'll leave it up to the maintainer to decide whether to close this issue.
I'll leave it up to the maintainer to decide whether to close this issue.
I'm definitely keeping it opened like #43 as a future enhancement. Even tho it's not something I recommend, the reality is that some people expect it or are accustomed to it from other tools.
Not quite sure when I'll have time to work on it, but I am definitely keeping it in mind.