use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class ReaderTest method testCompleteReadClass.
@Test(description = "scan methods")
public void testCompleteReadClass() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(CompleteFieldsResource.class);
Paths paths = openAPI.getPaths();
assertEquals(PATHS_NUMBER, paths.size());
PathItem pathItem = paths.get(PATH_REF);
assertNotNull(pathItem);
assertNull(pathItem.getPost());
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(OPERATION_SUMMARY, operation.getSummary());
assertEquals(OPERATION_DESCRIPTION, operation.getDescription());
assertEquals(TAG_NUMBER, operation.getTags().size());
assertEquals(EXAMPLE_TAG, operation.getTags().get(0));
assertEquals(SECOND_TAG, operation.getTags().get(1));
ExternalDocumentation externalDocs = operation.getExternalDocs();
assertEquals(EXTERNAL_DOCS_DESCRIPTION, externalDocs.getDescription());
assertEquals(EXTERNAL_DOCS_URL, externalDocs.getUrl());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class ReaderTest method test2818.
@Test(description = "test ticket #2818 @Parameter annotation")
public void test2818() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(Ticket2818Resource.class);
Paths paths = openAPI.getPaths();
assertEquals(paths.size(), 1);
PathItem pathItem = paths.get("/bookstore/{id}");
assertNotNull(pathItem);
Operation operation = pathItem.getGet();
assertNotNull(operation);
assertEquals(operation.getParameters().get(0).getSchema().getType(), "integer");
assertEquals(operation.getParameters().get(0).getSchema().getFormat(), "int32");
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class ReaderTest method testGetCallbacks.
@Test(description = "Callbacks")
public void testGetCallbacks() {
Reader reader = new Reader(new OpenAPI());
Method[] methods = SimpleCallbackResource.class.getMethods();
Operation callbackOperation = reader.parseMethod(methods[0], null, null);
assertNotNull(callbackOperation);
Map<String, Callback> callbacks = callbackOperation.getCallbacks();
assertNotNull(callbacks);
Callback callback = callbacks.get(CALLBACK_SUBSCRIPTION_ID);
assertNotNull(callback);
PathItem pathItem = callback.get(CALLBACK_URL);
assertNotNull(pathItem);
Operation postOperation = pathItem.getPost();
assertNotNull(postOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, postOperation.getDescription());
Operation getOperation = pathItem.getGet();
assertNotNull(getOperation);
assertEquals(CALLBACK_GET_OPERATION_DESCRIPTION, getOperation.getDescription());
Operation putOperation = pathItem.getPut();
assertNotNull(putOperation);
assertEquals(CALLBACK_POST_OPERATION_DESCRIPTION, putOperation.getDescription());
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class SpecFilter method addPathItemSchemaRef.
private void addPathItemSchemaRef(PathItem pathItem, Set<String> referencedDefinitions) {
if (pathItem.getParameters() != null) {
for (Parameter parameter : pathItem.getParameters()) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
}
}
Map<PathItem.HttpMethod, Operation> ops = pathItem.readOperationsMap();
for (Operation op : ops.values()) {
if (op.getRequestBody() != null) {
addContentSchemaRef(op.getRequestBody().getContent(), referencedDefinitions);
}
if (op.getResponses() != null) {
for (String keyResponses : op.getResponses().keySet()) {
ApiResponse response = op.getResponses().get(keyResponses);
if (response.getHeaders() != null) {
for (String keyHeaders : response.getHeaders().keySet()) {
Header header = response.getHeaders().get(keyHeaders);
addSchemaRef(header.getSchema(), referencedDefinitions);
addContentSchemaRef(header.getContent(), referencedDefinitions);
}
}
addContentSchemaRef(response.getContent(), referencedDefinitions);
}
}
if (op.getParameters() != null) {
for (Parameter parameter : op.getParameters()) {
addSchemaRef(parameter.getSchema(), referencedDefinitions);
addContentSchemaRef(parameter.getContent(), referencedDefinitions);
}
}
if (op.getCallbacks() != null) {
for (String keyCallback : op.getCallbacks().keySet()) {
Callback callback = op.getCallbacks().get(keyCallback);
for (PathItem callbackPathItem : callback.values()) {
addPathItemSchemaRef(callbackPathItem, referencedDefinitions);
}
}
}
}
}
use of io.swagger.v3.oas.models.PathItem in project swagger-core by swagger-api.
the class SpecFilter method filterPathItem.
protected PathItem filterPathItem(OpenAPISpecFilter filter, PathItem pathItem, String resourcePath, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
ApiDescription description = new ApiDescription(resourcePath, null);
Optional<PathItem> filteredPathItem = filter.filterPathItem(pathItem, description, params, cookies, headers);
if (filteredPathItem.isPresent()) {
return filteredPathItem.get();
}
return null;
}
Aggregations