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

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

Closed
velopert opened this issue Aug 19, 2020 · 12 comments · Fixed by #459
Closed
Assignees
Labels
semver-minor Issue or PR that should land as semver minor

Comments

@velopert
Copy link

🐛 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
@fox1t
Copy link
Member

fox1t commented Aug 20, 2020

Would you mind to send a PR to address this issue?

@velopert
Copy link
Author

I tried to fix the issue, however, my solution breaks the test code 😂.
I will send a PR when I get to fix the issue properly.

Thanks!

@ghost
Copy link

ghost commented Sep 4, 2020

@velopert Are you making progress? I would be interested in this and I'd be willing to give a hand.

@ghost
Copy link

ghost commented Sep 4, 2020

Upon further looking, I saw that this is caused by https://github.com/Eomm/json-schema-resolver (the example in the readme demonstrates this)

I think this issue should be closed and another one opened there.

@velopert @fox1t thoughts?

@IOsonoTAN
Copy link

Upon further looking, I saw that this is caused by https://github.com/Eomm/json-schema-resolver (the example in the readme demonstrates this)

I think this issue should be closed and another one opened there.

@velopert @fox1t thoughts?

I have already created PR there Eomm/json-schema-resolver#4

@Eomm
Copy link
Member

Eomm commented Oct 21, 2020

As reviewed in the PR the issuer is more complex, I will support @IOsonoTAN to get a good solution.

I agree that we should cover this use case that should be 99% of the cases (not a fact, just an opinion)

@yantrab
Copy link

yantrab commented Dec 31, 2020

any news with this issue? when @IOsonoTAN PR's will be merged?

@CloudPower97
Copy link

As a temporary solution I managed to get everything to work as intended by forking fastify-swagger using the patched json-schema-resolver package, including the needed option showSchemaId set to true in fastify-swagger code itself.

For anyone who is not willing to wait for @IOsonoTAN PR to get merged by json-schema-resolver mantainer you can just

npm install git+https://github.com/CloudPower97/fastify-swagger.git\#feature/schema-id

@vglkannan
Copy link

Any news with this issue?

@mcollina
Copy link
Member

cc @Eomm

@Eomm
Copy link
Member

Eomm commented Jun 24, 2021

I know it but I didn't get the chance to work on it: it is on my todo list but I have other things to push forward before this one 😞

@Eomm Eomm added the semver-minor Issue or PR that should land as semver minor label Aug 16, 2021
@Eomm Eomm self-assigned this Aug 16, 2021
@Eomm
Copy link
Member

Eomm commented Aug 26, 2021

Closing as superseded by #337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor Issue or PR that should land as semver minor
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants