Skip to content

External reference not resolved correctly #668

@tde-desc

Description

@tde-desc

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions