Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to render examples with only readonly properties #160

Open
sevdog opened this issue Oct 16, 2024 · 0 comments
Open

Unable to render examples with only readonly properties #160

sevdog opened this issue Oct 16, 2024 · 0 comments

Comments

@sevdog
Copy link

sevdog commented Oct 16, 2024

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:

if examples is None:
examples = {}
if not example:
if re.match(r"application/[a-zA-Z\+]*json", content_type) is None:
LOG.info("skipping non-JSON example generation.")
continue
example = _parse_schema(content["schema"], method=method)
if method is None:
examples["Example response"] = {
"value": example,
}
else:
examples["Example request"] = {
"value": example,
}
for example in examples.values():
# According to OpenAPI v3 specs, string examples should be left unchanged
if not isinstance(example["value"], str):
example["value"] = json.dumps(
example["value"], indent=4, separators=(",", ": ")
)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant