Skip to content

Schema added using fastify.addSchema is resulted as "def-#" in Swagger Models section #286

@velopert

Description

@velopert

🐛 Bug Report

When I add schema by fastify.addSchema, the Model name is shown as def-# where # is index.

image

To Reproduce

Steps to reproduce the behavior:

const fastify = require('fastify')();

fastify.register(require('fastify-swagger'), {
  swagger: {
    info: {
      title: 'Test swagger',
      description: 'testing the fastify swagger api',
      version: '0.1.0',
    },
    host: 'localhost',
    schemes: ['http'],
    consumes: ['application/json'],
    produces: ['application/json'],
  },
  exposeRoute: true,
});

fastify.addSchema({
  $id: 'greetings',
  type: 'object',
  properties: {
    hello: { type: 'string' },
  },
});

fastify.put(
  '/some-route/:id',
  {
    schema: {
      description: 'post some data',
      tags: ['user'],
      summary: 'qwerty',
      params: {
        type: 'object',
        properties: {
          id: {
            type: 'string',
            description: 'user id',
          },
        },
      },
      response: {
        201: {
          description: 'Succesful response',
          type: 'object',
          properties: {
            greetings: { $ref: 'greetings#' },
          },
        },
      },
    },
  },
  (req, reply) => {}
);

fastify.listen(5000, (err) => {
  if (err) throw err;
  console.log('listening');
});

Expected behavior

The model names should be shown properly like following screenshot:

image

Your Environment

  • node version: v12.15.0
  • fastify version: ^3.2.1
  • os: Mac
  • "fastify-swagger": "^3.3.0"
  • any other relevant information

Metadata

Metadata

Assignees

Labels

semver-minorIssue or PR that should land as semver minor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions