Нужно сгенерировать swagger.yaml и swagger документы без использования spring? - PullRequest
0 голосов
/ 26 сентября 2019
  1. Java-код для создания Docklet

    package com.tushar.migration.pentaho.config;
    
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    
    public class SwaggerConfig {
      private static final String LICENSE_URL = "";
      private static final String LICENSE = LICENSE_URL;
      private static final String CONTACT_EMAIL = LICENSE;
      private static final String APP_URL = "https://tushar.com";
      private static final String DEV_NAME = "Upgrade";
      private static final String TERMS_OF_SERVICE = "Terms of service";
      private static final String APP_VERSION = "1.0";
      private static final String APP_DESCRIPTION =
          "Pentaho Migration service provides the basic api endpoints for data migration.";
      private static final String APP_NAME = "PentahoMigrationService";
    
      public Docket pentahoAPI() {
        return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.any())
            .build()
            .apiInfo(metaData());
      }
    
      private ApiInfo metaData() {
        return new ApiInfo(
            APP_NAME,
            APP_DESCRIPTION,
            APP_VERSION,
            TERMS_OF_SERVICE,
            new Contact(DEV_NAME, APP_URL, CONTACT_EMAIL),
            LICENSE,
            LICENSE_URL);
      }
    }
    
  2. Gradle-задача для создания документа Swagger

.

task("generateSwaggerFile", type: SwaggerTask) {
    classesDirs = [
            file("build/classes/java/main")
    ]
    apiSources = [
            new ApiSource(
                    springmvc: false,
                    locations: [
                            "com.hilti.migration.pentaho.controller"
                    ],
                    schemes: ["http", "https"],
                    host: "hilti.com",
                    basePath: "/",
                    info: new Info(
                            title: "Pentaho Migration Service",
                            version: "v1",
                            description: "Pentaho Migrates data from AM2.0 to AM3.0",
                            contact: new Contact(
                                    url: "https://hilti.com",
                                    name: "TTM Upgrade",
                            ),
                            license: new License(
                                    url: "http://www.apache.org/licenses/LICENSE-2.0.html",
                                    name: "Apache 2.0"
                            )
                    ),
                    outputFormats: "yaml",
                    swaggerDirectory: file(".").path,
            )
    ]
}


tasks.generateSwaggerFile.dependsOn classes
check.dependsOn generateSwaggerFile
...