标签: swagger

如何让 Swagger+Swashbuckle 显示端点?

我正在尝试将 swagger+swashbuckle 添加到我的 ASP.NET Core 项目中。我可以启动并运行 Swagger UI,但它完全是空的。我尝试四处查看并在https://github.com/domaindrivendev/Swashbuckle/issues/1058发现了类似的问题。这让我认为路由可能是问题所在,所以我尝试为我的控制器提供一个使用[Route("testroute")]方法而不是类的显式路由。这使得我添加的路由端点毫无问题地显示出来。

由于向每个端点添加显式路由不是最佳选择,我做错了什么以及如何修复它以大摇大摆地显示我的所有端点?

我的初创公司集成了 swagger

    public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
                        .SetBasePath(env.ContentRootPath)
                        .AddJsonFile("appsettings.json", optional: true , reloadOnChange: true);

        Configuration = builder.Build();
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc().AddJsonOptions(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

        // Register the Swagger generator, defining one or …
Run Code Online (Sandbox Code Playgroud)

c# swagger swagger-ui swashbuckle asp.net-core

0
推荐指数
1
解决办法
3875
查看次数

Swagger 发送空的帖子请求

我刚刚为 laravel 5.1 (旧项目)设置了 swagger 我为我的项目编写了整个文档,但问题是当我去尝试一下!它发送空请求。当我用邮递员尝试完全相同的事情时,它的工作原理就像它应该的那样。

这是一个例子:

 /**
 * @SWG\Post(
 *     path="/api-routes/verify-report",
 *     consumes={"multipart/form-data"},
 *     description="Verify report",
 *     operationId="verifyReport",
 *     @SWG\Parameter(
 *         description="Application report id",
 *         format="int64",
 *         in="path",
 *         name="report_id",
 *         required=true,
 *         type="string"
 *     ),           
 *     produces={"application/json"},
 *     @SWG\Response(
 *         response="200",
 *         description="successful operation"
 *     ),
 *     summary="Verify report",
 *     tags={
 *         "Verify report"
 *     }
 * )
 * */
public function verifyReport() {

}
Run Code Online (Sandbox Code Playgroud)

我正在使用

"darkaonline/l5-swagger": "~3.0"
Run Code Online (Sandbox Code Playgroud)

php api laravel swagger

0
推荐指数
1
解决办法
1807
查看次数

为什么不在 REST API 版本控制中考虑模型?

对类似问题有一个答案,但对于示例来说过于具体,并且不能一般性地回答。

如果模型没有版本控制,任何人都可以告诉如何处理以下情况吗?

PUT /v1/users
username (string)
email (string) (required)
password (string) (required)
Run Code Online (Sandbox Code Playgroud)
POST /v2/users
username (string) (required)
email (string) required
password (string) (required)
Run Code Online (Sandbox Code Playgroud)

假设模型名称为UserModel,在 v1 版本中用户名是可选的,但在 V2 中是必需的。

如果我们使用像 ajv 这样的模式验证器,即使对于 v1 api 请求它也会失败,因为最新的规范/模型提到用户名是必填字段。

每个人都应该有充分的理由说模型不应该进行版本控制,但我可能明显遗漏了一些东西。在这种情况下,对模型进行版本控制更有意义,因为它不会轻易破坏向后兼容性。

versioning node.js express swagger ajv

0
推荐指数
1
解决办法
1343
查看次数

@Valid @RequestBody 无法验证输入错误的传入 Json

我想验证传入的 RequestBody。我的控制器 API 是,

\n\n
@RequestMapping(value = {\n        POSRequest.REQUEST_SEPARATOR + Request.UPDATE_URL,\n        method = RequestMethod.PUT,\n        produces = MediaType.APPLICATION_JSON_VALUE)\n@ApiOperation(value = "Update .\xe2\x80\x9d,\n        response = SuccessResponseDTO.class, ,\n        produces = "application/json", httpMethod = "PUT")\n@ApiResponses(value = {\n        @ApiResponse(code = 200, message = "OK",response = SuccessResponseDTO.class),\n        @ApiResponse(code = 401, message = "Unauthorized",response =ErrorResponseDTO.class),\n        @ApiResponse(code = 403, message = "Forbidden",response = ErrorResponseDTO.class),\n        @ApiResponse(code = 404, message = "Not Found",response = ErrorResponseDTO.class)\n})\npublic @ResponseBody\nSuccessResponseDTO update(HttpServletRequest request,\n                             @ApiParam(required = true, type = "String", value = " ") @RequestParam(value = \xe2\x80\x9cid\xe2\x80\x9d, …
Run Code Online (Sandbox Code Playgroud)

java spring swagger spring-boot

0
推荐指数
1
解决办法
1885
查看次数

使用 swagger 和express 没有出现 API 端点文档

我正在使用 Swagger 编写 API 文档。我已经在我的 Express 项目上成功设置了 Swagger,但是只要端点位于 app.js 文件之外的另一个路由文件上,端点的文档就不会显示

下面是我的 App.js 文件

const express = require('express')
const port = process.env.PORT
const userRouter = require('./routers/user')
require('./db/db')

const app = express()
const swaggerJsDoc = require("swagger-jsdoc");
const swaggerUi = require("swagger-ui-express");

// Extended: https://swagger.io/specification/#infoObject
const swaggerOptions = {
    swaggerDefinition: {
        info: {
            title: "MY API TITLE",
            description: "API Documentation",
            contact: {
                name: "Cali"
            },
            servers: ["http://localhost:3000"]
        }
    },
    // ['.routes/*.js']
    apis: ["app.js"]
};

const swaggerDocs = swaggerJsDoc(swaggerOptions);
app.use("/api/doc", swaggerUi.serve, swaggerUi.setup(swaggerDocs, {explorer: true}));

app.use(express.json()) …
Run Code Online (Sandbox Code Playgroud)

node.js express swagger swagger-ui

0
推荐指数
1
解决办法
2364
查看次数

如何将 openapi.yaml 规范公开到其余的 Spring Boot 中

我已经在外部安装了 swagger-ui,我只想将 swagger-ui (开源)实例从 openapi.yaml 连接到 localhost:8000/doc/api (.yaml) 。有什么想法吗?PS:我尝试使用

 @Bean
public OpenAPI customOpenAPI() {
    return new OpenAPI()
            .components(new Components().addSecuritySchemes("basicScheme",
                    new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
            .info(new Info().title("SpringShop API").version("0.1")
                    .license(new License().name("Apache 2.0").url("http://springdoc.org")))
            .externalDocs(new ExternalDocumentation()
                    .url("restapi/doc/openapi.yaml"));
}

    @Bean
    public SpringDocConfiguration springDocConfiguration(){
        return new SpringDocConfiguration();
    }
    @Bean
    public SpringDocConfigProperties springDocConfigProperties() {
        return new SpringDocConfigProperties();
    }
Run Code Online (Sandbox Code Playgroud)

但我没有发现任何有用的东西。谢谢。

    application.properties:
    springdoc.api-docs.enabled=false
springdoc.swagger-ui.url=openapi.yaml
springdoc.swagger-ui.path=/doc/api/ui.html

dependecies:
<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.4.4</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

spring swagger openapi springdoc

0
推荐指数
1
解决办法
1万
查看次数

如何从任何前端应用程序调用nestjs微服务?

我制作了一个 NestJS 微服务包和单独的 NestJS 客户端应用程序来联系微服务。下面给出的是客户端应用程序中使用的代码。在微服务中使用的方法是@messagePattern,并且它是函数式的。我的问题是前端应用程序如何直接联系微服务而不通过客户端以及如何在微服务中设置 swagger 或直接从邮递员测试它?

import { BadRequestException, Injectable, UnauthorizedException } from '@nestjs/common';
import { ClientProxy, ClientProxyFactory, Transport } from '@nestjs/microservices';
import { errorResponse, goodResponse } from 'src/helpers/response.helper';
import { AddContractDTO } from './contract.dto';

@Injectable()

export class ContractService {
    private client: ClientProxy; 

    constructor() {
        this.client = ClientProxyFactory.create({
          transport: Transport.TCP,
          options: {
            host: '127.0.0.1',
            port: 3011,
          },
        });
      }

    public async addContract(data: AddContractDTO) {
            const res = await this.client.send<any,any>('contract/addContract', data).toPromise();
            console.log(res);
            if(!res.success){
              throw new BadRequestException(res)
            }
            return goodResponse(res.data.data,'Contract created'); …
Run Code Online (Sandbox Code Playgroud)

javascript node.js swagger nestjs nestjs-swagger

0
推荐指数
1
解决办法
2217
查看次数

NestJS - Swagger JSON 导出

我有 Swagger,效果很好。但我找不到将路由导出为 JSON 的方法。我记得这样做过,只需在浏览器中访问一个 URL,但现在我不记得了。

我的招摇设置是这样的:

const swaggerOptions = new DocumentBuilder()
    .setTitle('Some API Docs')
    .setDescription('Some API description')
    .setVersion('1.0')
    .build();

  const swaggerDocument = SwaggerModule.createDocument(app, swaggerOptions);
  SwaggerModule.setup('docs', app, swaggerDocument);
Run Code Online (Sandbox Code Playgroud)

我可以使用以下命令访问 Swagger UI: localhost:3000/docs

我已阅读官方文档,他们提到使用:

  • http://localhost:3000/api/json 或 http://localhost:3000/api-json

另外,我看了SO,有这个线程

不幸的是,这些都不适用于我的情况。

获取 JSON 格式文档的 URL 是什么?

swagger swagger-ui nestjs

0
推荐指数
1
解决办法
3895
查看次数

Swagger 中鉴别器内的映射有什么作用?

文档中的解释对我来说不清楚。我的 api 文档渲染后没有看到任何差异。
视觉上有什么区别?从逻辑上讲,映射是做什么的?例如

MySchema:
  oneOf:
    - $ref: '#/componets/schemas/SubSchema1'
    - $ref: '#/componets/schemas/SubSchema2'
  discriminator:
    propertyName: some_property:
    mapping:
      TypeA: '#/componets/schemas/SubSchema1'
      TypeB: '#/componets/schemas/SubSchema2'
Run Code Online (Sandbox Code Playgroud)

documentation rest swagger openapi

0
推荐指数
1
解决办法
2437
查看次数

在 DRF 中使用 @extend_schema 而非 @actoin 时出现问题

您好,我的代码中有一个drf_spectaulous库的@extend_schema我需要在@action上使用它来自定义OpenAPI中的详细信息,但我收到这样的错误

Internal Server Error: /api/schema/
Traceback (most recent call last):
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line 482, in thread_handler
    raise exc_info[1]
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/django/core/handlers/exception.py", line 38, in inner
    response = await get_response(request)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/django/core/handlers/base.py", line 233, in _get_response_async
    response = await wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line 444, in __call__
    ret = await asyncio.wait_for(future, timeout=None)
  File "/usr/lib/python3.9/asyncio/tasks.py", line 442, in wait_for
    return await fut
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/mnt/62EE2B18EE2AE44F/NEW/django/webserver/django-env/lib/python3.9/site-packages/asgiref/sync.py", line …
Run Code Online (Sandbox Code Playgroud)

python django swagger openapi drf-spectacular

0
推荐指数
1
解决办法
1128
查看次数

NestJS Swagger OpenAPI CLI 插件 - 排除某些属性

我喜欢 CLI 插件如何让我不必在所有内容上编写 @ApiProperty()。

然而,在我的一些实体中,虽然我希望大多数属性是 @ApiProperty(),但我希望有些属性不是。

我在文档中找不到任何允许我从自动接收 @ApiProperty() 中排除特定字段的内容。

有人知道怎么做吗?

swagger nestjs

0
推荐指数
1
解决办法
2029
查看次数