Search in sources :

Example 16 with Reader

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

the class ConfigAndExtensionScannerTest method scanResourceWithExtensions.

@Test(description = "scan a resource with extensions")
public void scanResourceWithExtensions() {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(ResourceWithConfigAndExtensions.class);
    Swagger swagger = new Reader(new Swagger()).read(classes);
    assertEquals(swagger.getPaths().size(), 1);
    Info info = swagger.getInfo();
    assertNotNull(info);
    assertEquals(info.getDescription(), "Custom description");
    assertEquals(info.getTermsOfService(), "do-what-you-want");
    assertEquals(info.getTitle(), "TheAwesomeApi");
    assertEquals(info.getVersion(), "V1.2.3");
    assertEquals(info.getContact().getName(), "Sponge-Bob");
    assertEquals(info.getContact().getEmail(), "sponge-bob@swagger.io");
    assertEquals(info.getContact().getUrl(), "http://swagger.io");
    assertEquals(info.getLicense().getName(), "Apache 2.0");
    assertEquals(info.getLicense().getUrl(), "http://www.apache.org");
    assertEquals(swagger.getConsumes().size(), 2);
    assertTrue(swagger.getConsumes().contains("application/json"));
    assertTrue(swagger.getConsumes().contains("application/xml"));
    assertEquals(swagger.getProduces().size(), 2);
    swagger.getProduces().contains("application/json");
    swagger.getProduces().contains("application/xml");
    assertEquals(swagger.getExternalDocs().getDescription(), "test");
    assertEquals(swagger.getExternalDocs().getUrl(), "http://swagger.io");
    assertEquals(swagger.getSchemes().size(), 2);
    assertTrue(swagger.getSchemes().contains(Scheme.HTTP));
    assertTrue(swagger.getSchemes().contains(Scheme.HTTPS));
    assertEquals(swagger.getTags().size(), 7);
    assertEquals(swagger.getTags().get(0).getName(), "Tag-added-before-read");
    assertEquals(swagger.getTags().get(1).getName(), "mytag");
    assertEquals(swagger.getTags().get(1).getDescription(), "my tag");
    assertEquals(swagger.getTags().get(2).getName(), "anothertag");
    assertEquals(swagger.getTags().get(2).getDescription(), "another tag");
    assertEquals(swagger.getTags().get(2).getExternalDocs().getDescription(), "test");
    assertEquals(swagger.getTags().get(2).getExternalDocs().getUrl(), "http://swagger.io");
    assertEquals(swagger.getTags().get(3).getName(), "tagwithextensions");
    assertEquals(swagger.getTags().get(3).getDescription(), "my tag");
    Map<String, Object> extensions = swagger.getTags().get(3).getVendorExtensions();
    assertEquals(extensions.size(), 1);
    assertEquals(extensions.get("x-test"), "value");
    assertEquals(swagger.getTags().get(4).getName(), "externalinfo");
    assertEquals(swagger.getTags().get(5).getName(), "testingtag");
    assertEquals(swagger.getTags().get(6).getName(), "Tag-added-after-read");
    extensions = swagger.getInfo().getVendorExtensions();
    assertEquals(extensions.size(), 3);
    assertEquals(extensions.get("x-test1"), "value1");
    assertEquals(extensions.get("x-test2"), "value2");
    extensions = (Map<String, Object>) extensions.get("x-test");
    assertEquals(extensions.get("test1"), "value1");
    assertEquals(extensions.get("test2"), "value2");
    extensions = swagger.getPath("/who/cares").getOperations().get(0).getVendorExtensions();
    assertEquals(extensions.get("x-test"), "value");
    String json = Json.pretty(swagger);
    assertNotEquals(json.indexOf("\"x-test\" : {"), -1);
    assertNotEquals(json.indexOf("\"x-test1\" : \"value1\""), -1);
    assertNotEquals(json.indexOf("\"x-test2\" : \"value2\""), -1);
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Info(io.swagger.models.Info) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 17 with Reader

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

the class GenericsTest method scanModelWithGenericType.

@Test(description = "scan model with Generic Type")
public void scanModelWithGenericType() {
    final Swagger swagger = new Reader(new Swagger()).read(UserApiRoute.class);
    assertNotNull(swagger);
    final Model userEntity = swagger.getDefinitions().get("UserEntity");
    assertNotNull(userEntity);
    final Map<String, Property> properties = userEntity.getProperties();
    assertEquals(properties.size(), 2);
    assertNotNull(properties.get("id"));
    assertNotNull(properties.get("name"));
}
Also used : Swagger(io.swagger.models.Swagger) Model(io.swagger.models.Model) RefModel(io.swagger.models.RefModel) ArrayModel(io.swagger.models.ArrayModel) Reader(io.swagger.jaxrs.Reader) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) RefProperty(io.swagger.models.properties.RefProperty) Property(io.swagger.models.properties.Property) UUIDProperty(io.swagger.models.properties.UUIDProperty) Test(org.testng.annotations.Test)

Example 18 with Reader

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

the class OverriddenTypeTests method integerTypeOverrideTest.

@Test(description = "overrides a system-detected type")
public void integerTypeOverrideTest() {
    Swagger swagger = new Reader(new Swagger()).read(Resource469.class);
    QueryParameter qp = (QueryParameter) swagger.getPath("/test").getPut().getParameters().get(0);
    assertEquals(qp.getType(), "string");
    assertEquals(qp.getFormat(), "blah");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Example 19 with Reader

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

the class OverriddenTypeTests method integerFormatOverrideTest.

@Test(description = "overrides a system-detected format")
public void integerFormatOverrideTest() {
    Swagger swagger = new Reader(new Swagger()).read(Resource469.class);
    QueryParameter qp = (QueryParameter) swagger.getPath("/test").getPost().getParameters().get(0);
    assertEquals(qp.getFormat(), "int64");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Example 20 with Reader

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

the class OverriddenTypeTests method implicitParamTest.

@Test(description = "add a user-specified type with implicit annotation")
public void implicitParamTest() {
    Swagger swagger = new Reader(new Swagger()).read(Resource469.class);
    QueryParameter qp = (QueryParameter) swagger.getPath("/test2").getGet().getParameters().get(0);
    assertEquals(qp.getType(), "string");
    assertEquals(qp.getFormat(), "password");
}
Also used : QueryParameter(io.swagger.models.parameters.QueryParameter) Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Aggregations

Reader (io.swagger.jaxrs.Reader)33 Swagger (io.swagger.models.Swagger)31 Test (org.testng.annotations.Test)20 Parameter (io.swagger.models.parameters.Parameter)7 QueryParameter (io.swagger.models.parameters.QueryParameter)5 DefaultReaderConfig (io.swagger.jaxrs.config.DefaultReaderConfig)4 Operation (io.swagger.models.Operation)4 FormParameter (io.swagger.models.parameters.FormParameter)4 HeaderParameter (io.swagger.models.parameters.HeaderParameter)4 Test (org.junit.Test)4 Scanner (io.swagger.config.Scanner)3 SwaggerConfig (io.swagger.config.SwaggerConfig)3 Model (io.swagger.models.Model)3 Info (io.swagger.models.Info)2 NicknamedOperation (io.swagger.resources.NicknamedOperation)2 SwaggerDefinition (io.swagger.annotations.SwaggerDefinition)1 JaxrsScanner (io.swagger.jaxrs.config.JaxrsScanner)1 ReaderListener (io.swagger.jaxrs.config.ReaderListener)1 SwaggerContextService (io.swagger.jaxrs.config.SwaggerContextService)1 ArrayModel (io.swagger.models.ArrayModel)1