Skip to content

Support A Way To Generate $ref's #240

@cmcnicholas

Description

@cmcnicholas

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

I would like to define my typebox schema and have it so fastify both understands this schema and this library can produce valid openapi json schema.

A key requirement to clean openapi json schema is the ability to define our models and reference them throughout the specification.

For example I have:

export const RefreshResponseApiModelSchema = Type.Object(
  {
    accessToken: Type.String(),
    refreshToken: Type.String(),
  },
  { $id: 'RefreshResponseApiModel' },
);

export type RefreshResponseApiModel = Static<typeof RefreshResponseApiModelSchema>;

and have tried to register these with fastify during initialisation:

export function addSchemas(app: FastifyInstance) {
  // other schema
  app.addSchema(RefreshResponseApiModelSchema);
}

They add correctly but the resulting documentation is not correct, I can see the schema is added as below and never referenced by the methods that use these schema:

      "def-3": {
        "type": "object",
        "properties": {
          "accessToken": {
            "type": "string"
          },
          "refreshToken": {
            "type": "string"
          }
        },
        "required": [
          "accessToken",
          "refreshToken"
        ],
        "title": "RefreshResponseApiModel"
      }

I've read through the docs and tickets but can't see this expressed anywhere.

Motivation

To have an openapi documentation with generated schema that can be used by other tools e.g. codegen to generate correct model types with proper naming.

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions