Search in sources :

Example 51 with PathItem

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());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ExternalDocumentation(io.swagger.v3.oas.models.ExternalDocumentation) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 52 with PathItem

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");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Paths(io.swagger.v3.oas.models.Paths) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 53 with PathItem

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());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Method(java.lang.reflect.Method) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 54 with PathItem

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);
                }
            }
        }
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Header(io.swagger.v3.oas.models.headers.Header) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Example 55 with PathItem

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;
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ApiDescription(io.swagger.v3.core.model.ApiDescription)

Aggregations

PathItem (io.swagger.v3.oas.models.PathItem)66 Operation (io.swagger.v3.oas.models.Operation)52 OpenAPI (io.swagger.v3.oas.models.OpenAPI)50 Test (org.testng.annotations.Test)39 Paths (io.swagger.v3.oas.models.Paths)24 Map (java.util.Map)19 HashMap (java.util.HashMap)18 Schema (io.swagger.v3.oas.models.media.Schema)16 Components (io.swagger.v3.oas.models.Components)15 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)14 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)14 LinkedHashMap (java.util.LinkedHashMap)14 ArrayList (java.util.ArrayList)11 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)10 Parameter (io.swagger.v3.oas.models.parameters.Parameter)10 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 MediaType (io.swagger.v3.oas.models.media.MediaType)8 HttpMethod (io.swagger.models.HttpMethod)7 Callback (io.swagger.v3.oas.models.callbacks.Callback)7 Content (io.swagger.v3.oas.models.media.Content)7