io.swagger.models.Swagger.getPath()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中io.swagger.models.Swagger.getPath()方法的一些代码示例,展示了Swagger.getPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Swagger.getPath()方法的具体详情如下:
包路径:io.swagger.models.Swagger
类名称:Swagger
方法名:getPath

Swagger.getPath介绍

暂无

代码示例

代码示例来源:origin: jooby-project/jooby

Optional.ofNullable(swagger.getPath(pattern))
  .orElseGet(() -> {
   Path path = new Path();

代码示例来源:origin: swagger-api/swagger-parser

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;
}

代码示例来源:origin: io.swagger.parser.v3/swagger-parser-v2-converter

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;
}

代码示例来源:origin: apache/servicecomb-java-chassis

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);
 }
}

代码示例来源:origin: org.zalando/vertx-swagger

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();
}

代码示例来源:origin: kongchen/swagger-maven-plugin

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);
}

代码示例来源:origin: org.openapitools.swagger.parser/swagger-parser-v2-converter

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;
}

代码示例来源:origin: org.apache.servicecomb/swagger-generator-core

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);
 }
}

代码示例来源:origin: com.google.api/api-compiler

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);
}

代码示例来源:origin: org.zalando/vertx-swagger

private Operation getDeleteOperation() {
    return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getDelete();
  }
}

代码示例来源:origin: googleapis/api-compiler

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);
}

代码示例来源:origin: org.zalando/vertx-swagger

private Operation getPostOperation() {
  return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getPost();
}

代码示例来源:origin: tminglei/binder-swagger-java

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);
  }
}

代码示例来源:origin: org.zalando/vertx-swagger

private Operation getGetOperation() {
  return swaggerRouter.getSwagger().getPath(routeConfiguration.getSwaggerPath()).getGet();
}

代码示例来源:origin: org.wso2.carbon.auth/org.wso2.carbon.auth.rest.api.authenticators

/**
 * 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);
  }
}

代码示例来源:origin: org.zalando/vertx-swagger

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;
}

代码示例来源:origin: networknt/light-rest-4j

@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);
}

代码示例来源:origin: io.syndesis.server/server-api-generator

@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);
}

代码示例来源:origin: io.syndesis.rest/rest-connector-generator

@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);
}

代码示例来源:origin: io.syndesis.server/server-connector-generator

@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);
}

相关文章

微信公众号

最新文章

更多