Numbers being appended to the TypeScript interface names when using the same $ref multiple times
Hey there,
I’m trying to resolve some $refs in a YML model that looks like this:
type: object
required:
- title
properties:
identifier:
type: string
title:
$ref: "TranslatableField.yml"
example:
de: Konzert
en: concert
displayName:
$ref: "TranslatableField.yml"
description:
$ref: "TranslatableField.yml"
example:
de: Eine Beschreibung
en: Some description
TranslatableField.yml looks like this:
type: object
additionalProperties:
type: string
description: |-
A string that can be translated into multiple languages, e.g. { "de": "Konzert", "en": "concert" }
example:
de: Konzert
en: concert
As you can see, I’m referencing TranslatableField multiple times. I would expect my TypeScript interface to look like this after calling compile():
export interface Model {
title: TranslatableField
displayName?: TranslatableField
description?: TranslatableField
}
… but what I get is this:
export interface Model {
title: TranslatableField
displayName?: TranslatableField1
description?: TranslatableField2
}
Note the extra numbers at the end of TranslatableField. With declareExternallyReferenced: false this breaks the generated TypeScript file, because that’s an invalid model name that cannot be found/imported from anywhere. I’d like to reuse the same name (TranslatableField without the number) for all fields.
Here’s a full example: https://codesandbox.io/p/sandbox/json-schema-to-typescript-test-8n5d9s
Is there any way to prevent these extra number suffixes, e.g. with some configuration? 🤔
I appreciate any hints or ideas!
References
- https://github.com/bcherny/json-schema-to-typescript/issues/193