Skip to content

fix: fix no-$ref-siblings error #1048

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

Merged
merged 1 commit into from
Jul 29, 2025
Merged

fix: fix no-$ref-siblings error #1048

merged 1 commit into from
Jul 29, 2025

Conversation

shenbenson
Copy link
Contributor

@shenbenson shenbenson commented Jul 21, 2025

Fixes the no-$ref-siblings error seen in this PR

Ticket: DX-1580

This is done by wrapping innerSchema $ref's in an allOf in the case that a ref is present and has siblings.

Result:

The following code:

import * as t from 'io-ts';
import * as h from '@api-ts/io-ts-http';
/**
 * A simple route with type descriptions for references
 *
 * @operationId api.v1.test
 * @tag Test Routes
 */
export const route = h.httpRoute({
  path: '/foo',
  method: 'GET',
  request: h.httpRequest({}),
  response: {
    200: SimpleRouteResponse
  },
 });


 /**
  * Human readable description of the Simple Route Response
  * @title Human Readable Simple Route Response
 */
const SimpleRouteResponse = t.type({
  /** List of test refs */
  test: t.array(TestRef)
});

const TestRefBase = t.string;

const TestRef = TestRefBase;

Now results in:

  {
    openapi: '3.0.3',
    info: {
      title: 'Test',
      version: '1.0.0',
    },
    paths: {
      '/foo': {
        get: {
          summary: 'A simple route with type descriptions for references',
          operationId: 'api.v1.test',
          tags: ['Test Routes'],
          parameters: [],
          responses: {
            '200': {
              description: 'OK',
              content: {
                'application/json': {
                  schema: {
                    $ref: '#/components/schemas/SimpleRouteResponse',
                  },
                },
              },
            },
          },
        },
      },
    },
    components: {
      schemas: {
        SimpleRouteResponse: {
          description: 'Human readable description of the Simple Route Response',
          properties: {
            test: {
              type: 'array',
              items: {
+              allOf: [{ $ref: '#/components/schemas/TestRefBase' }],
-              $ref: '#/components/schemas/TestRefBase',
                description: 'List of test refs',
              },
            },
          },
          required: ['test'],
          title: 'Human Readable Simple Route Response',
          type: 'object',
        },
        TestRefBase: {
          title: 'TestRefBase',
          type: 'string',
        },
        TestRef: {
          allOf: [
            {
              title: 'TestRef',
            },
            {
              $ref: '#/components/schemas/TestRefBase',
            },
          ],
        },
      },
    },
  }

@starfy84 starfy84 force-pushed the dx-1580-no-ref-siblings branch from f11c59d to e5a1b81 Compare July 29, 2025 15:04
@starfy84 starfy84 self-assigned this Jul 29, 2025
@starfy84 starfy84 force-pushed the dx-1580-no-ref-siblings branch from e5a1b81 to 23a0df8 Compare July 29, 2025 15:12
@starfy84 starfy84 marked this pull request as ready for review July 29, 2025 15:15
@starfy84 starfy84 requested a review from a team as a code owner July 29, 2025 15:15
Fixes the no-$ref-siblings error seen in this [PR](BitGo/dev-portal#2508)

Ticket: DX-1580
@starfy84 starfy84 force-pushed the dx-1580-no-ref-siblings branch from 23a0df8 to cbe1c86 Compare July 29, 2025 15:47
Copy link
Contributor

@ericcrosson-bitgo ericcrosson-bitgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alley-oop'ing

Thanks @shenbenson and @starfy84!

@shenbenson shenbenson merged commit 8b3e259 into master Jul 29, 2025
6 checks passed
@shenbenson shenbenson deleted the dx-1580-no-ref-siblings branch July 29, 2025 20:15
Copy link

🎉 This PR is included in version @api-ts/[email protected] 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented Aug 1, 2025

🎉 This PR is included in version @api-ts/[email protected] 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Copy link

github-actions bot commented Aug 1, 2025

🎉 This PR is included in version @api-ts/[email protected] 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants