-
Notifications
You must be signed in to change notification settings - Fork 396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$ref inheritance not supported #613
Comments
Any update on that? I have the same issue. |
+1 on this bug. We are working with pydantic in our project and they recently removed their workaround for this bug so that now we have to rebuild this workaround as long as this bug is not solved. Here is a comment that leads to the bugfix in the json schema. Is it possible that this issue is due to the underlying ref parser? I found this discussion and it seems it won't be solved there. From my understanding to solve this bug the ref parser needs to be changed or a user setting has to be added that allows to switch the ref parser. |
Excuse me, how exactly should inheritance $ref be differentiated from reuse $ref |
Do you have more context about inheritance vs reuse ? I must admit I don't understand you question(s). Some samples maybe and expected output ? |
Sorry for sending unclear message. I tried to illustrated it with the example below: |
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Function",
"type": "object",
"additionalProperties": false,
"allOf": [
{
"$ref": "#/$defs/baseType"
},
{
"properties": {
"in": {
"$ref": "#/$defs/taggedValue"
},
"out": {
"$ref": "#/$defs/taggedValue"
}
}
}
],
"$defs": {
"baseType": {
"title": "BaseType",
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"taggedValue": {
"title": "TaggedValue",
"type": "object",
"properties": {
"tag": {
"type": "string"
},
"value": {
"type": "number"
}
}
}
}
} |
Actual output: export type Function = BaseType & {
in?: TaggedValue;
out?: TaggedValue;
[k: string]: unknown;
};
export interface BaseType {
name?: string;
[k: string]: unknown;
}
export interface TaggedValue {
tag?: string;
value?: number;
[k: string]: unknown;
} |
Desired output: export interface Function extends BaseType {
in?: TaggedValue;
out?: TaggedValue;
};
export interface BaseType {
name?: string;
}
export interface TaggedValue {
tag?: string;
value?: number;
} |
In the above example $ref is intended to be used for My question is how to distinguish these different uses of ref? What is the criteria? For instance, refs, under |
When modeling inheritance, we can use
$ref
to point to an existing definition and extend it.e.g.:
and the expected output to be equivalent to:
But with the provided code, the output of
json-schema-to-typescript
(14.1) with default options will be erroneous:BaseType
even if it's "reachable"BaseType
will be missing inPerson
Person
object can have extra properties even thoughunevaluatedProperties
is set to falseHere is the generated output with the default settings:
Even by enabling
unreachableDefinitions
, the output isn't better.BaseType
appears but it's still not used properly.The closest schema that would produce something close to the expected result would be:
Edit: I removed a part I was talking about using
additionalProperties
to store the $ref but I was mistaken, it's not the same behavior.The text was updated successfully, but these errors were encountered: