Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javadocs生成Swagger文档_Java_Maven_Swagger_Swagger Maven Plugin - Fatal编程技术网

使用Javadocs生成Swagger文档

使用Javadocs生成Swagger文档,java,maven,swagger,swagger-maven-plugin,Java,Maven,Swagger,Swagger Maven Plugin,我想为一组现有的RESTful API构建Swagger文档。我有以下要求: 离线生成虚张声势文档(我用过)。这个插件帮助我在编译时生成Swagger文档 阅读现有的Javadoc,以便在Swagger文档中使用它们 到目前为止,使用上述插件,我能够达到第一点。因此,对于现有的REST方法: /** * <p> * Gets the {@link DisplayPreferenceModel} with the name as provided in the parameter

我想为一组现有的RESTful API构建Swagger文档。我有以下要求:

  • 离线生成虚张声势文档(我用过)。这个插件帮助我在编译时生成Swagger文档
  • 阅读现有的Javadoc,以便在Swagger文档中使用它们
  • 到目前为止,使用上述插件,我能够达到第一点。因此,对于现有的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 DisplayPreferenceModel}
     */
    @RequestMapping(method = RequestMethod.GET, value = "/preferences/{preferenceName}")
    @ApiOperation(value = "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", 
                            notes = "No Notes please", response = DisplayPreferenceModel.class)
    @ApiResponses(value = { 
                            @ApiResponse(code = 400, message = "Invalid preferenceName supplied"), 
                            @ApiResponse(code = 404, message = "Display Preference Not Found")
                          }
                )
    public DisplayPreferenceModel getDisplayPreference( @PathVariable("preferenceName") final String preferenceName ) {
    }
    
    /**
    *
    *获取具有参数中提供的名称的{@link DisplayPreferenceModel}。返回在租户或主机级别定义的具有给定名称的首选项。
    *如果API有资格进行未经授权的访问,则此API为我们提供了首选项。如果API不符合此条件,则会抛出一个异常,表示需要授权。
    *

    *@param preferenceName *-首选项的名称。 *@return{@link DisplayPreferenceModel} */ @RequestMapping(method=RequestMethod.GET,value=“/preferences/{preferenceName}”) @ApiOperation(value=“如果此API符合未经授权的访问条件,则此API为我们提供首选项;如果不符合此条件,则会抛出一个异常,说明需要授权”, notes=“请不要注释”,response=DisplayPreferenceModel.class) @ApiResponses(值={ @ApiResponse(code=400,message=“提供的首选项名称无效”), @ApiResponse(代码=404,消息=“未找到显示首选项”) } ) public DisplayPreferenceModel getDisplayPreference(@PathVariable(“preferenceName”)最终字符串preferenceName){ }
    我能够生成昂首阔步的文档。@ApiOperation&@ApiResponses的使用使我的文档看起来很棒


    但是,我的问题是,我是否可以使用Javadocs,而不是让每个开发人员创建@ApiOperation&@ApiResponses,以便为我的团队节省时间?

    似乎有javadoc doclet用于生成JSON招摇资源列表:

    您可以使用从Javadoc生成swagger ui,它有一个swagger模块。首先,您需要将maven插件添加到pom文件中;e、 g

    <plugin>
            <groupId>com.webcohesion.enunciate</groupId>
            <artifactId>enunciate-maven-plugin</artifactId>
            <version>${enunciate.version}</version>
            <executions>
               <execution>
                      <goals>
                        <goal>docs</goal>
                      </goals>
                      <configuration>
                        <configFile>enunciate.xml</configFile>
                        <docsDir>${project.build.directory}</docsDir>
                      </configuration>
               </execution>
            </executions>
    </plugin>
    
    
    阐明
    阐明maven插件
    ${enuciate.version}
    文件
    expensiate.xml
    ${project.build.directory}
    
    其中“Enounciate.xml”包含项目特定的配置,如下所示:

    <enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:noNamespaceSchemaLocation="http://enunciate.webcohesion.com/schemas/enunciate-2.0.0-M.3.xsd">
    
        <application root="/rest" />
    
    </enunciate>
    
    
    

    然后运行
    mvn compile
    ,它将从您的Javadoc生成Swagger文档文件。

    如何生成这个docs@raj?我的项目是基于maven的,我也添加了Api符号和ApiResonses符号,但是我如何生成文档来提供帮助呢?我使用了“swagger springmvc”v1.0.2。然后我创建了一个CustomSwaggerConfig类,该类具有“@Configuration”和“@EnableSwagger”。在applicationContext.xml中,我引用了CustomSwaggerConfig。我没有spring,我只是和maven在一起,Struts抱歉,伙计,在这方面帮不了你多少忙。我们的项目使用Spring库,因此我们使用了“swagger-springmvc”,即使没有指定任何配置,它也能非常有效地工作。请注意,当您使用“docs”目标时,它是在
    mvn compile
    上生成的,而不是在
    mvn package
    上生成的
    mvn包
    用于不同的“组装”目标。还要确保您阅读了您需要的模块,否则它会生成大量您不需要的东西,就像其他语言的客户端一样。这可以与Springfox的swagger.json结合使用吗?