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); }
/** * Specify the {@link Info} object to be used by Swagger. This object * contains general information about the API such as the title, license, etc. * * @param info The {@link Info} object used by Swagger * @return This instance of {@link SwaggerDocumentationAssembler} */ public SwaggerDocumentationAssembler setInfo(Info info) { this.swagger.setInfo(info); return this; }
public Swagger info(Info info) { this.setInfo(info); return this; }
public AbstractDocumentSource(Log log, ApiSource apiSource) throws MojoFailureException { LOG = log; this.outputPath = apiSource.getOutputPath(); this.templatePath = apiSource.getTemplatePath(); this.swaggerPath = apiSource.getSwaggerDirectory(); this.modelSubstitute = apiSource.getModelSubstitute(); this.jsonExampleValues = apiSource.isJsonExampleValues(); swagger = new Swagger(); if (apiSource.getSchemes() != null) { for (String scheme : apiSource.getSchemes()) { swagger.scheme(Scheme.forValue(scheme)); } } // read description from file if (apiSource.getDescriptionFile() != null) { try { InputStream is = new FileInputStream(apiSource.getDescriptionFile()); apiSource.getInfo().setDescription(IOUtils.toString(is)); is.close(); } catch (IOException e) { throw new MojoFailureException(e.getMessage(), e); } } swagger.setHost(apiSource.getHost()); swagger.setInfo(apiSource.getInfo()); swagger.setBasePath(apiSource.getBasePath()); swagger.setExternalDocs(apiSource.getExternalDocs()); this.apiSource = apiSource; }
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); }
@Override public void afterPropertiesSet() throws Exception { swagger = new Swagger(); Info info = new Info(); info.setTitle("GreetingService"); swagger.setInfo(info); Map<String, Object> beans = applicationContext.getBeansWithAnnotation(SpringTimeService.class); Set<Class<?>> classes = new HashSet<Class<?>>(); for (Object bean : beans.values()) { classes.add(bean.getClass()); } Reader reader = new Reader(swagger, ReaderConfigUtils.getReaderConfig(null)); swagger = reader.read(classes); }
public void init(ServletConfig config) throws ServletException { Ioc ioc = appContext.getIoc(); Swagger swagger = ioc.get(Swagger.class); swagger.setInfo(ioc.get(Info.class, "swaggerInfo")); HashSet<Class<?>> classes = new HashSet<>(); String pkgName = conf.get("swagger.resource.package", appContext.getPackage()); for (Class<?> klass : Scans.me().scanPackage(pkgName)) { classes.add(klass); } Reader.read(swagger, classes); config.getServletContext().setAttribute("swagger", swagger); }
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 prepareSwagger() { List<String> json = Collections.singletonList(Operation.MEDIA_TYPE_APPLICATION_JSON); this.swagger.setConsumes(json); this.swagger.setProduces(json); if (this.service.getHost().getSecureListener() != null) { this.swagger.setSchemes(Collections.singletonList(Scheme.HTTPS)); URI uri = this.service.getHost().getSecureUri(); this.swagger.setHost(uri.getHost() + ":" + uri.getPort()); } else { this.swagger.setSchemes(Collections.singletonList(Scheme.HTTP)); URI uri = this.service.getHost().getPublicUri(); this.swagger.setHost(uri.getHost() + ":" + uri.getPort()); } this.swagger.setSchemes(new ArrayList<>()); this.swagger.setInfo(this.info); this.swagger.setBasePath(UriUtils.URI_PATH_CHAR); }
this.createOrganizationModel(attributes.get("organization"), info); swagger.setInfo(info);
@Override public Swagger configure(Swagger swagger) { ApplicationConfig application = ReferenceManager.getInstance().getApplication(); if (null != application) { Info info = swagger.getInfo(); if (info == null) { info = new Info(); swagger.setInfo(info); } info.setTitle(application.getName()); version = StringUtils.isNotBlank(version) ? version : application.getVersion(); if (StringUtils.isNotBlank(groupId) && StringUtils.isNotBlank(artifactId) && StringUtils.isNotBlank(version)){ info.setDescription(MessageFormat.format(mavenDependency, groupId, artifactId, version)); } info.setVersion(StringUtils.isNotBlank(version) ? version : ""); Contact contact = new Contact(); info.setContact(contact); contact.setName(application.getOwner()); } setBashPath(swagger); return swagger; }
swagger.setInfo(info); Map<String, Path> stringPathMap = new HashMap(); for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
reader.getSwagger().setInfo(info);
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); } }
@Override public void init(KieServerImpl kieServer, KieServerRegistry registry) { this.context = registry; JaxrsScanner jaxrsScanner = new DefaultJaxrsScanner(); jaxrsScanner.setPrettyPrint(true); /* * Set our JAX-RS Scanner with SCANNER_ID_DEFAULT. * We need to do this before creating the BeanConfig, as this prevents the BeanConfig to register itself as the default scanner. * The first one wins. */ SwaggerScannerLocator.getInstance().putScanner((SwaggerContextService.SCANNER_ID_DEFAULT), jaxrsScanner); BeanConfig beanConfig = new BeanConfig(); String contextRoot = KieServerEnvironment.getContextRoot(); if (contextRoot != null) { beanConfig.setBasePath(contextRoot + "/services/rest"); } //Set the Info on the Swagger object, not on the BeanConfig ... otherwise the Info on Swagger (which will be 'null') will override the Info we set on the BeanConfig. beanConfig.getSwagger().setInfo(getInfo()); beanConfig.setScan(true); initialized = true; }
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); }
private Swagger createSwagger(final Set<Class<?>> classes,final URL url){ Swagger swagger = new Reader(new Swagger()).read(classes); Info info = getSwaggerInfo(swagger); if(info!=null)swagger.setInfo(info); Map<String, SecuritySchemeDefinition> securityDefinitions = getSecurityDefinitions(swagger); if(securityDefinitions!=null)swagger.setSecurityDefinitions(securityDefinitions); String consumes = whiteLabel.getProperty(CONSUMES, null); if(anyIsSet(consumes))swagger.setConsumes(toList(swagger.getConsumes(),consumes)); String produces = whiteLabel.getProperty(PRODUCES, null); if(anyIsSet(produces))swagger.setProduces(toList(swagger.getProduces(),produces)); String basePath = whiteLabel.getProperty(BASE_PATH, getBasePath(swagger.getBasePath(), url)); if(anyIsSet(basePath))swagger.setBasePath(basePath); String schemes = whiteLabel.getProperty(SCHEMES, url.getProtocol().toUpperCase()); if(anyIsSet(schemes))swagger.setSchemes(toSchemeList(swagger.getSchemes(),schemes)); String host = whiteLabel.getProperty(HOST, url.getHost() + DOUBLE_POINT + url.getPort()); if(anyIsSet(host))swagger.setHost(host); String tags = whiteLabel.getProperty(TAGS, null); if(anyIsSet(tags))swagger.setTags(toTagList(swagger.getTags(),tags)); return swagger; }
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()); }
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 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); }