Skip to content
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

feat: support for refs #33

Open
simonireilly opened this issue Jan 29, 2022 · 0 comments
Open

feat: support for refs #33

simonireilly opened this issue Jan 29, 2022 · 0 comments

Comments

@simonireilly
Copy link
Owner

simonireilly commented Jan 29, 2022

Compeller needs to support refs, because refs are used heavily in OpenAPI specifications which become very large.

The specification itself will use refs to point at other declarations.

MVP

For an MVP, pointing at:

components.schema

Would be enough, in my opinion, to allow users to dry out their schema's.

Example

import { VersionSchema } from './schemas/version.schema';

export const OpenAPISpecification = {
  info: {
    title: 'New API generated with compeller',
    version: '1.0.0',
  },
  openapi: '3.1.0',
  paths: {
    'v1/version': {
      get: {
        responses: {
          '200': {
            description: 'Get the current API version',
            content: {
              'application/json': {
                schema: {
                  $ref: '#/components/schemas/Version',
                },
              },
            },
          },
        },
      },
    },
  },
  components: {
    schemas: {
      Version: {
        type: 'object',
        required: ['version'],
        additionalProperties: false,
        properties: {
          version: {
            type: 'string',
          },
        },
      } as const,
    },
  },
};

Research

This tool supports refs, and is suggested reading: https://github.com/Q42/openapi-typescript-validator

In principle we would be looking for the schema key to be ref and if so we would want to find the ref in the OpenAPI object, and use the ref type as the schema type.

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

No branches or pull requests

1 participant