@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { Swagger swagger = params.swagger; if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME)); MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder); if (isNotBlank(swagger.getHost())) { paragraphBuilder.italicText(labels.getLabel(Labels.HOST)) .textLine(COLON + swagger.getHost()); } if (isNotBlank(swagger.getBasePath())) { paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH)) .textLine(COLON + swagger.getBasePath()); } if (isNotEmpty(swagger.getSchemes())) { List<String> schemes = swagger.getSchemes().stream() .map(Enum::toString) .collect(Collectors.toList()); paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES)) .textLine(COLON + join(schemes, ", ")); } markupDocBuilder.paragraph(paragraphBuilder.toString(), true); } return markupDocBuilder; }
/** * The method extracts the forward address from the {@link Swagger} model. * @param swagger The {@link Swagger} model contains information about the source address. * @return The extracted source address configured in {@link Swagger}. */ private String getForwardAddress(final Swagger swagger){ String schemas = "http"; if(swagger.getSchemes() != null && !swagger.getSchemes().isEmpty()){ schemas = swagger.getSchemes().get(0).toValue(); } return schemas + "://" + swagger.getHost() + swagger.getBasePath(); }
private static String determineSchemeToUse(final Swagger swagger, final URI specificationUrl) { final List<Scheme> schemes = swagger.getSchemes(); final boolean noSchemes = schemes == null || schemes.isEmpty(); if (noSchemes && specificationUrl == null) { return null; } final String schemeToUse; if (noSchemes && specificationUrl != null) { schemeToUse = specificationUrl.getScheme(); } else if (schemes.contains(Scheme.HTTPS)) { schemeToUse = "https"; } else { schemeToUse = schemes.stream()// .filter(s -> s.toValue().startsWith("http"))// .map(s -> s.toValue())// .findFirst()// .orElse(null); } return schemeToUse; }
private static String determineSchemeToUse(final Swagger swagger, final URI specificationUrl) { final List<Scheme> schemes = swagger.getSchemes(); final boolean noSchemes = schemes == null || schemes.isEmpty(); if (noSchemes && specificationUrl == null) { return null; } final String schemeToUse; if (noSchemes && specificationUrl != null) { schemeToUse = specificationUrl.getScheme(); } else if (schemes.contains(Scheme.HTTPS)) { schemeToUse = "https"; } else { schemeToUse = schemes.stream()// .filter(s -> s.toValue().startsWith("http"))// .map(s -> s.toValue())// .findFirst()// .orElse(null); } return schemeToUse; }
private void validateSpecification(Swagger swagger, String resource) { if (Strings.isNullOrEmpty(swagger.getHost())) { throw new IllegalArgumentException( String.format( "The OpenAPI specification contained in %s is missing the mandatory field: 'host'", resource)); } if (CollectionUtils.isEmpty(swagger.getSchemes())) { throw new IllegalArgumentException( String.format( "The OpenAPI specification contained in %s is missing the mandatory field: 'schemes'", resource)); } if (MapUtils.isEmpty(swagger.getPaths())) { throw new IllegalArgumentException( String.format( "The OpenAPI specification contained in %s is missing the mandatory field: 'paths'", resource)); } } }
private Object getScheme(final Swagger swagger) { Object _xblockexpression = null; { final Function1<Scheme, String> _function = (Scheme it) -> { return it.toString().toLowerCase(); }; final List<String> schemes = ListExtensions.<Scheme, String>map(swagger.getSchemes(), _function); for (final String preferredScheme : Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("https", "http"))) { boolean _contains = schemes.contains(preferredScheme); if (_contains) { return preferredScheme; } } Object _xifexpression = null; int _size = schemes.size(); boolean _greaterThan = (_size > 0); if (_greaterThan) { _xifexpression = swagger.getSchemes().get(0); } else { _xifexpression = "http"; } _xblockexpression = ((Object)_xifexpression); } return _xblockexpression; }
final URI specificationUrl = (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION); final List<Scheme> schemes = swagger.getSchemes(); final String schemeToUse; if (schemes == null || schemes.isEmpty()) {
final URI specificationUrl = (URI) vendorExtensions.get(BaseSwaggerConnectorGenerator.URL_EXTENSION); final List<Scheme> schemes = swagger.getSchemes(); final String schemeToUse; if (schemes == null || schemes.isEmpty()) {
String basePath = swagger.getBasePath(); String scheme = null; if(swagger.getSchemes().size() > 0) { if (this.preferredScheme == null) { scheme = swagger.getSchemes().get(0).toValue(); } else { for (Scheme s : swagger.getSchemes()) { if (s.toValue().equalsIgnoreCase(this.preferredScheme)) { scheme = s.toValue(); scheme = swagger.getSchemes().get(0).toValue();
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 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; }
final String swaggerScheme = pickBestScheme(specificationUri.getScheme(), swagger.getSchemes()); final String swaggerHost = swagger.getHost();
@Override public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) { Swagger swagger = params.swagger; if (isNotBlank(swagger.getHost()) || isNotBlank(swagger.getBasePath()) || isNotEmpty(swagger.getSchemes())) { markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(Labels.URI_SCHEME)); MarkupDocBuilder paragraphBuilder = copyMarkupDocBuilder(markupDocBuilder); if (isNotBlank(swagger.getHost())) { paragraphBuilder.italicText(labels.getLabel(Labels.HOST)) .textLine(COLON + swagger.getHost()); } if (isNotBlank(swagger.getBasePath())) { paragraphBuilder.italicText(labels.getLabel(Labels.BASE_PATH)) .textLine(COLON + swagger.getBasePath()); } if (isNotEmpty(swagger.getSchemes())) { List<String> schemes = swagger.getSchemes().stream() .map(Enum::toString) .collect(Collectors.toList()); paragraphBuilder.italicText(labels.getLabel(Labels.SCHEMES)) .textLine(COLON + join(schemes, ", ")); } markupDocBuilder.paragraph(paragraphBuilder.toString(), true); } return markupDocBuilder; }
public void populateTable(Swagger swagger) { DefaultTableModel defaultTableModel = (DefaultTableModel) this.table.getModel(); List<Scheme> schemes = swagger.getSchemes();
consumes.addAll(getOrEmpty(spec.getConsumes())); produces.addAll(getOrEmpty(spec.getProduces())); childSchemes.addAll(getOrEmpty(spec.getSchemes())); security.addAll(getOrEmpty(spec.getSecurity())); securityDefinitions.putAll(getOrEmpty(spec.getSecurityDefinitions()));
final List<Scheme> schemes = swagger.getSchemes(); if (schemes == null || schemes.isEmpty()) { if (specificationUrl == null) {
final List<Scheme> schemes = swagger.getSchemes(); if (schemes == null || schemes.isEmpty()) { if (specificationUrl == null) {
logger.info("Host: " + swagger.getHost()); logger.info("Base path: " + swagger.getBasePath()); logger.info("Schemes: " + swagger.getSchemes()); logger.info("Consumes: " + swagger.getConsumes()); logger.info("Produces: " + swagger.getProduces());
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; }
@Override public void swagger(Swagger swagger) { swagger.setSchemes(fillList(swagger.getSchemes())); swagger.setConsumes(fillList(swagger.getConsumes())); swagger.setProduces(fillList(swagger.getProduces())); swagger.setPaths(fillMap(swagger.getPaths())); swagger.setDefinitions(fillMap(swagger.getDefinitions())); swagger.setParameters(fillMap(swagger.getParameters())); swagger.setResponses(fillMap(swagger.getResponses())); swagger.setSecurityDefinitions(fillMap(swagger.getSecurityDefinitions())); swagger.setSecurity(fillList(swagger.getSecurity())); swagger.setTags(fillList(swagger.getTags())); }