@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.Context 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)); } }
@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; }
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); }
@Override protected void configure() { Info info = new Info() .title("Rakam API Documentation") .version(ServiceStarter.RAKAM_VERSION) .description("An analytics platform API that lets you create your own analytics services.") .contact(new Contact().email("contact@rakam.io")) .license(new License() .name("Apache License 2.0") .url("http://www.apache.org/licenses/LICENSE-2.0.html"));
Info info = new Info(); info.setTitle(settings.getString("swagger.info.title", settings.getApplicationName())); info.setVersion(settings.getString("swagger.info.version", settings.getApplicationVersion())); info.setDescription(ClassUtil.loadStringResource(settings.getFileUrl("swagger.info.description", "classpath:swagger/info.md"))); Contact contact = new Contact(); contact.setName(settings.getString("swagger.info.contact.name", null)); contact.setUrl(settings.getString("swagger.info.contact.url", null)); contact.setEmail(settings.getString("swagger.info.contact.email", null)); if (Strings.isNullOrEmpty(contact.getName()) License license = new License(); license.setName(settings.getString("swagger.info.license.name", null)); license.setUrl(settings.getString("swagger.info.license.url", null)); if (Strings.isNullOrEmpty(license.getName()) && Strings.isNullOrEmpty(license.getUrl())) {
info.setLicense(new License()); info.getLicense().setName(v); }); info.setLicense(new License()); info.getLicense().setUrl(v); }); info.setContact(new Contact()); info.getContact().setName(v); }); info.setContact(new Contact()); info.setLicense(new License()); info.getLicense().setName(v); }); info.setLicense(new License()); info.getLicense().setUrl(v); });
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()); }
@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(); } }
Info apiInfo = new Info(); apiInfo.setVersion(ReleaseConstants.CURRENT_API_VERSION); apiInfo.setTitle("Admiral"); apiInfo.setLicense(new License().name("Apache 2.0") .url("https://github.com/vmware/admiral/blob/master/LICENSE")); apiInfo.setContact(new Contact().url("https://github.com/vmware/admiral"));
/** * Creates the license swagger definition. * * @param annotationExpression The ballerina annotation attribute value for license. * @param info The info definition which the license needs to be build on. */ private void createLicenseModel(BLangExpression annotationExpression, Info info) { if (null != annotationExpression) { BLangRecordLiteral licenseAnnotation = (BLangRecordLiteral) annotationExpression; Map<String, BLangExpression> licenseAttributes = ConverterUtils.listToMap(licenseAnnotation.getKeyValuePairs()); License license = new License(); if (licenseAttributes.containsKey(ConverterConstants.ATTR_NAME)) { license.setName( ConverterUtils.getStringLiteralValue(licenseAttributes.get(ConverterConstants.ATTR_NAME))); } if (licenseAttributes.containsKey(ConverterConstants.ATTR_URL)) { license.setUrl( ConverterUtils.getStringLiteralValue(licenseAttributes.get(ConverterConstants.ATTR_URL))); } info.setLicense(license); } }
/** * validate configuration according to swagger spec and plugin requirement * * @param apiSource * @throws GenerateException */ private void validateConfiguration(ApiSource apiSource) throws GenerateException { if (apiSource == null) { throw new GenerateException("You do not configure any apiSource!"); } else if (apiSource.getInfo() == null) { throw new GenerateException("`<info>` is required by Swagger Spec."); } if (apiSource.getInfo().getTitle() == null) { throw new GenerateException("`<info><title>` is required by Swagger Spec."); } if (apiSource.getInfo().getVersion() == null) { throw new GenerateException("`<info><version>` is required by Swagger Spec."); } if (apiSource.getInfo().getLicense() != null && apiSource.getInfo().getLicense().getName() == null) { throw new GenerateException("`<info><license><name>` is required by Swagger Spec."); } if (apiSource.getLocations() == null) { throw new GenerateException("<locations> is required by this plugin."); } }
public License license(ObjectNode node, String location, ParseResult result) { if(node == null) return null; License license = new License(); String value = getString("name", node, true, location, result); license.name(value); value = getString("url", node, false, location, result); license.url(value); // extra keys Set<String> keys = getKeys(node); for(String key : keys) { if(key.startsWith("x-")) { license.setVendorExtension(key, extension(node.get(key))); } else if(!LICENSE_KEYS.contains(key)) { result.extra(location + ".license", key, node.get(key)); } } return license; }
private License convert(io.swagger.models.License v2License) { if (v2License == null) { return null; } License license = new License(); license.setExtensions(convert(v2License.getVendorExtensions())); license.setName(v2License.getName()); license.setUrl(v2License.getUrl()); return license; }
License _license = null; if (_info!=null) { _license=_info.getLicense(); String _name = license.getName(); if (_name != null) { _elvis = _name; } else { String _url = license.getUrl(); _elvis = _url; String _url_1 = license.getUrl(); boolean _tripleNotEquals = (_url_1 != null); if (_tripleNotEquals) { StringConcatenation _builder = new StringConcatenation(); _builder.append("<a href=\""); String _url_2 = license.getUrl(); _builder.append(_url_2); _builder.append("\">");
public static License license() { return new License(); } public static BasicAuthDefinition basicAuth() {
public License name(String name) { setName(name); return this; }
public License url(String url) { setUrl(url); return this; }
io.swagger.models.Info info = swagger.getInfo(); if (info == null) { info = new io.swagger.models.Info(); swagger.setInfo(info); info.setDescription(infoConfig.description()); info.setTermsOfService(infoConfig.termsOfService()); Contact contact = info.getContact(); if (contact == null) { contact = new Contact(); info.setContact(contact); contact.setName(infoConfig.contact().name()); if (!infoConfig.contact().email().isEmpty()) { contact.setEmail(infoConfig.contact().email()); License license = info.getLicense(); if (license == null) { license = new License(); info.setLicense(license); license.setName(infoConfig.license().name()); if (!infoConfig.license().url().isEmpty()) { license.setUrl(infoConfig.license().url());