Search in sources :

Example 21 with Paths

use of io.swagger.v3.oas.models.Paths 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 22 with Paths

use of io.swagger.v3.oas.models.Paths 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 23 with Paths

use of io.swagger.v3.oas.models.Paths 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)

Example 24 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class ReaderTest method testSimpleReadClass.

@Test(description = "test a simple resource class")
public void testSimpleReadClass() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(BasicFieldsResource.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 6);
    PathItem pathItem = paths.get(PATH_1_REF);
    assertNotNull(pathItem);
    assertNull(pathItem.getPost());
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertEquals(OPERATION_SUMMARY, operation.getSummary());
    assertEquals(OPERATION_DESCRIPTION, operation.getDescription());
}
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 25 with Paths

use of io.swagger.v3.oas.models.Paths in project swagger-core by swagger-api.

the class ReaderTest method testResourceWithClassBasedSubresources.

@Test(description = "scan resource with class-based sub-resources")
public void testResourceWithClassBasedSubresources() {
    Reader reader = new Reader(new OpenAPI());
    OpenAPI openAPI = reader.read(SubResourceHead.class);
    Paths paths = openAPI.getPaths();
    assertEquals(paths.size(), 3);
    PathItem pathItem = paths.get("/head/tail/hello");
    assertNotNull(pathItem);
    Operation operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
    Schema schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
    pathItem = paths.get("/head/tail/{string}");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
    schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
    pathItem = paths.get("/head/noPath");
    assertNotNull(pathItem);
    operation = pathItem.getGet();
    assertNotNull(operation);
    assertTrue(operation.getResponses().getDefault().getContent().keySet().contains("*/*"));
    schema = operation.getResponses().getDefault().getContent().values().iterator().next().getSchema();
    assertNotNull(schema);
    assertEquals(schema.getType(), "string");
}
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)

Aggregations

Test (org.testng.annotations.Test)154 OpenAPI (io.swagger.v3.oas.models.OpenAPI)145 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)75 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)70 PathItem (io.swagger.v3.oas.models.PathItem)61 Operation (io.swagger.v3.oas.models.Operation)46 Paths (io.swagger.v3.oas.models.Paths)45 Schema (io.swagger.v3.oas.models.media.Schema)40 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)36 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)33 Components (io.swagger.v3.oas.models.Components)32 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)27 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)27 StringSchema (io.swagger.v3.oas.models.media.StringSchema)25 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)23 Parameter (io.swagger.v3.oas.models.parameters.Parameter)23 Info (io.swagger.v3.oas.models.info.Info)21 MapSchema (io.swagger.v3.oas.models.media.MapSchema)21 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)21 DateSchema (io.swagger.v3.oas.models.media.DateSchema)19