Swagger webservice doc generation

Swagger Javadoc

Link:

https://github.com/ryankennedy/swagger-jaxrs-doclet

Usage:

Allow swagger definition json file to begenerated on building the maven project. Add the following to your rest apiproject pom file

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-javadoc-plugin</artifactId>

<version>2.9.1</version>

<executions>

<execution>

<id>generate-service-docs</id>

<phase>generate-resources</phase>

<configuration>

<doclet>com.hypnoticocelot.jaxrs.doclet.ServiceDoclet</doclet>

<docletArtifact>

<groupId>com.hypnoticocelot</groupId>

<artifactId>jaxrs-doclet</artifactId>

<version>0.0.4-SNAPSHOT</version>

</docletArtifact>                       <reportOutputDirectory>${project.build.outputDirectory}</reportOutputDirectory>

<useStandardDocletOptions>false</useStandardDocletOptions>

<additionalparam>-apiVersion1 -docBasePath /apidocs -apiBasePathhttps://api.stubhub.com/</additionalparam>

</configuration>

<goals>

<goal>javadoc</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

mvn clean package      output is generated in target/classes/apidocs  

Pros:

Can generate swagger definition based onjax-rs annotations only, you don’t have to add any swagger annotations. Notinvasive.

Limitation:

The default plugin provided supports onlyjdk 1.7 javadoc, you have to recompile the source with jdk 1.6 tools.jar tosupport 1.6 javadoc

If at class level, api path is declared as “/”,the api json file is not generated

This has been fixed by me by modifying thesource code

If at class level, no path annotation isadded, the api json file is not generated

Swagger cxf integration

Link:

https://github.com/wordnik/swagger-core/wiki/Java-CXF-Quickstart

Usage:

Allow you to view swagger json definitionat runtime, there is an additional swagger doc rest endpoint in additional toyour original rest webservice

 

 

Maven dependencies

<dependency>

<groupId>com.wordnik</groupId>

<artifactId>swagger-jaxrs_2.10</artifactId>

<version>1.3.0</version>

</dependency>

Cxf spring config file

<!-- Swagger API listing resource -->

<bean id="swaggerResourceJSON"class="com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON"/>

<!-- Swagger writers -->

<bean id="resourceWriter"class="com.wordnik.swagger.jaxrs.listing.ResourceListingProvider"/>

<bean id="apiWriter"class="com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider"/>

<bean class="org.apache.cxf.jaxrs.JAXRSServerFactoryBean"init-method="create">

<property name="address" value="/" />

<property name="serviceBeans">

<list>

<!-- your resources go here -->

<!-- ... -->

<!-- ... -->

<!-- Swagger API Listing resource -->

<ref bean="swaggerResourceJSON" />

</list>

</property>

<property name="providers">

<list>

<!-- any other providers you need go here -->

<!-- ... -->

<!-- ... -->

<!-- required for writing swagger classes -->

<ref bean="resourceWriter" />

<ref bean="apiWriter" />

</list>

</property>

</bean>

<bean id="swaggerConfig" class="com.wordnik.swagger.jaxrs.config.BeanConfig">

<propertyname="resourcePackage" value="com.wordnik.swagger.sample.resource"/>

<propertyname="version" value="1.0.0"/>

<propertyname="basePath" value="http://localhost:8002/api"/>

<propertyname="title" value="Petstore sample app"/>

<propertyname="description" value="This is a app."/>

<propertyname="contact" value="[email protected]"/>

<propertyname="license" value="Apache 2.0 License"/>

<propertyname="licenseUrl" value="http://www.apache.org/licenses/LICENSE-2.0.html"/>

<property name="scan"value="true"/>

</bean>

The highlighted properties are important

You will see an additional endpoint in youwadl file and swagger json file in

http://<host>/<context>/api-docs

Pros:

API definitions are always most up to date,allow you to view swagger definition at run time

Limitations:

You need to add swagger annotations to yoursource

It will not work if:

You don’t have @Api annotation in yourservice class

You have @Api annotation but not [email protected] in your service method

 

Certain API definitions are not generated properly,even annotations are there. (Not too sure about the reasons)

Swagger maven plugin

Link:

https://github.com/kongchen/swagger-maven-plugin

Usage:

Allow swagger definition json file to begenerated on building the maven project, similar to the Javadocplugin

 

<pluginRepositories>

<pluginRepository>

<id>sonatype-snapshot</id>

<url>https://oss.sonatype.org/content/repositories/snapshots/</url>

<releases>

<enabled>false</enabled>

</releases>

<snapshots>

<enabled>true</enabled>

</snapshots>

</pluginRepository>

</pluginRepositories>

<build>

<plugins>

<plugin>

<groupId>com.github.kongchen</groupId>

<artifactId>swagger-maven-plugin</artifactId>

<version>2.0</version>

<configuration>

<apiSources>

<apiSource>

<locations>com.stubhub.apitest</locations>

<apiVersion>v1</apiVersion>

<basePath>http://www.stubhub.com.com</basePath>

<outputTemplate>

https://raw.github.com/kongchen/api-doc-template/master/v2.0/markdown.mustache

</outputTemplate>

<outputPath>generated/strapdown.html</outputPath>

<!--swaggerUIDocBasePath>http://www.stubhub.com/apidocsf</swaggerUIDocBasePath-->

<swaggerDirectory>generated/apidocs</swaggerDirectory>

<!--useOutputFlatStructure>false</useOutputFlatStructure-->

<!--mustacheFileRoot>${basedir}/src/main/resources/</mustacheFileRoot-->

</apiSource>

</apiSources>

</configuration>

<executions>

<execution>

<phase>compile</phase>

<goals>

<goal>generate</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

The highlighted package specifies thepackage to scan for swagger apis

Mvn clean compile   output is generated in generated/apidocs

Pros:

Can generate swagger API definition withoutserver running

Limitations:

You need to add swagger annotations to yoursource

It will not work if:

You don’t have @Api annotation in yourservice class

 

Swagger webservice doc generation,布布扣,bubuko.com

时间: 2024-08-25 12:08:09

Swagger webservice doc generation的相关文章

mule发布调用webservice

mule发布webservice 使用mule esb消息总线发布和调用webservice都非常精简,mule包装了所有操作,你只需要拖控件配置就可以,下面讲解mule发布: 1.下面是flow,http监听接口,CXF发布webservice,java用来引用webservice的方法. 2.xml代码如下:     <flow name="webService">      <http:listener config-ref="HTTP_Listene

ASP.NET CORE API Swagger+IdentityServer4授权验证

简介 本来不想写这篇博文,但在网上找到的文章博客都没有完整配置信息,所以这里记录下. 不了解IdentityServer4的可以看看我之前写的入门博文 Swagger 官方演示地址 源码地址 配置IdentityServer4服务端 首先创建一个新的ASP.NET Core项目. 这里选择空白项,新建空白项目 等待创建完成后,右键单击项目中的依赖项选择管理NuGet程序包,搜索IdentityServer4并安装: 等待安装完成后,下载官方提供的UI文件,并拖放到项目中.下载地址:https:/

Spring Boot:整合Swagger在线文档

综合概述 spring-boot作为当前最为流行的Java web开发脚手架,越来越多的开发者选择用其来构建企业级的RESTFul API接口.这些接口不但会服务于传统的web端(b/s),也会服务于移动端.在实际开发过程中,这些接口还要提供给开发测试进行相关的白盒测试,那么势必存在如何在多人协作中共享和及时更新API开发接口文档的问题. 假如你已经对传统的wiki文档共享方式所带来的弊端深恶痛绝,那么尝试一下Swagger2 方式,一定会让你有不一样的开发体验. 使用 Swagger 集成文档

JavaScript Patterns 2.12 Writing API Docs

Free and open source tools for doc generation: the JSDoc Toolkit (http://code.google.com/p/jsdoc-toolkit/) and YUIDoc (http://yuilibrary.com/projects/yuidoc). Process of generating API documentation ? Writing specially formatted code blocks ? Running

Using Apache Maven

Apache Maven是一个软件项目管理的综合工具(management and comprehension tool).可以将WAR文件部署到App Engine中.为了加快部署的速度,App Engine团队提供了插件和Maven原型这两个东西(plugin and Maven Archetypes). 注意:使用Maven时,你不需要从Google App Engine SDK下载java库.Maven会为你做这个事情.你也可以使用Maven在本地测试你的应用,以及将应用部署到生产环境的

Spring Boot:使用Redis存储技术

综合概述 Redis是一个开源免费的高性能key-value数据库,读取速度达110000次/s,写入速度达81000次/s.Redis支持丰富的数据类型,如Lists, Hashes, Sets 及 Ordered Sets 数据类型.Redis的所有操作都是原子性的,要么成功执行要么失败完全不执行.另外还可以通过MULTI和EXEC指令包起来支持事务.此外,Redis还具备丰富的特性 ,比如支持发布/订阅(publish/subscribe)模式,可以充当简单的消息中间件,还支持通知, ke

Spring Boot:使用Rabbit MQ消息队列

综合概述 消息队列 消息队列就是一个消息的链表,可以把消息看作一个记录,具有特定的格式以及特定的优先级.对消息队列有写权限的进程可以向消息队列中按照一定的规则添加新消息,对消息队列有读权限的进程则可以从消息队列中读走消息,而消息队列就是在消息的传输过程中保存消息的容器,你可以简单的把消息队列理解为类似快递柜,快递员(消息发布者)往快递柜(消息队列)投递物件(消息),接受者(消息订阅者)从快递柜(消息队列)接收物件(消息),当然消息队列往往还包含一些特定的消息传递和接收机制. 消息队列作为分布式系

使用swagger作为restful api的doc文档生成

作者:@Ryan-Miao本文为作者原创,转载请注明出处:http://www.cnblogs.com/woshimrf/p/5863318.html 目录 初衷swagger介绍在spring-boot中使用配置4.设定访问API doc的路由参考: 初衷 记得以前写接口,写完后会整理一份API接口文档,而文档的格式如果没有具体要求的话,最终展示的文档则完全决定于开发者的心情.也许多点,也许少点.甚至,接口总是需要适应新需求的,修改了,增加了,这份文档维护起来就很困难了.于是发现了swagge

spring boot之使用springfox swagger展示restful的api doc

新增文件: import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.bind.RelaxedPropertyResolver; import org.springframework.context.EnvironmentAware; import org.springframework.context.annotation.Bean; import org.springfra