Fastify openapi 3 创建始终必填字段

问题描述 投票:0回答:1

我使用@fastify/swagger和@fastify/swagger-ui, 我的配置

import fastifySwagger from '@fastify/swagger';
import fastifySwaggerUi from '@fastify/swagger-ui';
import { FastifyInstance } from 'fastify';
import fp from 'fastify-plugin';

const swagger = async (fastify: FastifyInstance) => {
  await fastify.register(fastifySwagger, {
    mode: 'dynamic',
    openapi: {
      openapi: '3.0.3',
      info: {
        title: 'openapi',
        version: '0.1.0'
      }
    }
  });

  await fastify.register(fastifySwaggerUi, {
    routePrefix: '/openapi',
    uiConfig: {
      deepLinking: true
    },
    uiHooks: {
      onRequest: function (request, reply, next) {
        next();
      },
      preHandler: function (request, reply, next) {
        next();
      }
    },
    staticCSP: true,
    transformStaticCSP: (header) => header,
    transformSpecification: (swaggerObject, request, reply) => {
      return swaggerObject;
    },
    transformSpecificationClone: true
  });
};

export default fp(swagger);

我的路线是这样的

export const articleRouter = async (fastify: FastifyInstance) => {
  fastify.get(
    '/list',
    {
      schema: {
        tags: ['article'],
        summary: 'getting artilce list',
        description: 'description in routes',
        params: {
          type: 'object',
          description: 'some params',
          properties: {
            limit: {
              type: 'number',
              description: 'limit articles'
            },
            sort: {
              type: 'string',
              description: 'asc or desc'
            }
          },
          required: ['sort']
        },
      }
    },
    async (req, resp) => {
      const articles = await articleService.findArticles();
      resp.send(articles);
    }
  );
};

招摇截图

enter image description here

一切正常,但始终需要字段“限制”。为什么?

请帮助我。

我正在使用配置和路由中的所有属性,但没有人帮助我。

@fastify/swagger @fastify/swagger-ui

node.js swagger openapi fastify
1个回答
0
投票

这个问题你找到解决办法了吗?

© www.soinside.com 2019 - 2024. All rights reserved.