Skip to content

Clean up pydantic JSON Schema and generated TypeScript types#161

Merged
gjreda merged 10 commits into
mainfrom
cleaner-json-schema
Jun 15, 2023
Merged

Clean up pydantic JSON Schema and generated TypeScript types#161
gjreda merged 10 commits into
mainfrom
cleaner-json-schema

Conversation

@danvk

@danvk danvk commented Jun 15, 2023

Copy link
Copy Markdown
Collaborator

We were getting some odd type aliases on the TypeScript side because Pydantic generated JSON Schema with fields like this:

{
  "given_name": {
    "title": "Given Name",
    "type": "string"
  }
}

json-schema-to-typescript turns this into:

type GivenName = string;

and then uses that as a type alias. The party line from both projects is that they're both doing this correctly (see bcherny/json-schema-to-typescript#504 and pydantic/pydantic#1740), however pydantic seems to recognize that this may not be what everyone wants and provides example code to strip off title in their docs:

"For example, the title key can be removed from the model's properties:"
https://docs.pydantic.dev/latest/usage/schema/#schema-customization

We can define our own base model to use this in all our API types.

@danvk danvk marked this pull request as ready for review June 15, 2023 16:43
@danvk danvk requested a review from gjreda June 15, 2023 16:44
@gjreda gjreda merged commit c277ab8 into main Jun 15, 2023
@gjreda gjreda deleted the cleaner-json-schema branch June 15, 2023 16:57
@gjreda

gjreda commented Jun 15, 2023

Copy link
Copy Markdown
Collaborator

part of the work for #136

@gjreda gjreda mentioned this pull request Jun 15, 2023
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

Successfully merging this pull request may close these issues.

2 participants