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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please update example folder for typescript #694

Closed
2 tasks done
giabao1008 opened this issue Nov 23, 2022 · 17 comments
Closed
2 tasks done

Please update example folder for typescript #694

giabao1008 opened this issue Nov 23, 2022 · 17 comments
Labels
good first issue Good for newcomers

Comments

@giabao1008
Copy link

giabao1008 commented Nov 23, 2022

Prerequisites

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

馃殌 Feature Proposal

currently im working with fastify swagger and typescript, follow as example folder.
but when use exposeRoute option, it will prompt error

Motivation

No response

Example

.register(swagger, {
    swagger: {
      info: {
        title: 'Test swagger',
        description: 'testing the fastify swagger api',
        version: '0.1.0',
      },
      host: 'localhost:3000',
      schemes: ['http'],
      consumes: ['application/json'],
      produces: ['application/json'],
      swagger: '2.0',
    },
    exposeRoute: true,
    // routePrefix: '/swagger-docs',
  })
@Uzlopak
Copy link
Contributor

Uzlopak commented Nov 23, 2022

Can provide a PR please?

@giabao1008
Copy link
Author

i cant, please help

@climba03003
Copy link
Member

Remove routePrefix: '/swagger-docs', as you show in your example.

@climba03003 climba03003 added the good first issue Good for newcomers label Nov 23, 2022
@giabao1008
Copy link
Author

  .register(swagger, {
    swagger: {
      info: {
        title: 'Test swagger',
        description: 'testing the fastify swagger api',
        version: '0.1.0',
      },
      basePath: '/',
      consumes: ['application/json'],
      host: 'localhost',
      swagger: '2.0',
    },
    // exposeRoute: true,
    // routePrefix: '/swagger-docs',
  });`` 
yes, i removed but, seem the path /documentation not work

@Uzlopak
Copy link
Contributor

Uzlopak commented Nov 23, 2022

Please read migration.md

@giabao1008
Copy link
Author

giabao1008 commented Nov 24, 2022

one more question, i ve connected swagger to fastify with swagger ui, define a router with schema, but in swagger doc, it not auto generated

this is my config

await fastify.register(fastifySwagger, {
    swagger: {
      info: {
        title: ' Swagger',
        description: 'Testing swagger API',
        version: '0.1.0',
      },
      host: `${HOST}:${PORT}`,
      schemes: ['http'],
      consumes: ['application/json'],
      produces: ['application/json'],
      swagger: '2.0',
    },
  });
  await fastify.register(fastifySwaggerUi, {
    routePrefix: '/v1/example/docs',
    initOAuth: {},
    uiConfig: {
      docExpansion: 'full',
      deepLinking: false,
    },
    uiHooks: {
      onRequest: function (request, reply, next) {
        next();
      },
      preHandler: function (request, reply, next) {
        next();
      },
    },
    staticCSP: true,
    transformStaticCSP: (header) => header,
  });

and router

fastify.get(
    '/',
    {
      schema: {
        description: 'This is an endpoint for fetching all users',
        tags: ['users'],
        response: {
          200: {
            description: 'Success Response',
            type: 'array',
            items: {
              type: 'object',
              properties: {
                id: { type: 'number' },
                name: { type: 'string' },
                age: { type: 'number' },
                createdAt: { type: 'string' },
                updatedAt: { type: 'string' },
              },
            },
          },
        },
      },
    },
    async function (request: FastifyRequest, reply: FastifyReply) {
      return fastify.exampleService.getAll();
    }
  );

please advise me

@kibertoad
Copy link
Member

kibertoad commented Nov 24, 2022

you need both fastify-swagger and fastify-swagger-ui

@giabao1008
Copy link
Author

you need both fastify-swagger and fastify-swagger-ui

yes, i have

@kibertoad
Copy link
Member

Please share full config then

@giabao1008
Copy link
Author

giabao1008 commented Nov 24, 2022

Please share full config then

please see above, it's my all configs, or what else ?

@giabao1008
Copy link
Author

Please share full config then

please see above

@borjatur
Copy link

here you have a fully working example https://github.com/borjatur/clean-architecture-fastify-mongodb/blob/master/src/infrastructure/http/plugins/docs.ts

hope that can help you

@kp198
Copy link

kp198 commented Jun 3, 2023

I tried the same and was unable to generate docs automatically for my APIs.
Any update here?

@mcollina
Copy link
Member

Everything is working fine for me, so it would be useful to have a reproduction.

@alexey-sh
Copy link

I copy-pasted the docs.ts file and even didn't get any page
image
image

@casantosmu
Copy link
Contributor

I copied and pasted examples from the documentation, and everything is functioning well: GitHub Link.

Similarly, I replicated the contents of the docs.ts file from @borjatur's example, and it is also working smoothly: GitHub Link.

@Uzlopak
Copy link
Contributor

Uzlopak commented Nov 26, 2023

If there are problems then please open a new issue.

@Uzlopak Uzlopak closed this as not planned Won't fix, can't repro, duplicate, stale Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

9 participants