Skip to content

Unable to render examples with only readonly properties #160

@sevdog

Description

@sevdog

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions