YousefED / YousefED/typescript-json-schema
[feature request] replace repeated nested structures with references
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 332
- PR merge metrics
- No merged PRs in 30d
Description
Sorry if this behavior already exists, I've reviewed the docs and am pretty sure it doesn't. I'm transferring ts -> json schema and then json schema -> pydantic. In this process the naming is important because otherwise some types will lose their meaning. Currently, it is challenging for the json schema -> pydantic model to resolve nested common refs. The --aliasRefs seems to address this issue nicely, but it does abstract the names of the refs as well. For instance,
{
"ISectionBlockMetadata": {
"$ref": "#/definitions/__type_2"
},
"__type_2": {
"properties": {
"asText": {
"title": "asText",
"type": "string"
}
},
"required": [
"asText"
],
"title": "__type_2",
"type": "object"
},
}
In this case the definition of __type_2 and its name ISectionBlockMetadata are separated. When it's compiled to pydantic it converts to something like:
class ISectionBlockMetadata(BaseModel):
__root__: FieldType2
class FieldType2(BaseModel):
as_text: str = Field(..., alias='asText', title='asText')
I believe a possible workaround for this could be to simply pass the parent ref name to the child as the title. For instance, I'd expect it to result in the following:
{
"ISectionBlockMetadata": {
"$ref": "#/definitions/__type_2"
},
"__type_2": {
"properties": {
"asText": {
"title": "asText",
"type": "string"
}
},
"required": [
"asText"
],
"title": "ISectionBlockMetadata",
"type": "object"
},
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the --aliasRefs handling and trace how nested common references receive their generated names; compare the reported input and expected schemas. Done means the child definition preserves the parent reference name as its title while existing reference behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100