public void apply(Swagger swagger) { swagger.setHost("newHostName"); //<1> swagger.basePath("newBasePath"); Map<String, Path> paths = swagger.getPaths(); //<2> paths.remove("/remove"); swagger.setPaths(paths); } }
/** * Specify the base address on which all documented services are available. * * @param host The address as string * @return This instance of {@link SwaggerDocumentationAssembler} */ public SwaggerDocumentationAssembler setHost(String host) { this.swagger.setHost(host); return this; }
public Swagger host(String host) { this.setHost(host); 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; }
@Override public void process(Object annotation, SwaggerGenerator swaggerGenerator) { SwaggerDefinition definitionAnnotation = (SwaggerDefinition) annotation; Swagger swagger = swaggerGenerator.getSwagger(); swaggerGenerator.setBasePath(definitionAnnotation.basePath()); swagger.setHost(definitionAnnotation.host()); convertConsumes(definitionAnnotation, swagger); convertProduces(definitionAnnotation, swagger); convertSchemes(definitionAnnotation, swagger); convertTags(definitionAnnotation, swagger); convertInfo(definitionAnnotation.info(), swagger); swagger.setExternalDocs(convertExternalDocs(definitionAnnotation.externalDocs())); }
private Swagger transformV2(String content, Map<String, String> config) { Swagger swagger = new SwaggerParser().parse(content); if (swagger != null && config != null && config.get("tryItURL") != null) { URI newURI = URI.create(config.get("tryItURL")); swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme()))); swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost()); swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath()); } return swagger; }
private Swagger transformV2(String content, Map<String, String> config) { Swagger swagger = new SwaggerParser().parse(content); if (swagger != null && config != null && config.get("tryItURL") != null) { URI newURI = URI.create(config.get("tryItURL")); swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme()))); swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost()); swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath()); } return swagger; }
private Swagger transformV1(String content, Map<String, String> config) { // Create temporary file for Swagger parser (only for descriptor version < 2.x) File temp = null; Swagger swagger = null; try { temp = createTmpSwagger1File(content); swagger = new SwaggerCompatConverter().read(temp.getAbsolutePath()); if (swagger != null && config != null && config.get("tryItURL") != null) { URI newURI = URI.create(config.get("tryItURL")); swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme()))); swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost()); swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath()); } } catch (IOException ioe) { // Fallback to the new parser } finally { if (temp != null) { temp.delete(); } } return swagger; }
private Swagger transformV1(String content, Map<String, String> config) { // Create temporary file for Swagger parser (only for descriptor version < 2.x) File temp = null; Swagger swagger = null; try { temp = createTmpSwagger1File(content); swagger = new SwaggerCompatConverter().read(temp.getAbsolutePath()); if (swagger != null && config != null && config.get("tryItURL") != null) { URI newURI = URI.create(config.get("tryItURL")); swagger.setSchemes(Collections.singletonList(Scheme.forValue(newURI.getScheme()))); swagger.setHost((newURI.getPort() != -1) ? newURI.getHost() + ':' + newURI.getPort() : newURI.getHost()); swagger.setBasePath((newURI.getRawPath().isEmpty()) ? "/" : newURI.getRawPath()); } } catch (IOException ioe) { // Fallback to the new parser } finally { if (temp != null) { temp.delete(); } } return swagger; }
public void scanAndRead() { Set<Class<?>> classes = classes(); if (classes != null) { Swagger swagger = reader.read(classes); if (StringUtils.isNotBlank(host)) { swagger.setHost(host); } if (StringUtils.isNotBlank(basePath)) { swagger.setBasePath(basePath); } updateInfoFromConfig(); } }
private void handleOptions(Swagger swagger, SwaggerUi3Options options) { if (!Strings.isNullOrEmpty(options.getBasePath())) { swagger.setBasePath(options.getBasePath()); } if (!Strings.isNullOrEmpty(options.getHost())) { swagger.setHost(options.getHost()); } }
swagger.setHost(host); swagger.setSchemes(schemes);
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); }
@Override public void scanAndRead() { Swagger swagger = reader.read(classes()); if (StringUtils.isNotBlank(getHost())) { swagger.setHost(getHost()); } if (StringUtils.isNotBlank(getBasePath())) { swagger.setBasePath(getBasePath()); } updateInfoFromConfig(); }
@Override public void scanAndRead() { Swagger swagger = reader.read(classes()); if (StringUtils.isNotBlank(getHost())) { swagger.setHost(getHost()); } if (StringUtils.isNotBlank(getBasePath())) { swagger.setBasePath(getBasePath()); } updateInfoFromConfig(); }
@Override public String generate(Swagger swagger) throws GenerationException { SwaggerUiOptions options = SwaggerUiOptions.fromParams(context.getGenTargetParameters()); if (!Strings.isNullOrEmpty(options.getBasePath())) { swagger.setBasePath(options.getBasePath()); } if (!Strings.isNullOrEmpty(options.getHost())) { swagger.setHost(options.getHost()); } URL resolutionBase = getResolutionBase(); String urlPrefix = new File(context.getOutputDirectory(), "assets/.").toURI().toString(); String swaggerUiString = new XGenerateSwaggerUI().generateForSwaggerSpec(swagger, urlPrefix, resolutionBase, isLiveView(), options, context); return swaggerUiString; }
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 process(Object annotation, SwaggerGenerator swaggerGenerator) { SwaggerDefinition definitionAnnotation = (SwaggerDefinition) annotation; Swagger swagger = swaggerGenerator.getSwagger(); swaggerGenerator.setBasePath(definitionAnnotation.basePath()); swagger.setHost(definitionAnnotation.host()); convertConsumes(definitionAnnotation, swagger); convertProduces(definitionAnnotation, swagger); convertSchemes(definitionAnnotation, swagger); convertTags(definitionAnnotation, swagger); convertInfo(definitionAnnotation.info(), swagger); swagger.setExternalDocs(convertExternalDocs(definitionAnnotation.externalDocs())); }
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; }
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); }