sphinx-contrib / openapi

OpenAPI (fka Swagger) spec renderer for Sphinx.
https://sphinxcontrib-openapi.readthedocs.io
BSD 2-Clause "Simplified" License
111 stars 81 forks source link

Unable to render examples with only readonly properties #160

Open sevdog opened 1 month ago

sevdog commented 1 month ago

When using the old renderer (since I cannot use the new one due to #124 and I want to keep API docs splitted based on path) with OpenAPI 3.1 and examples enabled there is a problem due to how examples are rendered and guessed:

https://github.com/sphinx-contrib/openapi/blob/e62e2986b66465e785a7ebd8905d639f1893dedc/sphinxcontrib/openapi/openapi31.py#L214-L236

If no example is provided in the swagger file one is guessed from _parse_schema, but if there are only readonly properties this method returns an object (_READONLY_PROPERTY) which is not serializable. This results in an unhandled exception (TypeError: Object of type object is not JSON serializable) which is not what is intended.