io.swagger.models.Path类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(13.5k)|赞(0)|评价(0)|浏览(112)

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

Path介绍

暂无

代码示例

代码示例来源: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: apache/servicecomb-java-chassis

protected void convertResponses() {
 if (swagger.getPaths() == null) {
  return;
 }
 for (Path path : swagger.getPaths().values()) {
  for (Operation operation : path.getOperations()) {
   for (Response response : operation.getResponses().values()) {
    convert(response.getSchema());
    Map<String, Property> headers = response.getHeaders();
    if (headers == null) {
     continue;
    }
    for (Property header : headers.values()) {
     convert(header);
    }
   }
  }
 }
}

代码示例来源:origin: Swagger2Markup/swagger2markup

Map<HttpMethod, Operation> result = new LinkedHashMap<>();
if (path.getGet() != null) {
  result.put(HttpMethod.GET, path.getGet());
if (path.getPut() != null) {
  result.put(HttpMethod.PUT, path.getPut());
if (path.getPost() != null) {
  result.put(HttpMethod.POST, path.getPost());
if (path.getDelete() != null) {
  result.put(HttpMethod.DELETE, path.getDelete());
if (path.getPatch() != null) {
  result.put(HttpMethod.PATCH, path.getPatch());
if (path.getHead() != null) {
  result.put(HttpMethod.HEAD, path.getHead());
if (path.getOptions() != null) {
  result.put(HttpMethod.OPTIONS, path.getOptions());

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

Optional.ofNullable(swagger.getTag(value))
   .orElseGet(() -> {
    Tag tag = new Tag().name(value);
    swagger.addTag(tag);
    return tag;
   });
 Optional.ofNullable(swagger.getPath(pattern))
   .orElseGet(() -> {
    Path path = new Path();
    swagger.path(pattern, path);
    return path;
Operation op = new Operation();
tags.forEach(it -> op.addTag(it.getName()));
op.operationId(operationId(route, tags.get(0), opIds));
path.set(method(route), op);

代码示例来源: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: io.syndesis/connector-generator

for (final Map.Entry<String, Path> pathEntry : notNull(swaggerModelInfo.getModel().getPaths()).entrySet()) {
  for (final Map.Entry<HttpMethod, Operation> operationEntry : notNull(pathEntry.getValue().getOperationMap()).entrySet()) {
    for (final Parameter parameter : notNull(operationEntry.getValue().getParameters())) {
      if (!(parameter instanceof BodyParameter)) {
        continue;
    for (final Map.Entry<String, Response> responseEntry : notNull(operationEntry.getValue().getResponses()).entrySet()) {
      if (!responseEntry.getKey().startsWith("2")) {
        continue; // check only correct responses
      if (responseEntry.getValue().getSchema() == null) {
        final String message = "Operation " + operationEntry.getKey() + " " + pathEntry.getKey()
          + " does not provide a response schema for code " + responseEntry.getKey();

代码示例来源:origin: apache/cxf

MessageContext ctx = createMessageContext();
String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/");
data.setBasePath(currentBasePath);
if (data.getHost() == null) {
  data.setHost(beanConfig.getHost());
if (data.getInfo() == null) {
  for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) {
    if (replaceTags && tag != null) {
      subentry.getValue().setTags(Collections.singletonList(tag.getName()));
      OperationResourceInfo ori = methods.get(key);
      subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori));
      for (int i = 0; i < subentry.getValue().getParameters().size(); i++) {
        subentry.getValue().getParameters().get(i).
            setDescription(javadocProvider.getMethodParameterDoc(ori, i));
        subentry.getValue().getResponses().entrySet().iterator().next().getValue().
            setDescription(javadocProvider.getMethodResponseDoc(ori));

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

protected void convertToInterface() {
 if (interfaceCls != null) {
  return;
 }
 ClassConfig classConfig = new ClassConfig();
 classConfig.setClassName(interfaceName);
 classConfig.setIntf(true);
 if (swagger.getPaths() != null) {
  for (Path path : swagger.getPaths().values()) {
   for (Operation operation : path.getOperations()) {
    Response result = operation.getResponses().get(SwaggerConst.SUCCESS_KEY);
    JavaType resultJavaType = swaggerObjectMap.get(result.getSchema());
    MethodConfig methodConfig = new MethodConfig();
    methodConfig.setName(operation.getOperationId());
    methodConfig.setResult(resultJavaType);
    for (Parameter parameter : operation.getParameters()) {
     String paramName = parameter.getName();
     paramName = ClassUtils.correctMethodParameterName(paramName);
     JavaType paramJavaType = ConverterMgr.findJavaType(this, parameter);
     methodConfig.addParameter(paramName, paramJavaType);
    }
    classConfig.addMethod(methodConfig);
   }
  }
 }
 interfaceCls = JavassistUtils.createClass(classLoader, classConfig);
}

代码示例来源:origin: dsukhoroslov/bagri

fullPath += paths.get(0);
Path path = swagger.getPath(fullPath);
if (path == null) {
  path = new Path();
    Operation op = new Operation();
    op.addScheme(Scheme.HTTP);
    op.addScheme(Scheme.HTTPS);
    op.setDescription(fn.getDescription());
    if (consumes != null) {
    op.defaultResponse(new Response());
    path.set(method.toLowerCase(), op);
    logger.debug("afterScan; added op: {} for method {}", op, method);
swagger.path(fullPath, path);
logger.debug("afterScan; set path: {}", path.getOperations()); 
if (consumes != null) {
  for (String consume: consumes) {
    swagger.addConsumes(consume);

代码示例来源:origin: org.kill-bill.billing/killbill-jaxrs

@Override
public void afterScan(final io.swagger.jaxrs.Reader reader, final Swagger swagger) {
  for (final String pathName : swagger.getPaths().keySet()) {
    final Path path = swagger.getPaths().get(pathName);
    decorateOperation(path.getGet(), pathName, "GET");
    decorateOperation(path.getPost(), pathName, "POST");
    decorateOperation(path.getPut(), pathName, "PUT");
    decorateOperation(path.getDelete(), pathName, "DELETE");
    decorateOperation(path.getOptions(), pathName, "OPTIONS");
  }
  for (final Model m : swagger.getDefinitions().values()) {
    if (m.getProperties() != null) {
      for (final Property p : m.getProperties().values()) {
        p.setReadOnly(false);
      }
    }
  }
}

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.core

@Override
public String generateSwaggerFromResources(CompositeAPI.Builder api) {
  Swagger swagger = new Swagger();
  Info info = new Info();
  info.setTitle(api.getName());
  swagger.setInfo(info);
  Map<String, Path> stringPathMap = new HashMap();
  for (UriTemplate uriTemplate : api.getUriTemplates().values()) {
      parameterList.add(getDefaultBodyParameter());
    Operation operation = new Operation();
    operation.setParameters(parameterList);
    operation.setOperationId(uriTemplate.getTemplateId());
    operation.addResponse("200", getDefaultResponse());
    if (stringPathMap.containsKey(uriTemplateString)) {
      Path path = stringPathMap.get(uriTemplateString);
      path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
    } else {
      Path path = new Path();
      path.set(uriTemplate.getHttpVerb().toLowerCase(), operation);
      stringPathMap.put(uriTemplateString, path);
  swagger.setPaths(stringPathMap);
  swagger.setPaths(stringPathMap);
  return Json.pretty(swagger);

代码示例来源:origin: org.wso2.carbon.apimgt/org.wso2.carbon.apimgt.core

String securityName = getOauthSecurityName(swagger);
if (!StringUtils.isEmpty(securityName)) {
  List<SecurityRequirement> securityRequirements = swagger.getSecurity();
  if (securityRequirements != null) {
    for (SecurityRequirement securityRequirement : securityRequirements) {
      SecurityRequirement securityRequirement = new SecurityRequirement();
      securityRequirement.setRequirements(securityName, api.getScopes());
      swagger.addSecurity(securityRequirement);
  swagger.getPaths().entrySet().removeIf(entry -> isPathNotExist(uriTemplateMap, securityName, entry));
  uriTemplateMap.forEach((k, v) -> {
    Path path = swagger.getPath(v.getUriTemplate());
    if (path == null) {
      path = new Path();
      swagger.path(v.getUriTemplate(), path);
    Map<HttpMethod, Operation> operationMap = path.getOperationMap();
    Operation operation = operationMap.get(getHttpMethodForVerb(v.getHttpVerb().toUpperCase
        ()));
      operationTocCreate.setParameters(parameterList);
      path.set(v.getHttpVerb().toLowerCase(), operationTocCreate);

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

Map<String, Path> paths = swagger.getPaths();
if (paths == null) paths = Collections.emptyMap();
for (String path : paths.keySet()) {
  Map<HttpMethod, Operation> operations = paths.get(path).getOperationMap();
  for (HttpMethod method : operations.keySet()) {
    Operation operation = operations.get(method);
    if (isEmpty(operation.getConsumes()))
      operation.setConsumes(swagger.getConsumes());
    if (isEmpty(operation.getProduces()))
      operation.setProduces(swagger.getProduces());
      Map<String, Response> responses = operation.getResponses();
      Response response = responses != null ? responses.get("200") : null;
      DataProvider dataProvider = response != null && response.getSchema() != null
        ? DataProviders.getInstance().collect(swagger, response.getSchema(), true)
        : new ConstDataProvider(null);
      dataProvider.setRequired(true);

代码示例来源:origin: io.swagger/swagger-inflector

public void resolvePath(Path path){
  for(Operation op : path.getOperations()) {
    // inputs
    for(Parameter parameter : op.getParameters()) {
      if(parameter instanceof BodyParameter) {
        BodyParameter body = (BodyParameter) parameter;
        Model schema = body.getSchema();
        Model resolved = resolveModel(schema);
        body.setSchema(resolved);
      }
    }
    // responses
    if(op.getResponses() != null) {
      for(String code : op.getResponses().keySet()) {
        Response response = op.getResponses().get(code);
        if (response.getResponseSchema() != null) {
          Model resolved = resolveModel(response.getResponseSchema());
          response.setResponseSchema(resolved);
        }
      }
    }
  }
}

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

public static OperationDescription operationDescriptionOf(final Swagger swagger, final Operation operation) {
  final Entry<String, Path> pathEntry = swagger.getPaths().entrySet().stream()
    .filter(e -> e.getValue().getOperations().contains(operation)).findFirst().get();
  final String path = pathEntry.getKey();
  final Entry<HttpMethod, Operation> operationEntry = pathEntry.getValue().getOperationMap().entrySet().stream()
    .filter(e -> e.getValue().equals(operation)).findFirst().get();
  final HttpMethod method = operationEntry.getKey();
  final String specifiedSummary = trimToNull(operation.getSummary());
  final String specifiedDescription = trimToNull(operation.getDescription());
  final String name = ofNullable(specifiedSummary).orElseGet(() -> method + " " + path);
  final String description = ofNullable(specifiedDescription).orElseGet(() -> "Send " + method + " request to " + path);
  return new OperationDescription(name, description);
}

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

@Test
public void shouldMakeNonUniqueOperationIdsUnique() {
  final Swagger swagger = new Swagger().path("/path", new Path().get(new Operation().operationId("foo"))
    .post(new Operation().operationId("foo")).put(new Operation().operationId("bar")));
  final Connector generated = generator.configureConnector(SWAGGER_TEMPLATE, new Connector.Builder().id("connector1").build(),
    createSettingsFrom(swagger));
  final List<ConnectorAction> actions = generated.getActions();
  assertThat(actions).hasSize(3);
  assertThat(actions.get(0).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo"));
  assertThat(actions.get(1).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("foo1"));
  assertThat(actions.get(2).getId()).hasValueSatisfying(id -> assertThat(id).endsWith("bar"));
}

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

public SwaggerHelperOperationDescriptionGenerationTest(final String operationSummary, final String operationDescription,
  final String expectedName, final String expectedDescription) {
  operation = new Operation().description(operationDescription).summary(operationSummary);
  swagger = new Swagger().path("/test", new Path().get(operation));
  expected = new OperationDescription(expectedName, expectedDescription);
}

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

tag.name(tagname);
   tags.put(tagname, tag);
   swagger.addTag(tag);
   path = new Path();
   paths.put(pattern, path);
  Operation op = new Operation();
  op.addTag(tag.getName());
  route.name().ifPresent(op::operationId);
  route.name().ifPresent(n -> op.summary(Route.normalize(n).substring(1)));
  path.set(route.method().toLowerCase(), op);
 } else {
  log.debug("skipping: {}", route);
swagger.paths(paths);

代码示例来源:origin: Sayi/swagger-dubbo

Method interfaceMethod = entry.getKey();
final Operation operation = new Operation();
String operationPath = null;
String httpMethod = null;
  if (operation.getResponses() == null) {
    operation.defaultResponse(new Response().description("successful operation"));
  final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
  Path path = swagger.getPath(parsedPath);
  if (path == null) {
    path = new Path();
    swagger.path(parsedPath, path);
  path.set(httpMethod.toLowerCase(), operation);

代码示例来源:origin: yangfuhai/jboot

continue;
final Operation operation = new Operation();
  if ("post".equalsIgnoreCase(httpMethod) && operation.getConsumes() == null) {
    operation.addConsumes("application/x-www-form-urlencoded");
if (operation.getResponses() == null) {
  operation.defaultResponse(new Response().description("successful operation"));
final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
Path path = swagger.getPath(parsedPath);
if (path == null) {
  path = new SwaggerPath();
  swagger.path(parsedPath, path);
path.set(httpMethod.toLowerCase(), operation);

相关文章