Java Code Examples for io.swagger.v3.oas.models.PathItem#getPost()

The following examples show how to use io.swagger.v3.oas.models.PathItem#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: OperationBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Extract operation id from path item set.
 *
 * @param path the path
 * @return the set
 */
private Set<String> extractOperationIdFromPathItem(PathItem path) {
	Set<String> ids = new HashSet<>();
	if (path.getGet() != null && StringUtils.isNotBlank(path.getGet().getOperationId())) {
		ids.add(path.getGet().getOperationId());
	}
	if (path.getPost() != null && StringUtils.isNotBlank(path.getPost().getOperationId())) {
		ids.add(path.getPost().getOperationId());
	}
	if (path.getPut() != null && StringUtils.isNotBlank(path.getPut().getOperationId())) {
		ids.add(path.getPut().getOperationId());
	}
	if (path.getDelete() != null && StringUtils.isNotBlank(path.getDelete().getOperationId())) {
		ids.add(path.getDelete().getOperationId());
	}
	if (path.getOptions() != null && StringUtils.isNotBlank(path.getOptions().getOperationId())) {
		ids.add(path.getOptions().getOperationId());
	}
	if (path.getHead() != null && StringUtils.isNotBlank(path.getHead().getOperationId())) {
		ids.add(path.getHead().getOperationId());
	}
	if (path.getPatch() != null && StringUtils.isNotBlank(path.getPatch().getOperationId())) {
		ids.add(path.getPatch().getOperationId());
	}
	return ids;
}
 
Example 2
Source File: RequestParameterTest.java    From cruise-control with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Return the list of parameters given the path item (an endpoint)
 *
 * @param pathItem Endpoint defined as a PathItem object
 * @return set of parameters for the specified endpoint
 */
public static Set<String> parseEndpoint(PathItem pathItem) throws IllegalArgumentException {
  List<Parameter> parameterList;
  Set<String> parameterSet = new TreeSet<>();
  if (pathItem.getGet() != null) {
    parameterList = pathItem.getGet().getParameters();
  } else if (pathItem.getPost() != null) {
    parameterList = pathItem.getPost().getParameters();
  } else {
    throw new IllegalArgumentException("Schema Parser does not support HTTP methods other than GET/POST");
  }

  for (Parameter parameter : parameterList) {
    Assert.assertFalse(parameterSet.contains(parameter.getName()));
    parameterSet.add(parameter.getName());
  }
  return parameterSet;
}
 
Example 3
Source File: ResponseTest.java    From cruise-control with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Check the consistency for all POST and GET endpoints defined in OpenAPI spec.
 */
@Test
public void checkOpenAPISpec() {
  ParseOptions options = new ParseOptions();
  options.setResolve(true);
  options.setFlatten(true);
  _openAPI = new OpenAPIV3Parser().read(OPENAPI_SPEC_PATH, null, options);
  for (PathItem path : _openAPI.getPaths().values()) {
    if (path.getGet() != null) {
      checkOperation(path.getGet());
    }
    if (path.getPost() != null) {
      checkOperation(path.getPost());
    }
  }
}
 
Example 4
Source File: OperationHelper.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
public List<OperationModel> getAllOperations(PathItem path, String url) {
    List<OperationModel> operations = new LinkedList<OperationModel>();

    if (path.getGet() != null) {
        operations.add(new OperationModel(url, path.getGet(), RequestMethod.GET));
    }
    if (path.getPost() != null) {
        operations.add(new OperationModel(url, path.getPost(), RequestMethod.POST));
    }
    if (path.getPut() != null) {
        operations.add(new OperationModel(url, path.getPut(), RequestMethod.PUT));
    }
    if (path.getHead() != null) {
        operations.add(new OperationModel(url, path.getHead(), RequestMethod.HEAD));
    }
    if (path.getOptions() != null) {
        operations.add(new OperationModel(url, path.getOptions(), RequestMethod.OPTION));
    }
    if (path.getDelete() != null) {
        operations.add(new OperationModel(url, path.getDelete(), RequestMethod.DELETE));
    }
    if (path.getPatch() != null) {
        operations.add(new OperationModel(url, path.getPatch(), RequestMethod.PATCH));
    }
    if (operations.isEmpty()) {
        log.debug("Failed to find any operations for url=" + url + " path=" + path);
    }

    return operations;
}
 
Example 5
Source File: AbstractEndpointGenerationTest.java    From flow with Apache License 2.0 4 votes vote down vote up
private void assertPath(Class<?> testEndpointClass,
        Method expectedEndpointMethod, PathItem actualPath) {
    Operation actualOperation = actualPath.getPost();
    assertEquals("Unexpected tag in the OpenAPI spec",
            actualOperation.getTags(),
            Collections.singletonList(testEndpointClass.getSimpleName()));
    assertTrue(String.format(
            "Unexpected OpenAPI operation id: does not contain the endpoint name of the class '%s'",
            testEndpointClass.getSimpleName()),
            actualOperation.getOperationId()
                    .contains(getEndpointName(testEndpointClass)));
    assertTrue(String.format(
            "Unexpected OpenAPI operation id: does not contain the name of the endpoint method '%s'",
            expectedEndpointMethod.getName()),
            actualOperation.getOperationId()
                    .contains(expectedEndpointMethod.getName()));

    if (expectedEndpointMethod.getParameterCount() > 0) {
        Schema requestSchema = extractSchema(
                actualOperation.getRequestBody().getContent());
        assertRequestSchema(requestSchema,
                expectedEndpointMethod.getParameterTypes(),
                expectedEndpointMethod.getParameters());
    } else {
        assertNull(String.format(
                "No request body should be present in path schema for endpoint method with no parameters, method: '%s'",
                expectedEndpointMethod), actualOperation.getRequestBody());
    }

    ApiResponses responses = actualOperation.getResponses();
    assertEquals(
            "Every operation is expected to have a single '200' response",
            1, responses.size());
    ApiResponse apiResponse = responses.get("200");
    assertNotNull(
            "Every operation is expected to have a single '200' response",
            apiResponse);

    if (expectedEndpointMethod.getReturnType() != void.class) {
        assertSchema(extractSchema(apiResponse.getContent()),
                expectedEndpointMethod.getReturnType());
    } else {
        assertNull(String.format(
                "No response is expected to be present for void method '%s'",
                expectedEndpointMethod), apiResponse.getContent());
    }

    assertNotNull(
            "Non-anonymous endpoint method should have a security data defined for it in the schema",
            actualOperation.getSecurity());
}