Skip to content

Circular reference error in openapi spec #3689

@scamden

Description

@scamden

Describe the bug

Circular reference error

To Reproduce Steps to reproduce the behavior:

const spec = {
  openapi: '3.0.0',
  paths: {
    '/test': {
      post: {
        requestBody: {
          required: true,
          content: {
            'application/json': {
              schema: {
                $ref: '#/components/schemas/RequestBody',
              },
            },
          },
        },
        responses: {
          '200': {
            description: 'ok',
            content: {
              'application/json': {
                schema: {
                  type: 'object',
                  properties: {
                    ok: { type: 'boolean' },
                  },
                },
              },
            },
          },
        },
      },
    },
  },
  components: {
    schemas: {
      RequestBody: {
        type: 'object',
        properties: {
          filters: {
            type: 'array',
            items: {
              anyOf: [
                { $ref: '#/components/schemas/FilterGroup' },
                { $ref: '#/components/schemas/SoloFilter' },
              ],
            },
          },
        },
      },
      FilterGroup: {
        type: 'object',
        required: ['operator', 'filters'],
        properties: {
          operator: {
            type: 'string',
            enum: ['AND', 'OR'],
          },
          filters: {
            type: 'array',
            items: {
              anyOf: [
                { $ref: '#/components/schemas/FilterGroup' },
                { $ref: '#/components/schemas/SoloFilter' },
              ],
            },
          },
        },
      },
      SoloFilter: {
        type: 'object',
        required: ['field'],
        properties: {
          field: {
            type: 'string',
          },
        },
      },
    },
  },
} as const;
type TOAS = NormalizeOAS<typeof spec>;
const client = createClient<TOAS>({ endpoint: 'http://example.com' });
const simpleFilters = [{ field: 'targetIp', comparator: 'eq', value: '1.2.3.4' }];
const body = {
  filters: simpleFilters,
};

// this errors.. notably it doesn't if i pass the body directly as a literal and not from a variable
void client['/test'].post(body);

Expected behavior

no error

Environment:

  • OS:
    Mac
  • NodeJS:
    24

Additional context

I'm on the latest feTS

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions