fix: make descriptions/examples available in JSON schema output #274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes two changes
it provides the
Code
example withinjson_schema_extra
rather than theexample
keyword. This resolves a small but annoying deprecation warning. It also requires ticking up the Pydantic pin that just got changed a few days ago, though.It handles
descriptions
inRootModels
to ensure that they're included in the generated JSON schema output (as used by applications like FastAPI). Currently, we supply descriptions to primitive-y types likeCondition
andCode
using thedescription
keyword. Counterintuitively, that argument doesn't actually get used in the JSON schema output, as far as I can tell. Instead, Pydantic first checks if there's a description in thejson_schema_extra
arg, and if not, it just uses the class docstring (otherwise, no description).The simple way out is to just take the description text and supply them as docstrings. This, however, includes a bunch of unsightly newlines and extra spaces. Alternatively, we could include descriptions a second time, but under
json_schema_extra=
, notdescription=
.