Java Code Examples for io.swagger.models.Path#getPost()

The following examples show how to use io.swagger.models.Path#getPost() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwaggerUtils.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * Provide a method to validate swagger. This method is now implemented to check common errors, and the logic
 * will be changed when necessary. For internal use only.
 */
public static void validateSwagger(Swagger swagger) {
  Map<String, Path> paths = swagger.getPaths();
  if (paths == null) {
    return;
  }

  for (Path path : paths.values()) {
    Operation operation = path.getPost();
    if (operation == null) {
      continue;
    }

    for (Parameter parameter : operation.getParameters()) {
      if (BodyParameter.class.isInstance(parameter) &&
          ((BodyParameter) parameter).getSchema() == null) {
        throw new ServiceCombException("swagger validator: body parameter schema is empty.");
      }
    }
  }
}
 
Example 2
Source File: SwaggerEndpointSource.java    From light-rest-4j with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<Endpoint> listEndpoints() {

    List<Endpoint> endpoints = new ArrayList<>();
    String basePath = findBasePath();
    Map<String, Path> paths = SwaggerHelper.swagger.getPaths();

    if(log.isInfoEnabled()) log.info("Generating paths from Swagger spec");
    for (Map.Entry<String, Path> pathPair : paths.entrySet()) {
        String path = basePath + pathPair.getKey();
        Path pathImpl = pathPair.getValue();

        if(pathImpl.getGet() != null) addEndpoint(endpoints, path, "get");
        if(pathImpl.getPut() != null) addEndpoint(endpoints, path, "put");
        if(pathImpl.getHead() != null) addEndpoint(endpoints, path, "head");
        if(pathImpl.getPost() != null) addEndpoint(endpoints, path, "post");
        if(pathImpl.getDelete() != null) addEndpoint(endpoints, path, "delete");
        if(pathImpl.getPatch() != null) addEndpoint(endpoints, path, "patch");
        if(pathImpl.getOptions() != null) addEndpoint(endpoints, path, "options");
    }
    return endpoints;
}
 
Example 3
Source File: ProtoApiFromOpenApi.java    From api-compiler with Apache License 2.0 6 votes vote down vote up
private Path getNewWildCardPathObject(Path userDefinedWildCardPathObject) {
  Preconditions.checkNotNull(
      userDefinedWildCardPathObject, "userDefinedWildCardPathObject cannot be null");

  Path path = new Path();
  if (userDefinedWildCardPathObject.getGet() == null) {
    path.set("get", constructReservedOperation("Get"));
  }
  if (userDefinedWildCardPathObject.getDelete() == null) {
    path.set("delete", constructReservedOperation("Delete"));
  }
  if (userDefinedWildCardPathObject.getPatch() == null) {
    path.set("patch", constructReservedOperation("Patch"));
  }
  if (userDefinedWildCardPathObject.getPost() == null) {
    path.set("post", constructReservedOperation("Post"));
  }
  if (userDefinedWildCardPathObject.getPut() == null) {
    path.set("put", constructReservedOperation("Put"));
  }
  return path;
}
 
Example 4
Source File: TestApiOperation.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
private void testPrimitive(Path path) {
  Operation operation = path.getPost();

  Assert.assertEquals(2, operation.getResponses().size());

  ModelImpl result200 = (ModelImpl) operation.getResponses().get("200").getResponseSchema();
  Assert.assertEquals("integer", result200.getType());
  Assert.assertEquals("int32", result200.getFormat());

  ModelImpl result202 = (ModelImpl) operation.getResponses().get("202").getResponseSchema();
  Assert.assertEquals("string", result202.getType());
  Assert.assertEquals(null, result202.getFormat());
}
 
Example 5
Source File: PathUtils.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the operations of a path as a map which preserves the insertion order.
 *
 * @param path the path
 * @return the operations of a path as a map
 */
private static Map<HttpMethod, Operation> getOperationMap(Path path) {
    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());
    }

    return result;
}
 
Example 6
Source File: TestApiOperation.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private void testSet(Path path) {
  Operation operation = path.getPost();
  Model result200 = operation.getResponses().get("200").getResponseSchema();
  Assert.assertEquals(ArrayModel.class, result200.getClass());
  Assert.assertEquals(true, ((ArrayModel) result200).getUniqueItems());
}
 
Example 7
Source File: TestApiOperation.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private void testList(Path path) {
  Operation operation = path.getPost();
  Model result200 = operation.getResponses().get("200").getResponseSchema();
  Assert.assertEquals(ArrayModel.class, result200.getClass());
  Assert.assertEquals(null, ((ArrayModel) result200).getUniqueItems());
}
 
Example 8
Source File: TestApiOperation.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
private void testMap(Path path) {
  Operation operation = path.getPost();
  Model result200 = operation.getResponses().get("200").getResponseSchema();
  Assert.assertEquals(ModelImpl.class, result200.getClass());
  Assert.assertTrue(((ModelImpl) result200).getAdditionalProperties() != null);
}
 
Example 9
Source File: SwaggerConverter.java    From swagger-parser with Apache License 2.0 4 votes vote down vote up
public PathItem convert(Path v2Path) {
    PathItem v3Path = new PathItem();

    if (v2Path instanceof RefPath) {

        v3Path.set$ref(((RefPath) v2Path).get$ref());
    } else {

        if (v2Path.getParameters() != null) {
            for (io.swagger.models.parameters.Parameter param : v2Path.getParameters()) {
                v3Path.addParametersItem(convert(param));
            }
        }

        io.swagger.models.Operation v2Operation;

        v2Operation = v2Path.getGet();
        if (v2Operation != null) {
            v3Path.setGet(convert(v2Operation));
        }
        v2Operation = v2Path.getPut();
        if (v2Operation != null) {
            v3Path.setPut(convert(v2Operation));
        }
        v2Operation = v2Path.getPost();
        if (v2Operation != null) {
            v3Path.setPost(convert(v2Operation));
        }
        v2Operation = v2Path.getPatch();
        if (v2Operation != null) {
            v3Path.setPatch(convert(v2Operation));
        }
        v2Operation = v2Path.getDelete();
        if (v2Operation != null) {
            v3Path.setDelete(convert(v2Operation));
        }
        v2Operation = v2Path.getHead();
        if (v2Operation != null) {
            v3Path.setHead(convert(v2Operation));
        }
        v2Operation = v2Path.getOptions();
        if (v2Operation != null) {
            v3Path.setOptions(convert(v2Operation));
        }

        v3Path.setExtensions(convert(v2Path.getVendorExtensions()));
    }

    return v3Path;
}