Search in sources :

Example 11 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testAnotherResourceWithSubresources.

@Test(description = "test another resource with subresources")
public void testAnotherResourceWithSubresources() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(TestResource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 3);
    PathItem pathItem = paths.get("/test/status");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
    Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
    pathItem = paths.get("/test/more/otherStatus");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
    assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
    schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
    pathItem = paths.get("/test/evenmore/otherStatus");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
    assertFalse(operation.getResponses().getDefault().getContent().keySet().contains("application/xml"));
    schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
    assertEquals(operation.getRequestBody().getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/Pet");
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) 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 12 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testScanMethods.

@Test(description = "scan methods")
public void testScanMethods() {
    Reader reader = new Reader(new OpenAPI());
    Method[] methods = SimpleMethods.class.getMethods();
    for (final Method method : methods) {
        if (isValidRestPath(method)) {
            Operation operation = reader.parseMethod(method, null, null);
            assertNotNull(operation);
        }
    }
}
Also used : 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 13 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testExtensions.

@Test(description = "Extensions Tests")
public void testExtensions() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(ExtensionsResource.class);
    assertNotNull(openAPI);
    SerializationMatchers.assertEqualsToYaml(openAPI, ExtensionsResource.YAML);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 14 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method testSubscriptionIdParam.

@Test(description = "Get the Param of an operation")
public void testSubscriptionIdParam() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(BasicFieldsResource.class);
    assertNotNull(openAPI);
    Paths openAPIPaths = openAPI.getPaths();
    assertNotNull(openAPIPaths);
    PathItem pathItem = openAPIPaths.get(PATH_1_REF);
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    List<Parameter> parameters = operation.getParameters();
    assertNotNull(parameters);
    assertEquals(PARAMETER_NUMBER, parameters.size());
    Parameter parameter = parameters.get(0);
    assertNotNull(parameter);
    assertEquals(PARAMETER_IN, parameter.getIn());
    assertEquals(PARAMETER_NAME, parameter.getName());
    assertEquals(PARAMETER_DESCRIPTION, parameter.getDescription());
    assertEquals(Boolean.TRUE, parameter.getRequired());
    assertEquals(Boolean.TRUE, parameter.getAllowEmptyValue());
    assertEquals(Boolean.TRUE, parameter.getAllowReserved());
    Schema schema = parameter.getSchema();
    assertNotNull(schema);
    assertEquals(SCHEMA_TYPE, schema.getType());
    assertEquals(SCHEMA_FORMAT, schema.getFormat());
    assertEquals(SCHEMA_DESCRIPTION, schema.getDescription());
    assertEquals(Boolean.TRUE, schema.getReadOnly());
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) Parameter(io.swagger.v3.oas.models.parameters.Parameter) 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 15 with Reader

use of io.swagger.v3.jaxrs2.Reader in project swagger-core by swagger-api.

the class ReaderTest method test2646.

@Test(description = "test ticket #2646 method annotated with @Produce")
public void test2646() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(BookStoreTicket2646.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 2);
    PathItem pathItem = paths.get("/bookstore");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("application/json"));
    pathItem = paths.get("/bookstore/{id}");
    assertNotNull(pathItem);
    operation = pathItem.getDelete();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
}
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)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)85 Test (org.testng.annotations.Test)81 Operation (io.swagger.v3.oas.models.Operation)24 PathItem (io.swagger.v3.oas.models.PathItem)17 Info (io.swagger.v3.oas.models.info.Info)17 Components (io.swagger.v3.oas.models.Components)15 Paths (io.swagger.v3.oas.models.Paths)15 Reader (io.swagger.v3.jaxrs2.Reader)11 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)9 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)8 Schema (io.swagger.v3.oas.models.media.Schema)8 Parameter (io.swagger.v3.oas.models.parameters.Parameter)7 Method (java.lang.reflect.Method)7 SwaggerConfiguration (io.swagger.v3.oas.integration.SwaggerConfiguration)5 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)4 SpecFilter (io.swagger.v3.core.filter.SpecFilter)4 AbstractAnnotationTest (io.swagger.v3.jaxrs2.annotations.AbstractAnnotationTest)4 GenericOpenApiContext (io.swagger.v3.oas.integration.GenericOpenApiContext)4 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)4