io.swagger.annotations.Info#io.swagger.models.License源码实例Demo

下面列出了io.swagger.annotations.Info#io.swagger.models.License 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ambari-logsearch   文件: ApiDocConfig.java
@Bean
public BeanConfig swaggerConfig() {
  BeanConfig beanConfig = new BeanConfig();
  beanConfig.setSchemes(new String[]{"http", "https"});
  beanConfig.setBasePath(BASE_PATH);
  beanConfig.setTitle(TITLE);
  beanConfig.setDescription(DESCRIPTION);
  beanConfig.setLicense(LICENSE);
  beanConfig.setLicenseUrl(LICENSE_URL);
  beanConfig.setScan(true);
  beanConfig.setVersion(VERSION);
  beanConfig.setResourcePackage(ServiceLogsResource.class.getPackage().getName());

  License license = new License();
  license.setName(LICENSE);
  license.setUrl(LICENSE_URL);

  Info info = new Info();
  info.setDescription(DESCRIPTION);
  info.setTitle(TITLE);
  info.setVersion(VERSION);
  info.setLicense(license);
  beanConfig.setInfo(info);
  return beanConfig;
}
 
源代码2 项目: dorado   文件: ApiContextBuilderImpl.java
@Override
// 这里定制Api全局信息,如文档描述、license,contact等信息
public ApiContext buildApiContext() {
	Info info = new Info()
			.contact(new Contact().email("[email protected]").name("weiping wang")
					.url("http://github.com/javagossip/dorado"))
			.license(new License().name("apache v2.0").url("http://www.apache.org"))
			.termsOfService("http://swagger.io/terms/").description("Dorado服务框架api接口文档")
			.title("dorado demo api接口文档").version("1.0.0");

	//构造api访问授权的apiKey
	ApiKey apiKey = ApiKey.builder().withName("Authorization").withIn("header").build();
	ApiContext apiContext = ApiContext.builder().withApiKey(apiKey)
			.withInfo(info).build();

	return apiContext;
}
 
源代码3 项目: dorado   文件: SwaggerAutoConfiguration.java
@Bean(name = "swaggerApiContext")
public ApiContext buildApiContext() {
	Info info = new Info();
	info.title(swaggerConfig.getTitle()).description(swaggerConfig.getDescription())
			.termsOfService(swaggerConfig.getTermsOfServiceUrl()).version(swaggerConfig.getVersion());
	Contact contact = swaggerConfig.getContact();

	if (contact != null)
		info.setContact(new io.swagger.models.Contact().email(contact.getEmail()).name(contact.getName())
				.url(contact.getUrl()));

	info.setLicense(new License().name(swaggerConfig.getLicense()).url(swaggerConfig.getLicenseUrl()));

	ApiContext.Builder apiContextBuilder = ApiContext.builder().withInfo(info);

	ai.houyi.dorado.swagger.springboot.SwaggerProperties.ApiKey apiKey = swaggerConfig.getApiKey();
	if (apiKey != null) {
		ApiKey _apiKey = ApiKey.builder().withIn(swaggerConfig.getApiKey().getIn())
				.withName(swaggerConfig.getApiKey().getName()).build();
		apiContextBuilder.withApiKey(_apiKey);
	}

	return apiContextBuilder.build();
}
 
private License convertLicense(io.swagger.annotations.License licenseAnnotation) {
  License license = new License();

  if (StringUtils.isNotEmpty(licenseAnnotation.name())) {
    license.setName(licenseAnnotation.name());
  }
  if (StringUtils.isNotEmpty(licenseAnnotation.url())) {
    license.setUrl(licenseAnnotation.url());
  }

  if (StringUtils.isEmpty(license.getName()) && StringUtils.isEmpty(license.getUrl())) {
    return null;
  }

  return license;
}
 
源代码5 项目: swagger2markup   文件: LicenseInfoComponent.java
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    Info info = params.info;
    License license = info.getLicense();
    String termOfService = info.getTermsOfService();
    if ((license != null && (isNotBlank(license.getName()) || isNotBlank(license.getUrl()))) || isNotBlank(termOfService)) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(LICENSE_INFORMATION));
        MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);
        if (license != null) {
            if (isNotBlank(license.getName())) {
                paragraph.italicText(labels.getLabel(LICENSE)).textLine(COLON + license.getName());
            }
            if (isNotBlank(license.getUrl())) {
                paragraph.italicText(labels.getLabel(LICENSE_URL)).textLine(COLON + license.getUrl());
            }
        }

        paragraph.italicText(labels.getLabel(TERMS_OF_SERVICE)).textLine(COLON + termOfService);

        markupDocBuilder.paragraph(paragraph.toString(), true);
    }

    return markupDocBuilder;
}
 
源代码6 项目: swagger2markup   文件: LicenseInfoComponentTest.java
@Test
public void testLicenseInfoComponent() throws URISyntaxException {

    Info info = new Info()
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))
            .termsOfService("Bla bla bla");

    Swagger2MarkupConverter.SwaggerContext context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new LicenseInfoComponent(context).apply(markupDocBuilder, LicenseInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}
 
源代码7 项目: cxf   文件: Java2SwaggerMojo.java
private void configureSwagger() {
    swagger = new Swagger();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    Info info = new Info();
    Contact swaggerContact = new Contact();
    License swaggerLicense = new License();
    swaggerLicense.name(this.license)
        .url(this.licenseUrl);
    swaggerContact.name(this.contact);
    info.version(this.version)
        .description(this.description)
        .contact(swaggerContact)
        .license(swaggerLicense)
        .title(this.title);
    swagger.setInfo(info);
    if (this.schemes != null) {
        for (String scheme : this.schemes) {
            swagger.scheme(Scheme.forValue(scheme));
        }
    }
    swagger.setHost(this.host);
    swagger.setBasePath(this.basePath);
}
 
源代码8 项目: jboot   文件: JbootSwaggerManager.java
public void init() {
    if (!config.isConfigOk()) {
        return;
    }

    swagger = new Swagger();
    swagger.setHost(config.getHost());
    swagger.setBasePath("/");
    swagger.addScheme(HTTP);
    swagger.addScheme(HTTPS);


    Info swaggerInfo = new Info();
    swaggerInfo.setDescription(config.getDescription());
    swaggerInfo.setVersion(config.getVersion());
    swaggerInfo.setTitle(config.getTitle());
    swaggerInfo.setTermsOfService(config.getTermsOfService());

    Contact contact = new Contact();
    contact.setName(config.getContactName());
    contact.setEmail(config.getContactEmail());
    contact.setUrl(config.getContactUrl());
    swaggerInfo.setContact(contact);

    License license = new License();
    license.setName(config.getLicenseName());
    license.setUrl(config.getLicenseUrl());
    swaggerInfo.setLicense(license);


    swagger.setInfo(swaggerInfo);

    List<Class> classes = ClassScanner.scanClassByAnnotation(RequestMapping.class, false);

    Reader.read(swagger, classes);

}
 
源代码9 项目: msf4j   文件: MSF4JBeanConfig.java
private void updateInfoFromConfig() {
    if (getSwagger().getInfo() == null) {
        setInfo(new Info());
    }

    if (StringUtils.isNotBlank(getDescription())) {
        getSwagger().getInfo().setDescription(getDescription());
    }

    if (StringUtils.isNotBlank(getTitle())) {
        getSwagger().getInfo().setTitle(getTitle());
    }

    if (StringUtils.isNotBlank(getVersion())) {
        getSwagger().getInfo().setVersion(getVersion());
    }

    if (StringUtils.isNotBlank(getTermsOfServiceUrl())) {
        getSwagger().getInfo().setTermsOfService(getTermsOfServiceUrl());
    }

    if (getContact() != null) {
        getSwagger().getInfo().setContact((new Contact()).name(getContact()));
    }

    if (getLicense() != null && getLicenseUrl() != null) {
        getSwagger().getInfo().setLicense((new License()).name(getLicense()).url(getLicenseUrl()));
    }

    if (getSchemes() != null) {
        for (String scheme : getSchemes()) {
            reader.getSwagger().scheme(Scheme.forValue(scheme));
        }
    }

    reader.getSwagger().setInfo(getInfo());
}
 
源代码10 项目: swagger-maven-plugin   文件: ApiSource.java
private License from(io.swagger.annotations.License licenseAnnotation) {
    License license = new License()
            .name(emptyToNull(licenseAnnotation.name()))
            .url(emptyToNull(licenseAnnotation.url()));
    if (license.getName() == null && license.getUrl() == null) {
        license = null;
    }
    return license;
}
 
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (additionalProperties.containsKey(PROJECT_NAME)) {
        projectName = ((String) additionalProperties.get(PROJECT_NAME));
    }
    if (additionalProperties.containsKey(PROJECT_DESCRIPTION)) {
        projectDescription = ((String) additionalProperties.get(PROJECT_DESCRIPTION));
    }
    if (additionalProperties.containsKey(PROJECT_VERSION)) {
        projectVersion = ((String) additionalProperties.get(PROJECT_VERSION));
    }
    if (additionalProperties.containsKey(BASE_NAMESPACE)) {
        baseNamespace = ((String) additionalProperties.get(BASE_NAMESPACE));
    }

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (projectName == null &&  info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            projectName = dashize(info.getTitle());
        }
        if (projectVersion == null) {
            // when projectVersion is not specified, use info.version
            projectVersion = info.getVersion();
        }
        if (projectDescription == null) {
            // when projectDescription is not specified, use info.description
            projectDescription = info.getDescription();
        }

        if (info.getContact() != null) {
            Contact contact = info.getContact();
            if (additionalProperties.get(PROJECT_URL) == null) {
                additionalProperties.put(PROJECT_URL, contact.getUrl());
            }
        }
        if (info.getLicense() != null) {
            License license = info.getLicense();
            if (additionalProperties.get(PROJECT_LICENSE_NAME) == null) {
                additionalProperties.put(PROJECT_LICENSE_NAME, license.getName());
            }
            if (additionalProperties.get(PROJECT_LICENSE_URL) == null) {
                additionalProperties.put(PROJECT_LICENSE_URL, license.getUrl());
            }
        }
    }

    // default values
    if (projectName == null) {
        projectName = "swagger-clj-client";
    }
    if (projectVersion == null) {
        projectVersion = "1.0.0";
    }
    if (projectDescription == null) {
        projectDescription = "Client library of " + projectName;
    }
    if (baseNamespace == null) {
        baseNamespace = dashize(projectName);
    }
    apiPackage = baseNamespace + ".api";

    additionalProperties.put(PROJECT_NAME, projectName);
    additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
    additionalProperties.put(PROJECT_VERSION, projectVersion);
    additionalProperties.put(BASE_NAMESPACE, baseNamespace);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);

    final String baseNamespaceFolder = sourceFolder + File.separator + namespaceToFolder(baseNamespace);
    supportingFiles.add(new SupportingFile("project.mustache", "", "project.clj"));
    supportingFiles.add(new SupportingFile("core.mustache", baseNamespaceFolder, "core.clj"));
    supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
    supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
}
 
@Override
public void preprocessSwagger(Swagger swagger) {
    super.preprocessSwagger(swagger);

    if (swagger.getInfo() != null) {
        Info info = swagger.getInfo();
        if (StringUtils.isBlank(projectName) && info.getTitle() != null) {
            // when projectName is not specified, generate it from info.title
            projectName = sanitizeName(dashize(info.getTitle()));
        }
        if (StringUtils.isBlank(projectVersion)) {
            // when projectVersion is not specified, use info.version
            projectVersion = escapeUnsafeCharacters(escapeQuotationMark(info.getVersion()));
        }
        if (projectDescription == null) {
            // when projectDescription is not specified, use info.description
            projectDescription = sanitizeName(info.getDescription());
        }

        // when licenceName is not specified, use info.license
        if (additionalProperties.get(CodegenConstants.LICENSE_NAME) == null && info.getLicense() != null) {
            License license = info.getLicense();
            licenseName = license.getName();
        }
    }

    // default values
    if (StringUtils.isBlank(projectName)) {
        projectName = "swagger-js-client";
    }
    if (StringUtils.isBlank(moduleName)) {
        moduleName = camelize(underscore(projectName));
    }
    if (StringUtils.isBlank(projectVersion)) {
        projectVersion = "1.0.0";
    }
    if (projectDescription == null) {
        projectDescription = "Client library of " + projectName;
    }
    if (StringUtils.isBlank(licenseName)) {
        licenseName = "Unlicense";
    }

    additionalProperties.put(PROJECT_NAME, projectName);
    additionalProperties.put(MODULE_NAME, moduleName);
    additionalProperties.put(PROJECT_DESCRIPTION, escapeText(projectDescription));
    additionalProperties.put(PROJECT_VERSION, projectVersion);
    additionalProperties.put(CodegenConstants.LICENSE_NAME, licenseName);
    additionalProperties.put(CodegenConstants.API_PACKAGE, apiPackage);
    additionalProperties.put(CodegenConstants.INVOKER_PACKAGE, invokerPackage);
    additionalProperties.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, localVariablePrefix);
    additionalProperties.put(CodegenConstants.MODEL_PACKAGE, modelPackage);
    additionalProperties.put(CodegenConstants.SOURCE_FOLDER, sourceFolder);
    additionalProperties.put(USE_PROMISES, usePromises);
    additionalProperties.put(USE_INHERITANCE, supportsInheritance);
    additionalProperties.put(EMIT_MODEL_METHODS, emitModelMethods);
    additionalProperties.put(EMIT_JS_DOC, emitJSDoc);
    additionalProperties.put(USE_ES6, useES6);

    // make api and model doc path available in mustache template
    additionalProperties.put("apiDocPath", apiDocPath);
    additionalProperties.put("modelDocPath", modelDocPath);

    String[][] supportingTemplateFiles = JAVASCRIPT_SUPPORTING_FILES;
    if (useES6) {
        supportingTemplateFiles = JAVASCRIPT_ES6_SUPPORTING_FILES;
    }

    for (String[] supportingTemplateFile :supportingTemplateFiles) {
        supportingFiles.add(new SupportingFile(supportingTemplateFile[0], "", supportingTemplateFile[1]));
    }
}