目前有一个项目,其中使用asp.net中的swashbuckle设置swagger。我想合并新的 Swagger UI https://swagger.io/swagger-ui/。有没有一种简单的方法可以做到这一点?
谢谢
我正在编写一个 swagger 合约,但我的数据模型是使用 JSONSchemas 定义的。
\n\n创建模型后,我正在 swagger UI 中测试它们。现在我在使用“oneOf”作为参考时遇到问题。如下...
\n\n...\n "socio":{\n "type":{\n "oneOf":[\n {\n "properties":{\n "pessoaFisica":{\n //"pessoaFisica": "object",\n "$ref":"http://soa-mds/XXXXXX/apps/SOA/JSONSchemas/Corporativo/pessoaFisica.json"\n },\n "pessoaJuridica":{ \n //"pessoaJuridica": "object",\n "$ref":"http://soa-mds/dataprev.gov.br/apps/SOA/JSONSchemas/Corporativo/pessoaJuridica.json"\n },\n "estrangeiro":{\n //"estrangeiro": "object",\n "$ref":"http://soa-mds/XXXXXX/apps/SOA/JSONSchemas/Corporativo/estrangeiro.json"\n }\n }\n } \n ] \n }\n } \n },\n....\nRun Code Online (Sandbox Code Playgroud)\n\n经过研究,我没有找到\xc2\xb4t 找到将 oneOF 与 $ref 一起使用的正确方法。
\n\n谁能帮我?
\n\n\n我在 SpringBoot 中有一个 POST 操作@RestController,它接受查询参数和请求正文:
@RequestMapping(path = "/benchmark", method = POST)
public String startBenchmark(@QueryParam("numMessages") int numMessages, @RequestBody String body) {
Run Code Online (Sandbox Code Playgroud)
Swagger UI 会将“numMessages”呈现为参数类型“body”。有办法纠正这个问题吗?
我在我们的应用程序中使用 hapi-swagger,其中一个 API 尝试使用自定义标头,但是当我使用自定义标头调用该 API 时出现以下错误
{
"statusCode": 400,
"error": "Bad Request",
"message": "Invalid request headers input"
}
Run Code Online (Sandbox Code Playgroud)
在我使用带有验证器的标头的 API 下方。
{
method: 'POST',
path: '/v1/testapi',
config: {
description: 'Greet user',
notes: ['Use to greet a user'],
tags: ['api'],
handler: function ( request, h ) {
console.log('sending response...');
return h.response('OK');
},
validate: {
headers: {
name: Joi.string().required()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我们正在使用的版本。
"hapi": "17.2.2",
"hapi-swagger": "9.1.1",
"joi": "13.1.2",
我已经定义了我的 swagger 定义,如下所示:
const swaggerDefinition = {
info: {
title: 'Node Swagger API',
version: '1.0.0',
description: 'Describing a RESTful API with Swagger',
},
host: 'localhost:8000',
basePath: '/',
securityDefinitions: {
JWT: {
type: 'apiKey',
description: 'JWT authorization of an API',
name: 'Authorization',
in: 'header',
},
},
};
Run Code Online (Sandbox Code Playgroud)
但是我无法在 swagger UI 甚至 swagger.json 中获得任何授权
info: {
title: "Node Swagger API",
version: "1.0.0",
description: "Describing a RESTful API with Swagger"
},
host: "localhost:8000",
basePath: "/",
securityDefinitions: { },
swagger: "2.0",
Run Code Online (Sandbox Code Playgroud)
securitydefinitions 块在 swagger.json …
在环回的swagger规范中指定日期和时间的数据类型时,我遇到警告/错误。下面是我的环回user.json文件
"properties": {
"schedule": {
"type": "dateTime",
"required": true
},
}
Run Code Online (Sandbox Code Playgroud)
Swagger:跳过未知类型“dateTime”
请问我可以知道swagger中日期和时间的相关数据类型是什么吗?
我有一个带有身份验证服务的简单 REST 应用程序。我试图向它添加 swagger 和 swagger-ui,但我只能在/v2/api-docs. 在swagger-ui.html我只看到端点组,但我无法扩展任何列表。
在 chrome 调试中,我看到:
加载资源失败:服务器响应状态为 401()
未捕获的类型错误:无法读取未定义的属性“indexOf”
并在带有服务器的终端上:
错误 10020 --- [nio-5001-exec-3] ctrapJwtAuthenticationEntryPoint:响应未经授权的错误。消息 - 访问此资源需要完全身份验证
看起来我的配置文件丢失了一些东西,我尝试了一些在网上找到的解决方案,但仍然没有任何效果。
这是我的代码:
绒球
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
控制器
@RestController
@PreAuthorize("hasRole('USER')")
@RequestMapping(path = "restaurant")
@Api(value="restaurant", description="Example operations for restaurants")
public class RestaurantController {
// endpoints
}
Run Code Online (Sandbox Code Playgroud)
招摇豆
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.tablebooker.restaurantservice.restaurant"))
.paths(PathSelectors.any())
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
安全配置
@Configuration
@EnableWebSecurity …Run Code Online (Sandbox Code Playgroud) 我在 Spring-boot 5 中使用 OpenAPI 3.0,因此没有配置 YAML。我有一个包含客户端标识 ID 的标头(这不是身份验证标头)。我想让它成为一个强制性的标题参数。在 OpenAPI 配置下方添加
@Configuration
public class OpenAPIConfiguration {
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
.components(new Components()
.addParameters("myCustomHeader", new Parameter().in("header").schema(new StringSchema()).required(true).description("myCustomHeader").name("myCustomHeader")))
.info(new Info()
.title("My Rest Application")
.version("1.2.26"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,swagger UI 不会在任何 API 中显示所需的参数。有人可以帮助我做错什么吗?
我有一个简单的 nodeJS 项目,想在其中添加 swagger 。我需要 swaggerUI 和 swaggerJSDoc
这是我的 app.js 文件。
// requires
const path = require("path");
const express = require("express");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
const postsRoutes = require("./routes/posts/posts");
const userRoutes = require("./routes/auth/user");
const swaggerUi = require("swagger-ui-express");
const swaggerJSDoc = require("swagger-jsdoc");
// https://swagger.io/specification/v2/
const swaggerOptions = {
swaggerDefinition: {
info: {
title: "Post API",
description: "This is a sample Post API",
contact: {
name: "Test ",
url: "http://www.swagger.io/support",
email: "test@gmail.com"
},
servers: ["http://localhost:3850/"]
}
},
swagger: …Run Code Online (Sandbox Code Playgroud) 我在 cuba 平台上创建了一个自定义的 rest 控制器,并按照文档https://doc.cuba-platform.com/restapi-7.1/#rest_api_v2_custom_auth 中的说明进行操作
我的“rest-dispatcher-spring.xml”
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<context:component-scan base-package="com.company.test.web.resource"/>
</beans>
Run Code Online (Sandbox Code Playgroud)
将“rest-dispatcher-spring.xml”添加到“web-app.properties”
cuba.restSpringContextConfig = +com/company/test/rest-dispatcher-spring.xml
Run Code Online (Sandbox Code Playgroud)
我的控制器看起来像这样
package com.company.test.web.resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
@RestController
@RequestMapping("/test")
public class TestResource {
@RequestMapping(value = "/testAPI", method = RequestMethod.GET, produces = APPLICATION_JSON_VALUE)
public ResponseEntity testAPI() {
return new ResponseEntity<>(HttpStatus.OK);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以从 Postman 调用 API,但该 API 未使用 URL 在 Swagger-ui 中显示 …
swagger-ui ×10
swagger ×7
node.js ×4
java ×2
spring ×2
spring-boot ×2
swagger-2.0 ×2
asp.net ×1
hapi-swagger ×1
hapijs ×1
jsonschema ×1
jwt ×1
loopback ×1
loopbackjs ×1
openapi ×1
swagger-3.0 ×1
swashbuckle ×1