Search in sources :

Example 91 with Swagger

use of io.swagger.models.Swagger in project carbon-apimgt by wso2.

the class DynamicHtmlGenTestCase method testPreprocessSwagger.

@Test
public void testPreprocessSwagger() throws Exception {
    DynamicHtmlGen htmlGen = new DynamicHtmlGen();
    Swagger swagger = new Swagger();
    Path path = new Path();
    Operation operation = new Operation();
    List<String> tags = new ArrayList<>();
    tags.add("tag1");
    tags.add("tag2");
    tags.add("tag3");
    tags.add("tag4");
    operation.setTags(tags);
    path.setGet(operation);
    swagger.path("get_sample", path);
    htmlGen.preprocessSwagger(swagger);
    List<String> processedTags = swagger.getPath("get_sample").getGet().getTags();
    Assert.assertEquals(processedTags.size(), 1);
    Assert.assertEquals(processedTags.get(0), "tag1");
}
Also used : Path(io.swagger.models.Path) DynamicHtmlGen(org.wso2.carbon.apimgt.rest.api.common.codegen.DynamicHtmlGen) Swagger(io.swagger.models.Swagger) ArrayList(java.util.ArrayList) CodegenOperation(io.swagger.codegen.CodegenOperation) Operation(io.swagger.models.Operation) Test(org.testng.annotations.Test)

Example 92 with Swagger

use of io.swagger.models.Swagger in project ORCID-Source by ORCID.

the class SwaggerJSONResource method getListingYaml.

@GET
@Produces("application/yaml")
@Path(OrcidApiConstants.SWAGGER_FILE_YAML)
@ApiOperation(value = "The swagger definition in YAML", hidden = true)
public Response getListingYaml(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
    Swagger swagger = (Swagger) context.getAttribute("swagger");
    if (!initialized) {
        swagger = scan(app);
    }
    try {
        if (swagger != null) {
            SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
            LOGGER.debug("using filter " + filterImpl);
            if (filterImpl != null) {
                SpecFilter f = new SpecFilter();
                swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
            }
            String yaml = Yaml.mapper().writeValueAsString(swagger);
            String[] parts = yaml.split("\n");
            StringBuilder b = new StringBuilder();
            for (String part : parts) {
                //int pos = part.indexOf("!<");
                //int endPos = part.indexOf(">");
                b.append(part);
                b.append("\n");
            }
            return Response.ok().entity(b.toString()).type("application/yaml").build();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return Response.status(404).build();
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SpecFilter(io.swagger.core.filter.SpecFilter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 93 with Swagger

use of io.swagger.models.Swagger in project ORCID-Source by ORCID.

the class SwaggerJSONResource method getListingJson.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(OrcidApiConstants.SWAGGER_FILE)
@ApiOperation(value = "The swagger definition in JSON", hidden = true)
public Response getListingJson(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
    Swagger swagger = (Swagger) context.getAttribute("swagger");
    if (!initialized) {
        swagger = scan(app);
    }
    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 Response.ok().entity(swagger).build();
    } else {
        return Response.status(404).build();
    }
}
Also used : Swagger(io.swagger.models.Swagger) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SwaggerSpecFilter(io.swagger.core.filter.SwaggerSpecFilter) SpecFilter(io.swagger.core.filter.SpecFilter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 94 with Swagger

use of io.swagger.models.Swagger in project ORCID-Source by ORCID.

the class MemberSwaggerResource method scan.

/**
     * Scan the classes and add in the OAuth information
     * 
     */
@Override
protected synchronized Swagger scan(Application app) {
    // tell swagger to pick up our jaxb annotations
    Json.mapper().registerModule(new JaxbAnnotationModule());
    Swagger s = super.scan(app);
    OAuth2Definition oauth = new OAuth2Definition();
    oauth.accessCode(this.authEndPoint, this.tokenEndPoint);
    oauth.scope(ScopePathType.READ_LIMITED.value(), "Read Limited record");
    oauth.scope(ScopePathType.PERSON_UPDATE.value(), "Update person");
    oauth.scope(ScopePathType.ACTIVITIES_UPDATE.value(), "Update activities");
    s.securityDefinition("orcid_auth", oauth);
    OAuth2Definition oauthTwoLegs = new OAuth2Definition();
    oauthTwoLegs.application(this.tokenEndPoint);
    oauthTwoLegs.scope(ScopePathType.PREMIUM_NOTIFICATION.value(), "Notifications");
    oauthTwoLegs.scope(ScopePathType.READ_PUBLIC.value(), "Read Public record");
    oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_READ.value(), "Read groups");
    oauthTwoLegs.scope(ScopePathType.GROUP_ID_RECORD_UPDATE.value(), "Update groups");
    s.securityDefinition("orcid_two_legs", oauthTwoLegs);
    return s;
}
Also used : JaxbAnnotationModule(com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule) Swagger(io.swagger.models.Swagger) OAuth2Definition(io.swagger.models.auth.OAuth2Definition)

Example 95 with Swagger

use of io.swagger.models.Swagger in project camel by apache.

the class RestSwaggerReader method read.

/**
     * Read the REST-DSL definition's and parse that as a Swagger model representation
     *
     * @param rests             the rest-dsl
     * @param route             optional route path to filter the rest-dsl to only include from the chose route
     * @param config            the swagger configuration
     * @param classResolver     class resolver to use
     * @return the swagger model
     */
public Swagger read(List<RestDefinition> rests, String route, BeanConfig config, String camelContextId, ClassResolver classResolver) {
    Swagger swagger = new Swagger();
    for (RestDefinition rest : rests) {
        if (ObjectHelper.isNotEmpty(route) && !route.equals("/")) {
            // filter by route
            if (!rest.getPath().equals(route)) {
                continue;
            }
        }
        parse(swagger, rest, camelContextId, classResolver);
    }
    // configure before returning
    swagger = config.configure(swagger);
    return swagger;
}
Also used : RestDefinition(org.apache.camel.model.rest.RestDefinition) Swagger(io.swagger.models.Swagger)

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