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():
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.
This does not seem to be an issue with json-schema-ref-parser - the json schema returned by the ref parser is valid, and does not append the names. This looks like an issue in the library you are using.
Hey there,
I’m trying to resolve some $refs in a YML model that looks like this:
TranslatableField.yml
looks like this:As you can see, I’m referencing
TranslatableField
multiple times. I would expect my TypeScript interface to look like this after callingcompile()
:… but what I get is this:
Note the extra numbers at the end of
TranslatableField
. WithdeclareExternallyReferenced: 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