`$ref` with other keywords doesn't work
Description
In the specifications up to the JSON Schema Draft 7, if you included other keywords in an object using $ref, they were ignored^1, but starting with the Draft 2019-09, you are allowed to include other properties in $ref^2. Since the OAS 3.1.0 is 100% compatible with the Draft 2020-12^3, the OAS 3.1.0 allows such usage, but openapi-typescript does not reflect it in the type definition.
| Name | Version |
|---|---|
openapi-typescript |
7.0.0-next.8 |
| Node.js | 21.7.1 |
| OS + version | macOS 14.4 |
Reproduction
- Generate type definitions using the following document:
OpenAPI document
{
"openapi": "3.1.0",
"info": {
"title": "Example API",
"version": "1.0.0"
},
"servers": [
{
"url": "https://example.com/api"
}
],
"security": [],
"paths": {
"/example": {
"get": {
"operationId": "getExample",
"summary": "Get example",
"responses": {
"200": {
"description": "Get successfully",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/example",
"properties": {
"b": "number"
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"example": {
"type": "object",
"properties": {
"a": {
"type": "string"
}
},
"required": [
"a"
]
}
}
}
}
- Then you get the following result:
content: {
"application/json": components["schemas"]["example"];
};
Expected result
I think this would have to be:
content: {
"application/json": components["schemas"]["example"] & { b?: number };
};
Checklist
- [x] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) - [ ] I’m willing to open a PR (see CONTRIBUTING.md)
This is a good addition! I think 6.x or 7.x (beta) could support this addition without it being a breaking change. Would love a PR for this if anyone is able to provide one!
Not sure if I should create another issue for this, but I think it might be related to the above. In the case of composition, required gets ignored in this scenario:
{
...
"components": {
"schemas": {
"Foo": {
"type": "object"
"properties": {
"id": {
...
}
}
},
"Bar": {
"allOf": [
{ "$ref": "#/components/schemas/Foo" },
{ "required": ["id"] }
]
}
}
}
}
This issue is stale because it has been open for 90 days with no activity. If there is no activity in the next 7 days, the issue will be closed.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please open a new issue if you believe you are encountering a related problem.