Spring MVC - RAML Spec Synchroniser简介

1. Spring MVC - RAML Spec Synchroniser是一个工具,用以在Spring MVC应用和RAML文件定义之间进行同步。即Spring MVC应用的变化,可以通过该工具同步体现在RAML文件的定义中;反之亦然。

该工具包含如下3个独立的组件:

  • springmvc-raml-plugin
  • springmvc-raml-parser(忽略),解析Spring Annotations以生产RAML文件
  • springmvc-raml-annotations(忽略),定制Annotations
我们关注其中的springmvc-raml-plugin插件。


2. springmvc-raml-plugin是一个Maven插件,用以从RAML文件生成Spring框架的服务器端和客户端代码,或者反之。

1)从Spring代码实现生成RAML文件

pom.xml文件配置如下:

<plugin>
  <groupId>com.phoenixnap.oss</groupId>
  <artifactId>springmvc-raml-plugin</artifactId>
  <version>0.8.6</version>
  <configuration>
    <outputRamlFilePath>/src/main/resources/public/raml/api.raml</outputRamlFilePath>
	<javaDocPath>D:/</javaDocPath>
    <restBasePath>/</restBasePath>
    <version>0.0.1</version>
    <includeGlobalMediaType>false</includeGlobalMediaType>
	<restrictOnMediaType>false</restrictOnMediaType>
	<ignoredList>
	   <param>com.package.to.ignore</param>
	   <param>com.specificClass.to.ignore.ClassName</param>
	</ignoredList>
	<dependencyPackagesList>
	   <param>com.package.in.dependency.jar.to.include</param>
	</dependencyPackagesList>
  </configuration>
  <executions>
    <execution>
      <id>generate-springmvc-api-docs</id>
      <phase>compile</phase>
      <goals>
        <goal>generate-springmvc-api-docs</goal>
      </goals>
    </execution>
  </executions>
</plugin>

执行mvn clean install即可。


2)从RAML文件生成Spring代码实现

pom.xml文件配置如下:

<plugin>
  <groupId>com.phoenixnap.oss</groupId>
  <artifactId>springmvc-raml-plugin</artifactId>
  <version>0.8.6</version>
  <configuration>
    <ramlPath>{path.to.raml.file}</ramlPath>
	<schemaLocation>{path.to.schema.directory||schema.absolute.url}</schemaLocation>
	<outputRelativePath>/src/generated</outputRelativePath>
    <addTimestampFolder>false</addTimestampFolder>
    <basePackage>com.gen.wow</basePackage>
    <baseUri>/api</baseUri>
    <generateUnreferencedSchemas>true</generateUnreferencedSchemas>
	<generationConfig>
		<includeAdditionalProperties>false</includeAdditionalProperties>
		...
	</generationConfig>
	<seperateMethodsByContentType>false</seperateMethodsByContentType>
	<rule>com.phoenixnap.oss.ramlapisync.generation.rules.Spring4ControllerStubRule</rule>
	<ruleConfiguration>			
	</ruleConfiguration>
  </configuration>
  <executions>
    <execution>
      <id>generate-springmvc-endpoints</id>
      <phase>compile</phase>
      <goals>
        <goal>generate-springmvc-endpoints</goal>
      </goals>
    </execution>
  </executions>
</plugin>

执行mvn clean install即可。


3)检查RAML文件,验证生成的Spring代码实现

pom.xml文件配置如下:

<plugin>
  <groupId>com.phoenixnap.oss</groupId>
  <artifactId>springmvc-raml-plugin</artifactId>
  <version>0.8.6</version>
  <configuration>
    <ramlToVerifyPath>/src/main/resources/public/raml/api.raml</ramlToVerifyPath>
	<javaDocPath>D:/</javaDocPath>
    <performStyleChecks>true</performStyleChecks>
	<checkRamlAgainstImplementation>true</checkRamlAgainstImplementation>
	<checkForResourceExistence>true</checkForResourceExistence>
	<checkForActionExistence>true</checkForActionExistence>
	<checkForQueryParameterExistence>true</checkForQueryParameterExistence>
	<checkForPluralisedResourceNames>true</checkForPluralisedResourceNames>
	<checkForSpecialCharactersInResourceNames>true</checkForSpecialCharactersInResourceNames>
	<checkForDefinitionOf40xResponseInSecuredResource>true</checkForDefinitionOf40xResponseInSecuredResource>
	<checkForSchemaInSuccessfulResponseBody>true</checkForSchemaInSuccessfulResponseBody>
	<checkForSchemaInRequestBody>true</checkForSchemaInRequestBody>
	<checkForDefinitionOf404ResponseInGetRequest>true</checkForDefinitionOf404ResponseInGetRequest>
	<checkForResponseBodySchema>true</checkForResponseBodySchema>
	<breakBuildOnWarnings>false</breakBuildOnWarnings>
    <logWarnings>true</logWarnings>
    <logErrors>true</logErrors>
	<ignoredList>
	   <param>com.package.to.ignore</param>
	   <param>com.specificClass.to.ignore.ClassName</param>
	</ignoredList>
	<dependencyPackagesList>
	   <param>com.package.in.dependency.jar.to.include</param>
	</dependencyPackagesList>
  </configuration>
  <executions>
    <execution>
      <id>generate-springmvc-api-docs</id>
      <phase>compile</phase>
      <goals>
        <goal>verify-springmvc-api-docs</goal>
      </goals>
    </execution>
  </executions>
</plugin>

执行mvn clean install即可。



参考链接:

https://github.com/phoenixnap/springmvc-raml-plugin


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值