@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")); Swagger swagger = new Swagger().info(info) .basePath("/") .tags(ImmutableList.copyOf(tags)) .securityDefinition("write_key", new ApiKeyAuthDefinition().in(In.HEADER).name("write_key"))
private void correctInfo() { Info info = swagger.getInfo(); if (info == null) { info = new Info(); swagger.setInfo(info); } if (StringUtils.isEmpty(info.getTitle())) { info.setTitle("swagger definition for " + cls.getName()); } if (StringUtils.isEmpty(info.getVersion())) { info.setVersion("1.0.0"); } setJavaInterface(info, cls); }
private void convertInfo(io.swagger.annotations.Info infoAnnotation, Swagger swagger) { if (infoAnnotation == null) { return; } Info info = new Info(); info.setTitle(infoAnnotation.title()); info.setVersion(infoAnnotation.version()); info.setDescription(infoAnnotation.description()); info.setTermsOfService(infoAnnotation.termsOfService()); info.setContact(convertContact(infoAnnotation.contact())); info.setLicense(convertLicense(infoAnnotation.license())); info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoAnnotation.extensions())); swagger.setInfo(info); }
/** * Builds the overview MarkupDocument. * * @return the overview MarkupDocument */ @Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, OverviewDocument.Parameters params) { Swagger swagger = params.swagger; Info info = swagger.getInfo(); buildDocumentTitle(markupDocBuilder, info.getTitle()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEFORE, markupDocBuilder)); buildOverviewTitle(markupDocBuilder, labels.getLabel(Labels.OVERVIEW)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_BEGIN, markupDocBuilder)); buildDescriptionParagraph(markupDocBuilder, info.getDescription()); buildVersionInfoSection(markupDocBuilder, info); buildContactInfoSection(markupDocBuilder, info.getContact()); buildLicenseInfoSection(markupDocBuilder, info); buildUriSchemeSection(markupDocBuilder, swagger); buildTagsSection(markupDocBuilder, swagger.getTags()); buildConsumesSection(markupDocBuilder, swagger.getConsumes()); buildProducesSection(markupDocBuilder, swagger.getProduces()); buildExternalDocsSection(markupDocBuilder, swagger.getExternalDocs()); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_END, markupDocBuilder)); applyOverviewDocumentExtension(new Context(Position.DOCUMENT_AFTER, markupDocBuilder)); return markupDocBuilder; }
@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)); } }
@Test public void testVersionInfoComponent() throws URISyntaxException { Info info = new Info().version("1.0"); Swagger2MarkupConverter.Context context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new VersionInfoComponent(context).apply(markupDocBuilder, VersionInfoComponent.parameters(info, OverviewDocument.SECTION_TITLE_LEVEL)); markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8); Path expectedFile = getExpectedFile(COMPONENT_NAME); DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME)); } }
protected void readInfoConfig(SwaggerDefinition config) { Info infoConfig = config.info(); 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()); info.setTitle(infoConfig.title()); info.setVersion(infoConfig.version()); Contact contact = info.getContact(); if (contact == null) { contact = new Contact(); info.setContact(contact); License license = info.getLicense(); if (license == null) { license = new License(); info.setLicense(license); info.getVendorExtensions().putAll(BaseReaderUtils.parseExtensions(infoConfig.extensions()));
Swagger swagger = new Swagger(); 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()) info.setContact(contact); 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(license); swagger.setInfo(info); swagger.setExternalDocs(externalDocs);
LOGGER.debug("Generating combined specification from {} inputs", specs.size()); final Swagger combined = new Swagger(); combined.basePath(basePath); final Info info = new Info(); combined.setInfo(info); ofNullable(spec.getInfo()).ifPresent(specInfo -> description .append("\n* **") .append(specInfo.getTitle()) .append("**") .append(ofNullable(specInfo.getDescription()).map(specDesc -> " - " + specDesc).orElse(""))); tags.addAll(getOrEmpty(spec.getTags())); info.setTitle(ofNullable(title).orElse(DEFAULT_TITLE)); info.setDescription(description.toString()); return combined;
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()); }
public String generateSwaggerFromResources(API.APIBuilder api) { Swagger swagger = new Swagger(); Info info = new Info(); info.setTitle(api.getName()); info.setDescription(api.getDescription()); Contact contact = new Contact(); if (api.getBusinessInformation() != null) { BusinessInformation businessInformation = api.getBusinessInformation(); contact.setName(businessInformation.getBusinessOwner()); contact.setEmail(businessInformation.getBusinessOwnerEmail()); info.setContact(contact); info.setVersion(api.getVersion()); swagger.setInfo(info); String basePath = api.getContext() + File.separator + api.getVersion(); swagger.setBasePath(basePath); setSwaggerSchemes(swagger, api.getTransport());
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); }
public Swagger convert(ResourceListing resourceListing, List<ApiDeclaration> apiDeclarations) { Info info = new Info(); if (resourceListing.getInfo() != null) { ApiInfo apiInfo = resourceListing.getInfo(); Contact contact = null; if (apiInfo.getContact() != null) { contact = new Contact() .url(apiInfo.getContact()); license = new License() .name(apiInfo.getLicense()) .url(apiInfo.getLicenseUrl()); info = new Info() .description(apiInfo.getDescription()) .version(resourceListing.getApiVersion()) .title(apiInfo.getTitle()) .termsOfService(apiInfo.getTermsOfServiceUrl()) .contact(contact) .license(license); } else if (resourceListing.getApiVersion() != null) { info = new Info() .version(resourceListing.getApiVersion()); Swagger swagger = new Swagger() .host(host) .scheme(Scheme.forValue(scheme)) .basePath(basePath) .info(info)
final Info info = new Info(); cfg.setInfo(info); getConfigurationProperty(configurationProperties.getTitle()).ifPresent(v -> { info.setTitle(v); }); getConfigurationProperty(configurationProperties.getVersion()).ifPresent(v -> { info.setVersion(v); }); getConfigurationProperty(configurationProperties.getDescription()).ifPresent(v -> { info.setDescription(v); }); getConfigurationProperty(configurationProperties.getTermsOfServiceUrl()).ifPresent(v -> { info.setTermsOfService(v); }); getConfigurationProperty(configurationProperties.getLicenseName()).ifPresent(v -> { if (info.getLicense() == null) { info.setLicense(new License()); info.getLicense().setName(v); }); getConfigurationProperty(configurationProperties.getLicenseUrl()).ifPresent(v -> { if (info.getLicense() == null) { info.setLicense(new License()); info.getLicense().setUrl(v); }); getConfigurationProperty(configurationProperties.getContactName()).ifPresent(v -> { if (info.getContact() == null) { info.setContact(new Contact());
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); } }
protected void startCustomSwaggerService() { SwaggerDocumentationService swaggerDocumentationService = new SwaggerDocumentationService(); Info info = new Info(); info.version(ReleaseConstants.CURRENT_API_VERSION) .title(SwaggerDocumentation.InfoConstants.TITLE) .description(SwaggerDocumentation.InfoConstants.DESCRIPTION) .contact(new Contact() .name(SwaggerDocumentation.InfoConstants.CONTACT_NAME) .url(SwaggerDocumentation.InfoConstants.CONTACT_URL)) .license(new License() .name(SwaggerDocumentation.InfoConstants.LICENSE_NAME) .url(SwaggerDocumentation.InfoConstants.LICENSE_URL)); swaggerDocumentationService .setInfo(info) .setIncludePackages("com.vmware.admiral") .setSchemes(Scheme.HTTP, Scheme.HTTPS); this.startService(swaggerDocumentationService); }
private NewApiEntity mapSwagger12ToNewApi(Swagger swagger) { if (swagger == null || swagger.getInfo() == null) { return null; } NewApiEntity apiEntity = new NewApiEntity(); apiEntity.setName(swagger.getInfo().getTitle()); apiEntity.setDescription(swagger.getInfo().getDescription()); apiEntity.setVersion(swagger.getInfo().getVersion()); String scheme = (swagger.getSchemes() == null || swagger.getSchemes().isEmpty()) ? defaultScheme : swagger.getSchemes().iterator().next().toValue(); apiEntity.setEndpoint(scheme + "://" + swagger.getHost() + swagger.getBasePath()); apiEntity.setPaths(new ArrayList<>( swagger.getPaths().keySet() .stream() .map(path -> path.replaceAll("\\{(.[^/]*)\\}", ":$1")) .collect(Collectors.toList()))); return apiEntity; }
private void updateInfoFromConfig() { info = getSwagger().getInfo(); if (info == null) { info = new Info(); info.description(description); info.title(title); info.version(version); info.termsOfService(termsOfServiceUrl); this.info.contact(new Contact() .name(contact)); this.info.license(new License() .name(license) .url(licenseUrl)); reader.getSwagger().scheme(Scheme.forValue(scheme)); reader.getSwagger().setInfo(info);
private void initSwagger() { final Info info = new Info() .version(OpenmrsConstants.OPENMRS_VERSION_SHORT) .title("OpenMRS API Docs") .description("OpenMRS RESTful API documentation generated by Swagger") .contact(new Contact().name("OpenMRS").url("http://openmrs.org")) .license(new License().name("MPL-2.0 w/ HD").url("http://openmrs.org/license")); swagger .info(info) .host(this.host) .basePath(this.basePath) .schemes(this.schemes) .securityDefinition("basic_auth", new BasicAuthDefinition()) .security(new SecurityRequirement().requirement("basic_auth")) .consumes("application/json") .produces("application/json") .externalDocs(new ExternalDocs() .description("Find more info on REST Module Wiki") .url("https://wiki.openmrs.org/x/xoAaAQ")); }
@Override public void init(ServletConfig config) throws ServletException { Info info = new Info() .title("Swagger Server") .description("List of admin REST APIs for the pravega controller service.") .termsOfService("") .contact(new Contact() .email("")) .license(new License() .name("Apache 2.0") .url("http://www.apache.org/licenses/LICENSE-2.0")); ServletContext context = config.getServletContext(); Swagger swagger = new Swagger().info(info); new SwaggerContextService().withServletConfig(config).updateSwagger(swagger); } }