External reference not resolved correctly
Description
We have the following folder structure:
- openapi.json
- products
-- firstEndpoint.json
-- secondEndpoint.json
- schemas
-- FirstRequest.json
-- SecondRequest.json
-- SomeField.json
with:
openapi.json
{
"openapi": "3.0.3",
"info": {
"title": "API",
"version": "1.0.0"
},
"paths": {
"/firstEndpoint": {
"$ref": "products/firstEndpoint.json"
},
"/secondEndpoint": {
"$ref": "products/secondEndpoint.json"
}
}
}
firstEndpoint.json
{
"post": {
"operationId": "testOne",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "schemas/FirstRequest.json"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
secondEndpoint.json
{
"post": {
"operationId": "testTwo",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "schemas/SecondRequest.json"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
}
FirstRequest.json
{
"type": "object",
"properties": {
"someField": {
"$ref": "SomeField.json"
}
}
}
SecondRequest.json
{
"type": "object",
"properties": {
"someField": {
"$ref": "SomeField.json"
}
}
}
SomeField.json
{
"type": "object",
"properties": {
"someProperty": {
"type": "string"
}
}
}
The problem is, that the types.gen.ts generates the first reference on SomeField.json in FirstRequest.json correctly but can not resolve the same reference in SecondRequest.json:
types.gen.ts
export type TestOneData = {
requestBody: {
someField?: {
someProperty?: string;
};
};
};
export type TestTwoData = {
requestBody: {
someField?: paths__1firstEndpoint_post_requestBody_content_application_1json_schema_properties_someField; // <-- this does not compile
};
};
OpenAPI specification (optional)
No response
Configuration
import { defineConfig } from '@hey-api/openapi-ts';
export default defineConfig({
input: '../openapi/openapi-test.json',
output: {
path: 'src/client',
format: 'prettier'
},
debug: true
});
System information (optional)
npm 10.7.0 Node 20.14.0 openapi-ts 0.46.3
Interesting, thanks for reporting @tde-desc
Do you have any idea, when you are going to address this issue? I am asking because we would like to use your lib intensively, but need a possibility to reuse external references.
@tde-desc can you please create a reproducible example in StackBlitz?
@mrlubos ofcause, here you go https://stackblitz.com/edit/stackblitz-starters-kowe2x?file=src%2Fclient%2Ftypes.gen.ts - reproducable with
npm run openapi-ts
Duplicate of https://github.com/hey-api/openapi-ts/issues/1135
cc @carson2222
Hey @tde-desc, thanks for all your effort! I've managed to fix the ref parser issue: https://github.com/hey-api/json-schema-ref-parser/pull/10 We will soon update the openapi-ts to use the latest ref parser 1.0.7 version.