Optional.ofNullable(swagger.getPath(pattern)) .orElseGet(() -> { Path path = new Path();
public SwaggerInventory process(Swagger swagger) { Iterator var2; if(swagger.getTags() != null) { var2 = swagger.getTags().iterator(); while(var2.hasNext()) { Tag key = (Tag)var2.next(); this.process(key); } } String key1; if(swagger.getPaths() != null) { var2 = swagger.getPaths().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Path model = swagger.getPath(key1); this.process(model); } } if(swagger.getDefinitions() != null) { var2 = swagger.getDefinitions().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Model model1 = (Model)swagger.getDefinitions().get(key1); this.process(model1); } } return this; }
public SwaggerInventory process(Swagger swagger) { Iterator var2; if(swagger.getTags() != null) { var2 = swagger.getTags().iterator(); while(var2.hasNext()) { Tag key = (Tag)var2.next(); this.process(key); } } String key1; if(swagger.getPaths() != null) { var2 = swagger.getPaths().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Path model = swagger.getPath(key1); this.process(model); } } if(swagger.getDefinitions() != null) { var2 = swagger.getDefinitions().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Model model1 = (Model)swagger.getDefinitions().get(key1); this.process(model1); } } return this; }
protected void addOperationToSwagger() { if (StringUtils.isEmpty(httpMethod)) { return; } Path pathObj = swagger.getPath(path); if (pathObj == null) { pathObj = new Path(); swagger.path(path, pathObj); } HttpMethod hm = HttpMethod.valueOf(httpMethod.toUpperCase(Locale.US)); if (pathObj.getOperationMap().get(hm) != null) { throw new Error(String.format("Only allowed one default path. %s:%s", swaggerGenerator.getCls().getName(), providerMethod.getName())); } pathObj.set(httpMethod, operation); } }
public DefaultBindingBuilder(BindingBuilderFactory bindingBuilderFactory, SwaggerRouter swaggerRouter, String path) { this.bindingBuilderFactory = bindingBuilderFactory; this.swaggerRouter = swaggerRouter; this.routeConfiguration = new RouteConfiguration(path); Path swaggerPath = swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()); Preconditions.checkNotNull(swaggerPath, String.format("Could not find swagger path: [%s] in swagger spec: [%s]", routeConfiguration.getSwaggerPath(), swaggerRouter.getSwagger().getPaths().keySet())); this.operationMap = swaggerPath.getOperationMap(); }
protected void updatePath(String operationPath, String httpMethod, Operation operation) { if (httpMethod == null) { return; } Path path = swagger.getPath(operationPath); if (path == null) { path = new Path(); swagger.path(operationPath, path); } path.set(httpMethod, operation); }
public SwaggerInventory process(Swagger swagger) { Iterator var2; if(swagger.getTags() != null) { var2 = swagger.getTags().iterator(); while(var2.hasNext()) { Tag key = (Tag)var2.next(); this.process(key); } } String key1; if(swagger.getPaths() != null) { var2 = swagger.getPaths().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Path model = swagger.getPath(key1); this.process(model); } } if(swagger.getDefinitions() != null) { var2 = swagger.getDefinitions().keySet().iterator(); while(var2.hasNext()) { key1 = (String)var2.next(); Model model1 = (Model)swagger.getDefinitions().get(key1); this.process(model1); } } return this; }
protected void addOperationToSwagger() { if (StringUtils.isEmpty(httpMethod)) { return; } Path pathObj = swagger.getPath(path); if (pathObj == null) { pathObj = new Path(); swagger.path(path, pathObj); } HttpMethod hm = HttpMethod.valueOf(httpMethod.toUpperCase(Locale.US)); if (pathObj.getOperationMap().get(hm) != null) { throw new Error(String.format("Only allowed one default path. %s:%s", swaggerGenerator.getCls().getName(), providerMethod.getName())); } pathObj.set(httpMethod, operation); } }
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) { Map<String, String> duplicateOperationIdLookup = Maps.newHashMap(); TreeSet<String> urlPaths = Sets.newTreeSet(swagger.getPaths().keySet()); for (String urlPath : urlPaths) { Path pathObj = swagger.getPath(urlPath); createServiceMethodsFromPath(serviceBuilder, urlPath, pathObj, duplicateOperationIdLookup); } if (isAllowAllMethodsConfigured(swagger, diagCollector)) { Path userDefinedWildCardPathObject = new Path(); if (urlPaths.contains(OpenApiUtils.WILDCARD_URL_PATH)) { userDefinedWildCardPathObject = swagger.getPath(OpenApiUtils.WILDCARD_URL_PATH); } createServiceMethodsFromPath( serviceBuilder, OpenApiUtils.WILDCARD_URL_PATH, getNewWildCardPathObject(userDefinedWildCardPathObject), duplicateOperationIdLookup); } coreApiBuilder.setVersion(swagger.getInfo().getVersion()); if (isDeprecated(swagger)) { coreApiBuilder.addOptions( createBoolOption( ServiceOptions.getDescriptor() .findFieldByNumber(ServiceOptions.DEPRECATED_FIELD_NUMBER) .getFullName(), true)); } serviceBuilder.addApis(coreApiBuilder); }
private Operation getDeleteOperation() { return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getDelete(); } }
public void addFromSwagger(Service.Builder serviceBuilder, Swagger swagger) { Map<String, String> duplicateOperationIdLookup = Maps.newHashMap(); TreeSet<String> urlPaths = Sets.newTreeSet(swagger.getPaths().keySet()); for (String urlPath : urlPaths) { Path pathObj = swagger.getPath(urlPath); createServiceMethodsFromPath(serviceBuilder, urlPath, pathObj, duplicateOperationIdLookup); } if (isAllowAllMethodsConfigured(swagger, diagCollector)) { Path userDefinedWildCardPathObject = new Path(); if (urlPaths.contains(OpenApiUtils.WILDCARD_URL_PATH)) { userDefinedWildCardPathObject = swagger.getPath(OpenApiUtils.WILDCARD_URL_PATH); } createServiceMethodsFromPath( serviceBuilder, OpenApiUtils.WILDCARD_URL_PATH, getNewWildCardPathObject(userDefinedWildCardPathObject), duplicateOperationIdLookup); } coreApiBuilder.setVersion(swagger.getInfo().getVersion()); if (isDeprecated(swagger)) { coreApiBuilder.addOptions( createBoolOption( ServiceOptions.getDescriptor() .findFieldByNumber(ServiceOptions.DEPRECATED_FIELD_NUMBER) .getFullName(), true)); } serviceBuilder.addApis(coreApiBuilder); }
private Operation getPostOperation() { return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getPost(); }
public ExOperation mkOperation(HttpMethod method, String path) { notEmpty(path, "'path' CAN'T be null or empty!!!"); notEmpty(method, "'method' CAN'T be null or empty!!!"); synchronized (swagger) { String origPath = path; path = path.replaceAll("<[^>]+>", "").replaceAll("/:([^/]+)", "/{$1}"); // replace `/:id<[0-9]+>` with `/{id}` if (swagger.getPath(path) == null) { logger.info(">>> adding path - '" + path + "'"); swagger.path(path, new Path()); } Path pathObj = swagger.getPath(path); if (pathObj.getOperationMap().get(method) != null) { throw new IllegalArgumentException("DUPLICATED operation - " + method + " '" + path + "'"); } logger.info(">>> adding operation - " + method + " '" + path + "'"); pathObj.set(method.name().toLowerCase(), new ExOperation(this, method, path)); implemented.put(entry(method, path), true); // set implemented by default String prevPath = origPaths.put(entry(method, path), origPath); if (prevPath != null) throw new IllegalArgumentException( "`" + path + "` was repeatedly defined by `" + prevPath + "` and `" + origPath + "`!!!"); return (ExOperation) pathObj.getOperationMap().get(method); } }
private Operation getGetOperation() { return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getGet(); }
/** * Get defined HTTP methods in the swagger definition as a comma separated string * * @param request Request * @param method Method information for the request * @return Http Methods as a comma separated string * @throws RestAPIAuthSecurityException if failed to get defined http methods */ public static String getDefinedMethodHeadersInSwaggerContent( Request request, Method method) throws RestAPIAuthSecurityException { RestAPIInfo electedSwagger = getElectedRestApiInfo(request); if (electedSwagger != null) { Path swaggerAPIPath = electedSwagger.getSwagger().getPath(getApiPath(method)); if (swaggerAPIPath == null) { throw new RestAPIAuthSecurityException("Could not read API path from the swagger definition"); } return swaggerAPIPath.getOperationMap().keySet().stream().map(Enum::toString) .collect(Collectors.joining(", ")); } else { throw new RestAPIAuthSecurityException("Couldn't find the SwaggerDefinition for API path", ExceptionCodes .INTERNAL_ERROR); } }
public <T, R> DefaultBindingBuilder get(Class<T> paramType, AsyncFunction<T, R> function) { routeConfiguration.addHandler(HttpMethod.GET, new ParameterCheckHandler(operationMap.get(io.swagger.models.HttpMethod.GET))); routeConfiguration.addHandler(HttpMethod.GET, toMetricsHandler(new GetHandler<>(swaggerRouter.getMapper(), function, paramType, swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath())))); return this; }
@Override public void handleRequest(final HttpServerExchange exchange) throws Exception { final NormalisedPath requestPath = new ApiNormalisedPath(exchange.getRequestURI()); final Optional<NormalisedPath> maybeApiPath = SwaggerHelper.findMatchingApiPath(requestPath); if (!maybeApiPath.isPresent()) { setExchangeStatus(exchange, STATUS_INVALID_REQUEST_PATH, requestPath.normalised()); return; } final NormalisedPath swaggerPathString = maybeApiPath.get(); final Path swaggerPath = SwaggerHelper.swagger.getPath(swaggerPathString.original()); final HttpMethod httpMethod = HttpMethod.valueOf(exchange.getRequestMethod().toString()); final Operation operation = swaggerPath.getOperationMap().get(httpMethod); if (operation == null) { setExchangeStatus(exchange, STATUS_METHOD_NOT_ALLOWED); return; } // This handler can identify the swaggerOperation and endpoint only. Other info will be added by JwtVerifyHandler. final SwaggerOperation swaggerOperation = new SwaggerOperation(swaggerPathString, swaggerPath, httpMethod, operation); String endpoint = swaggerPathString.normalised() + "@" + httpMethod.toString().toLowerCase(); Map<String, Object> auditInfo = new HashMap<>(); auditInfo.put(Constants.ENDPOINT_STRING, endpoint); auditInfo.put(Constants.SWAGGER_OPERATION_STRING, swaggerOperation); exchange.putAttachment(AuditHandler.AUDIT_INFO, auditInfo); Handler.next(exchange, next); }
@Test public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final Swagger swagger = new SwaggerParser().parse(specification); final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0); final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator .createPropertyFromParameter(petIdPathParameter); final ConfigurationProperty expected = new ConfigurationProperty.Builder()// .componentProperty(false)// .deprecated(false)// .description("ID of pet to return")// .displayName("petId")// .group("producer")// .javaType(Long.class.getName())// .kind("property")// .required(true)// .secret(false)// .type("integer")// .build(); assertThat(maybeConfigurationProperty).hasValue(expected); }
@Test public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final Swagger swagger = new SwaggerParser().parse(specification); final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0); final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator .createPropertyFromParameter(petIdPathParameter); final ConfigurationProperty expected = new ConfigurationProperty.Builder()// .componentProperty(false)// .deprecated(false)// .description("ID of pet to return")// .displayName("petId")// .group("producer")// .javaType(Long.class.getName())// .kind("property")// .required(true)// .secret(false)// .type("integer")// .build(); assertThat(maybeConfigurationProperty).hasValue(expected); }
@Test public void shouldCreatePropertyParametersFromPetstoreSwagger() throws IOException { final String specification = resource("/swagger/petstore.swagger.json"); final Swagger swagger = new SwaggerParser().parse(specification); final Parameter petIdPathParameter = swagger.getPath("/pet/{petId}").getGet().getParameters().get(0); final Optional<ConfigurationProperty> maybeConfigurationProperty = BaseSwaggerConnectorGenerator .createPropertyFromParameter(petIdPathParameter); final ConfigurationProperty expected = new ConfigurationProperty.Builder()// .componentProperty(false)// .deprecated(false)// .description("ID of pet to return")// .displayName("petId")// .group("producer")// .javaType(Long.class.getName())// .kind("property")// .required(true)// .secret(false)// .type("integer")// .build(); assertThat(maybeConfigurationProperty).hasValue(expected); }