我想知道如何以昂首阔步的方式记录枚举.
根据JavaDoc
dataType.有关支持的数据类型,请参阅文档.如果数据类型是自定义对象,请设置其名称,或者不设置任何名称.在枚举的情况下,使用'string'和allowableValues作为枚举常量.
但我没有找到一些好的Java示例如何真正使用它,规范在这里.
package betlista.tests.swagger;
import betlista.tests.swagger.model.Input;
import betlista.tests.swagger.model.Output;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
@Api(value = "first", position = 1)
public class RestServiceFirst {
@ApiOperation(value = "foo1 operation", httpMethod = "POST", position = 1, nickname = "foo")
public void foo1(Input input) {
}
@ApiOperation(value = "bar1 operation", response = Output.class, httpMethod = "GET", position = 2, nickname = "bar")
public Output bar1() {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
package betlista.tests.swagger;
import betlista.tests.swagger.model.Input;
import betlista.tests.swagger.model.Output;
import …
Run Code Online (Sandbox Code Playgroud) 我想为现有的一组RESTful API构建Swagger文档.我有以下要求:
到目前为止使用上面的插件我能够实现第1点.所以对于现有的REST方法:
/**
* <p>
* Gets the {@link DisplayPreferenceModel} with the name as provided in the parameter. The preference with the given name defined at the tenant or master level is returned.
* This API gives us the preference if it is eligible for unauthorized access If it is not eligible it throws an Exception saying Authorization required.
* </p>
* @param preferenceName
* - The name of the preference.
* @return {@link …
Run Code Online (Sandbox Code Playgroud) 我正在使用swagger测试我的其余api,我的实体类的属性之一是日期字段,我需要yyyy-mm-dd格式的日期,但swagger模型架构将此字段显示为日期时间而不是日期字段,因此它给出了时间和区域的日期.如何将此日期时间转换为日期字段?
我有一个java实体类TimeEntry.java,它的一个属性是Date,它看起来像这样.
@ApiModelProperty(required = true)
@JsonFormat(pattern = DATE_FORMAT)
private Date date;
Run Code Online (Sandbox Code Playgroud)
对于此字段,在swagger UI模型架构上,字段日期显示为"日期":"2016-01-08T22:34:22.337Z"但我需要将其作为"日期":"2016-01-08".
我尝试过以下方法:
1.
@ApiModelProperty(required = true, dataType="date")
@JsonFormat(pattern = DATE_FORMAT)
private Date date;
Run Code Online (Sandbox Code Playgroud)
2.Tried跟随这段代码(覆盖OverrideConvertor类)但找不到swagger-core 1.3版本的mvn repo.仅提供1.5版本https://github.com/swagger-api/swagger-core/wiki/overriding-models
请帮忙.
我有一个简单的端点,我想用swagger-maven-plugin处理.生成的swagger.conf不能反映单个@ApiOperations的正确"paths:".api的根是"/ api",我想将GET和PUT的端点添加到"/ api/cluster".相反,swagger.json输出的"paths:"子句是"/ api".
这是.java源代码,类上有@Api(value ="/ api")和@RequestMapping(value ="/ api"),带有@RequestMapping(value ="/ cluster")的入口点:
ClusterManagerController.java:
package com.vmturbo.clustermgr;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import javax.ws.rs.Path;
import java.io.OutputStream;
import java.util.Map;
import java.util.Set;
/**
* REST endpoint for ClusterMgr, exposing APIs for component status, component configuration, node configuration.
**/
@Component
@RestController
@Api(value = "/api", description = "Methods for managing the Ops Manager Cluster")
@RequestMapping(value="/api", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE})
public class ClusterMgrController {
@Autowired
private ClusterMgrService clusterMgrService;
/**
* Get …
Run Code Online (Sandbox Code Playgroud) Javadoc(通过Maven)在我的Java JAX-RS接口方法签名中给出了以下错误:
error: element value must be a constant expression
Run Code Online (Sandbox Code Playgroud)
这是我的JAX-RS接口:
public interface FooResource {
@Consumes(APPLICATION_FORM_URLENCODED_UTF_8)
public void bar();
}
Run Code Online (Sandbox Code Playgroud)
Javdoc给出了错误@Consumes
.以下是APPLICATION_FORM_URLENCODED_UTF_8
出现在MyAppConstants
同一项目中的定义:
public static final String APPLICATION_FORM_URLENCODED_UTF_8 =
APPLICATION_FORM_URLENCODED + ";" + CHARSET_PARAMETER + "=UTF-8";
Run Code Online (Sandbox Code Playgroud)
这里是这样定义的APPLICATION_FORM_URLENCODED
,它出现在javax.ws.rs.core.MediaType
:
public final static String APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
Run Code Online (Sandbox Code Playgroud)
这里是定义CHARSET_PARAMETER
,也出现在javax.ws.rs.core.MediaType
:
public static final String CHARSET_PARAMETER = "charset";
Run Code Online (Sandbox Code Playgroud)
现在我问你:APPLICATION_FORM_URLENCODED_UTF_8
在编译时不是很常见?
错误消息没有说我必须提供文字.它说我必须提供一个常数.那么这不是一个常数呢?
(我几乎可以发誓这种情况曾经有效但突然停止了工作.)
更新: 找到原因,但仍然不明白.
出于某种原因,仅仅包括swagger-maven-plugin
在POM中就会触发这个问题!我的代码根本没有改变,但是一旦我添加了以下依赖项,我突然得到现有代码的Javadoc警告!
<dependency>
<groupId>com.github.kongchen</groupId> …
Run Code Online (Sandbox Code Playgroud) java annotations javadoc maven-javadoc-plugin swagger-maven-plugin
我有自己的 RequestMappingHandlerMapping 并且正在使用 springfox-swagger-ui。添加自定义映射后,我无法在http://localhost:8080/swagger-ui.html实现 swagger ui 。有任何想法吗?
这是我的配置。
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
@Override
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
return new ApiVersionRequestMappingHandlerMapping("v");
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("(META-INF/resources/webjars");
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud) spring swagger-ui spring-boot swagger-maven-plugin swagger-2.0
我使用下面的maven插件将swagger与我的应用程序集成 https://github.com/martypitt/swagger-springmvc
我在我的spring servlet xml中配置了以下内容
<mvc:annotation-driven/> <!-- Required so swagger-springmvc can access spring's RequestMappingHandlerMapping -->
<bean class="com.mangofactory.swagger.configuration.SpringSwaggerConfig" />
<mvc:default-servlet-handler/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" >
<list>
<value>/WEB-INF/swagger.properties</value>
</list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
我的招摇属性如下所示
documentation.services.basePath = http://payrollservice.com/customservice documentation.services.version = 1.0
我生成的api-docs.json如下所示,我不确定为什么它没有基本路径,为什么它有前缀"/ default"
{
apiVersion: "1.0",
swaggerVersion: "1.2",
apis: [
{
path: "/default/custom-controller",
description: "backupset API"
}
],
info: {
title: "default Title",
description: "Api Description",
termsOfServiceUrl: "Api terms of service",
contact: "Contact Email",
license: "Licence Type",
licenseUrl: "License URL"
}
}
Run Code Online (Sandbox Code Playgroud) java ×6
swagger ×5
maven ×2
spring ×2
swagger-ui ×2
annotations ×1
javadoc ×1
spring-boot ×1
spring-mvc ×1
springfox ×1
swagger-2.0 ×1