Search in sources :

Example 61 with Swagger

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

the class BeanConfig method scanAndRead.

public void scanAndRead() {
    Set<Class<?>> classes = classes();
    if (classes != null) {
        Swagger swagger = reader.read(classes);
        if (StringUtils.isNotBlank(host)) {
            swagger.setHost(host);
        }
        if (StringUtils.isNotBlank(basePath)) {
            swagger.setBasePath(basePath);
        }
        updateInfoFromConfig();
    }
}
Also used : Swagger(io.swagger.models.Swagger)

Example 62 with Swagger

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

the class BaseApiListingResource method process.

protected Swagger process(Application app, ServletContext servletContext, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) {
    SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
    Swagger swagger = ctxService.getSwagger();
    synchronized (ApiListingResource.class) {
        if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
            if (!initializedScanner.containsKey(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc))) {
                swagger = scan(app, servletContext, sc, uriInfo);
            }
        } else {
            if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
                if (!initializedConfig.containsKey(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc))) {
                    swagger = scan(app, servletContext, sc, uriInfo);
                }
            } else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
                if (!initializedConfig.containsKey(sc.getServletName() + "_" + ctxService.getBasePath())) {
                    swagger = scan(app, servletContext, sc, uriInfo);
                }
            } else if (!initialized) {
                swagger = scan(app, servletContext, sc, uriInfo);
            }
        }
    }
    if (swagger != null) {
        SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
        if (filterImpl != null) {
            SpecFilter f = new SpecFilter();
            swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
        }
    }
    return swagger;
}
Also used : SwaggerContextService(io.swagger.jaxrs.config.SwaggerContextService) Swagger(io.swagger.models.Swagger) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SpecFilter(io.swagger.core.filter.SpecFilter)

Example 63 with Swagger

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

the class JsonIdentityTest method scan.

@Test(description = "Scan API with operation and response references")
public void scan() throws IOException {
    final Swagger swagger = new Reader(new Swagger()).read(JsonIdentityResource.class);
    final String json = ResourceUtils.loadClassResource(getClass(), "ResourceWithJsonIdentity.json");
    SerializationMatchers.assertEqualsToJson(swagger, json);
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Example 64 with Swagger

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

the class ReaderTest method scanImplicitParamOverriddenMethodTest.

@Test(description = "scan indirect implicit params from overridden method")
public void scanImplicitParamOverriddenMethodTest() {
    final Swagger swagger = new Reader(new Swagger()).read(IndirectImplicitParamsImpl.class);
    assertNotNull(swagger);
    assertEquals(swagger.getPath("/v1/users").getPost().getParameters().size(), 2);
}
Also used : Swagger(io.swagger.models.Swagger) Reader(io.swagger.jaxrs.Reader) Test(org.testng.annotations.Test)

Example 65 with Swagger

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

the class ReaderTest method scanExternalDocsOnMethod.

@Test(description = "scan external docs on method")
public void scanExternalDocsOnMethod() {
    Swagger swagger = getSwagger(ResourceWithExternalDocs.class);
    ExternalDocs externalDocsForGet = swagger.getPath("/testString").getGet().getExternalDocs();
    assertNull(externalDocsForGet);
    ExternalDocs externalDocsForPost = swagger.getPath("/testString").getPost().getExternalDocs();
    assertNotNull(externalDocsForPost);
    assertEquals("Test Description", externalDocsForPost.getDescription());
    assertEquals("https://swagger.io/", externalDocsForPost.getUrl());
}
Also used : Swagger(io.swagger.models.Swagger) ResourceWithExternalDocs(io.swagger.resources.ResourceWithExternalDocs) ExternalDocs(io.swagger.models.ExternalDocs) Test(org.testng.annotations.Test)

Aggregations

Swagger (io.swagger.models.Swagger)184 Test (org.testng.annotations.Test)115 Operation (io.swagger.models.Operation)45 Parameter (io.swagger.models.parameters.Parameter)33 QueryParameter (io.swagger.models.parameters.QueryParameter)33 BodyParameter (io.swagger.models.parameters.BodyParameter)29 Path (io.swagger.models.Path)26 PathParameter (io.swagger.models.parameters.PathParameter)25 Reader (io.swagger.jaxrs.Reader)23 SpecFilter (io.swagger.core.filter.SpecFilter)21 Test (org.junit.Test)19 SwaggerParser (io.swagger.parser.SwaggerParser)16 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)16 Response (io.swagger.models.Response)14 SerializableParameter (io.swagger.models.parameters.SerializableParameter)14 HashMap (java.util.HashMap)14 Info (io.swagger.models.Info)12 Map (java.util.Map)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 Model (io.swagger.models.Model)10