Skip to content

Better rendering of example responses #64

Closed

Description

@jan-ldwg

I'm using the mkdocs plugin.

When rendering the example for a response, the values of the examples array in the json schema are not used.

This
"name": { "description": "", "type": "string", "examples": ["A-DSP", "MON 1"] },
gets rendered as

"name": "string"

In my opinion it should use a value from the examples array.

Image

A similar issue exists for enums, they get rendered as null, I think rendering one of the possible values would be better.

I guess the rendering of an array of a type and null is fixed with the latest pr, but a new release would be greatly appreciated.

Activity

  1. jan-ldwg commented on Mar 5, 2026

    @jan-ldwg
    Author

    I tested it further, example with just one value works as expected, but from my understanding examples with an array of values is the correct way since JSON schema draft 6

  2. added a commit that references this issue on Mar 7, 2026
    3308067
  3. jan-ldwg commented on Mar 7, 2026

    @jan-ldwg
    Author

    Thank you for the quick fix!

    examples works as expected, however, enum still renders null for me, not the first element.

  4. RobertoPrevato commented on Mar 7, 2026

    @RobertoPrevato
    Member

    @jan-ldwg thanks for the heads up. When I reviewed I checked this detail, but I must have done something wrong. I'll take a look. Contributions are welcome, in case you beat me on time. - finally I used the Copilot CLI. 👀

  5. RobertoPrevato commented on Mar 7, 2026

    @RobertoPrevato
    Member

    This is what Claude Sonnet 4.6 analyzed with the Copilot CLI:

    The root cause was that enum without an explicit type field (perfectly valid JSON Schema) fell through to return None — the enum check in ScalarExampleHandler was only
    reached when there was a type to dispatch on. Fixed by adding an early enum check in get_example_from_schema itself, just like the examples check, so it catches all
    cases regardless of whether type is present.

  6. RobertoPrevato commented on Mar 7, 2026

    @RobertoPrevato
    Member

    @jan-ldwg can you please try definining a type for the enum in your case? When I reviewed, I reviewed the situation of enums having type defined in the schema.

  7. jan-ldwg commented on Mar 7, 2026

    @jan-ldwg
    Author

    You`re right, having a type defined fixes it. Thank you!

  8. RobertoPrevato commented on Mar 7, 2026

    @RobertoPrevato
    Member

    Thanks! in any case, I will apply the fix for the situation without type defined. I won´t release it today to PyPi, though.

  9. added a commit that references this issue on Mar 7, 2026
    319d55e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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