标签: swagger

如何使用Swashbuckle在WebAPI上省略Swagger文档中的方法

我有一个C#ASP.NET WebAPI应用程序,其中包含使用Swashbuckle自动生成的API文档.我希望能够从文档中省略某些方法,但我似乎无法弄清楚如何告诉Swagger不要将它们包含在Swagger UI输出中.

我觉得它与添加模型或模式过滤器有关,但它不明显该做什么,文档似乎只提供了如何修改方法的输出的示例,而不是从输出中完全删除它.

提前致谢.

.net c# asp.net swagger

110
推荐指数
9
解决办法
5万
查看次数

如何在Swagger规范(swagger.json)中表示"授权:承载<令牌>"

我试图传达认证/安全方案需要设置标题,如下所示:

Authorization: Bearer <token>
Run Code Online (Sandbox Code Playgroud)

这是我基于swagger文档的内容:

securityDefinitions:
  APIKey:
    type: apiKey
    name: Authorization
    in: header
security:
  - APIKey: []
Run Code Online (Sandbox Code Playgroud)

提前致谢!

swagger swagger-2.0 swagger-editor

94
推荐指数
4
解决办法
11万
查看次数

在Spring MVC应用程序中实现Swagger的"简单"方法

我有一个用简单的Spring编写的ReSTFul API(没有Spring Boot,没有花哨的东西!).我需要实现Swagger.到目前为止,互联网上的每一页都只让我感到疯狂,因为令人困惑的配置和臃肿的代码,我根本找不到便携式.

有没有人有一个示例项目(或一组详细步骤)可以帮助我实现这一目标?特别是,我正在寻找一个使用swagger-springmvc的好样本.我知道它有'样本',但充其量,深奥的代码令人沮丧.

我必须澄清一点,我不是在寻找"为什么Swagger是最好的".我没有使用(并且我目前的任务不会使用)Spring Boot等.

spring spring-mvc swagger

82
推荐指数
2
解决办法
8万
查看次数

摇摇欲坠的继承与构成

在我的"简化"API中,所有响应都是从基础"响应"类派生(继承)的.响应类填充元数据的标头和包含用户请求的核心数据的主体组成.响应(在JSON中)的布局使得所有元数据都在第一个"层"上,而主体是一个称为"body"的单个属性,因此

response
|--metadata attribute 1 (string/int/object)
|--metadata attribute 2 (string/int/object)
|--body (object)
    |--body attribute 1 (string/int/object)
    |--body attribute 2 (string/int/object)
Run Code Online (Sandbox Code Playgroud)

我试图使用以下JSON在swagger中定义这种关系:

{
    ...
    "definitions": {
        "response": {
            "allOf": [
                {
                    "$ref": "#/definitions/response_header"
                },
                {
                    "properties": {
                        "body": {
                            "description": "The body of the response (not metadata)",
                            "schema": {
                                "$ref": "#/definitions/response_body"
                            }
                        }
                    }
                }
            ]
        },
        "response_header": {
            "type": "object",
            "required": [
                "result"
            ],
            "properties": {
                "result": {
                    "type": "string",
                    "description": "value of 'success', for a …
Run Code Online (Sandbox Code Playgroud)

swagger

74
推荐指数
3
解决办法
6万
查看次数

将Swagger规范JSON转换为HTML文档

对于用PHP编写一些REST API的,我被要求创建扬鞭的文件,因为我不知道的添加注解这些现有的API和创建这样的文件没有简单的方法,我用这个编辑器生成一些现在.

我保存了使用该编辑器创建的JSON和YAML文件,现在我需要创建最终的交互式Swagger文档(这个声明可能听起来很幼稚和模糊).

有人可以告诉我如何将Swagger JSON规范文件转换为实际的Swagger文档吗?

我在Windows平台上,对Ant/Maven一无所知.

yaml swagger swagger-php

73
推荐指数
8
解决办法
10万
查看次数

Swagger/OpenAPI - 使用$ ref传递可重用的已定义参数

假设我有一个类似的参数limit.这个地方到处都是用的,如果我需要更新它,就必须在任何地方进行更改:

parameters:
    - name: limit
      in: query
      description: Limits the number of returned results
      required: false
      type: number
      format: int32
Run Code Online (Sandbox Code Playgroud)

我可以使用$ ref在别处定义它并使其可重用吗?我遇到了这张票,暗示有人想改变或改进功能,但我不知道它是否已经存在于今天?

swagger swagger-2.0 openapi

72
推荐指数
2
解决办法
4万
查看次数

如何从Swagger API声明生成JSON-Schema

我使用Swagger v 1.2获得服务的Swagger API声明

我对Swagger的原始感觉是,它非常接近JSON Schema(草案3和最近草案4),并且为请求和响应对象生成JSON Schema相对容易.

然而,虽然Swagger的一部分重用了JSON Schema结构,但事实证明,它只使用了功能的子集,并且它还在模型中引入了它自己的继承(使用subTypesdiscriminator).

问题:是否有任何现有项目或代码片段可以从Swagger API声明生成可用的JSON模式

最佳JSON Schema Draft 4并使用Python(但我很乐意找到任何东西).

jsonschema swagger

67
推荐指数
3
解决办法
6万
查看次数

Springfox 3.0.0 无法与 Spring Boot 2.6.0 一起使用

Springfox 3.0.0 无法与 Spring Boot 2.6.0 一起使用,升级后出现以下错误

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:54)
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155)
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123)
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
    at com.enkindle.AntivirusApplication.main(AntivirusApplication.java:16)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
    at springfox.documentation.spring.web.WebMvcPatternsRequestConditionWrapper.getPatterns(WebMvcPatternsRequestConditionWrapper.java:56)
    at springfox.documentation.RequestHandler.sortedPaths(RequestHandler.java:113)
    at …
Run Code Online (Sandbox Code Playgroud)

java swagger spring-boot springfox spring-boot-2.6.0

66
推荐指数
5
解决办法
10万
查看次数

如何配置Spring Security以允许无需身份验证即可访问Swagger URL

我的项目有Spring Security.主要问题:无法访问http:// localhost:8080/api/v2/api-docs中的 swagger URL .它表示缺少或无效的授权标头.

浏览器窗口的屏幕截图 My pom.xml包含以下条目

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.4.0</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.4.0</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

SwaggerConfig:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2).select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(apiInfo());
}

private ApiInfo apiInfo() {
    ApiInfo apiInfo = new ApiInfo("My REST API", "Some custom description of API.", "API TOS", "Terms of service", "myeaddress@company.com", "License of API", "API license URL");
    return apiInfo;
}
Run Code Online (Sandbox Code Playgroud)

AppConfig的:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.musigma.esp2" })
@Import(SwaggerConfig.class) …
Run Code Online (Sandbox Code Playgroud)

spring-mvc swagger swagger-ui swagger-2.0 springfox

65
推荐指数
8
解决办法
8万
查看次数

如何将swagger apis导出到邮递员

最近我写了RESTful API中与用SpringMVC和招摇的UI(V2).今天,我只注意到按钮导入的postman.And我点击它上面,我刚才看到的评论" 导入邮差收集,环境,数据转储,卷曲命令,或RAML/WADL/Swagger(v1/v2)/ Runscope文件. " 在此输入图像描述

起初我已经搞砸了,但没有答案满足我的情况.

所以我的问题是如何创建邮递员需要的文件.顺便说一句,我不熟悉招摇.

swagger postman

60
推荐指数
3
解决办法
5万
查看次数