Search in sources :

Example 26 with Swagger

use of io.swagger.models.Swagger in project swagger-core by swagger-api.

the class FormDataBodyPartTest method testFormDataBodyPart.

@Test(description = "FormDataBodyPart should be ignored when generating the Swagger document")
public void testFormDataBodyPart() {
    final Swagger swagger = new Reader(new Swagger()).read(ResourceWithFormData.class);
    final List<Parameter> parameters = swagger.getPath("/test/document/{documentName}.json").getPost().getParameters();
    assertEquals(parameters.size(), 3);
    assertEquals(parameters.get(0).getName(), "documentName");
    assertEquals(parameters.get(1).getName(), "input");
    assertEquals(parameters.get(2).getName(), "id");
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Parameter(io.swagger.models.parameters.Parameter) Test(org.testng.annotations.Test)

Example 27 with Swagger

use of io.swagger.models.Swagger in project swagger-core by swagger-api.

the class ScannerTest method scanAnotherResource.

@Test(description = "scan another resource")
public void scanAnotherResource() {
    final Swagger swagger = getSwagger(ResourceWithComplexBodyInputType.class);
    final Operation post = swagger.getPaths().get("/myapi/testPostWithBody").getPost();
    assertNotNull(post);
    assertNotNull(swagger.getDefinitions());
    assertNotNull(swagger.getDefinitions().get("ClassWithString"));
}
Also used : Swagger(io.swagger.models.Swagger) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 28 with Swagger

use of io.swagger.models.Swagger in project swagger-core by swagger-api.

the class ScannerTest method scanBeanParamResource.

@Test(description = "scan a bean param resource")
public void scanBeanParamResource() {
    final Swagger swagger = getSwagger(ResourceWithBeanParams.class);
    final List<Parameter> params = getParameters(swagger, "/bean/{id}");
    final HeaderParameter headerParam1 = (HeaderParameter) params.get(0);
    assertEquals(headerParam1.getDefaultValue(), 1);
    assertEquals(headerParam1.getName(), "test order annotation 1");
    final HeaderParameter headerParam2 = (HeaderParameter) params.get(1);
    assertEquals(headerParam2.getDefaultValue(), 2);
    assertEquals(headerParam2.getName(), "test order annotation 2");
    final QueryParameter priority1 = (QueryParameter) params.get(2);
    assertNull(priority1.getDefaultValue());
    assertEquals(priority1.getName(), "test priority 1");
    final QueryParameter priority2 = (QueryParameter) params.get(3);
    assertEquals(priority2.getDefaultValue(), 4);
    assertEquals(priority2.getName(), "test priority 2");
    final ModelImpl bodyParam1 = (ModelImpl) ((BodyParameter) params.get(4)).getSchema();
    assertEquals(bodyParam1.getDefaultValue(), "bodyParam");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) BodyParameter(io.swagger.models.parameters.BodyParameter) Parameter(io.swagger.models.parameters.Parameter) QueryParameter(io.swagger.models.parameters.QueryParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) HeaderParameter(io.swagger.models.parameters.HeaderParameter) ModelImpl(io.swagger.models.ModelImpl) Test(org.testng.annotations.Test)

Example 29 with Swagger

use of io.swagger.models.Swagger in project swagger-core by swagger-api.

the class ScannerTest method scanResourceWithExtensions.

@Test(description = "scan resource with extensions")
public void scanResourceWithExtensions() throws JsonProcessingException {
    final Swagger swagger = getSwagger(ResourceWithExtensions.class);
    assertNotNull(swagger);
    Map<String, Object> infoExtensions = swagger.getInfo().getVendorExtensions();
    assertEquals("private", infoExtensions.get("x-accessLevel"));
    Map<String, Object> operationExtensions = swagger.getPath("/rest/test").getGet().getVendorExtensions();
    assertEquals("/hello-world/v1/", operationExtensions.get("x-externalPath"));
}
Also used : Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Example 30 with Swagger

use of io.swagger.models.Swagger in project swagger-core by swagger-api.

the class ReaderTest method scanEmptyPathAnnotation.

@Test(description = "scan empty path annotation")
public void scanEmptyPathAnnotation() {
    Swagger swagger = getSwagger(ResourceWithEmptyPath.class);
    assertNotNull(getGet(swagger, "/"));
}
Also used : Swagger(io.swagger.models.Swagger) Test(org.testng.annotations.Test)

Aggregations

Swagger (io.swagger.models.Swagger)164 Test (org.testng.annotations.Test)114 Operation (io.swagger.models.Operation)39 Parameter (io.swagger.models.parameters.Parameter)30 QueryParameter (io.swagger.models.parameters.QueryParameter)30 BodyParameter (io.swagger.models.parameters.BodyParameter)26 Reader (io.swagger.jaxrs.Reader)23 PathParameter (io.swagger.models.parameters.PathParameter)22 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 Path (io.swagger.models.Path)18 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10 NicknamedOperation (io.swagger.resources.NicknamedOperation)10 HeaderParameter (io.swagger.models.parameters.HeaderParameter)9 BeanConfig (io.swagger.jaxrs.config.BeanConfig)8 Map (java.util.Map)8 Info (io.swagger.models.Info)7