Search in sources :

Example 81 with Info

use of io.swagger.v3.oas.models.info.Info in project atlasmap by atlasmap.

the class AtlasService method processMappingRequest.

/**
 * Processes mapping by feeding input data.
 * @param request request
 * @param uriInfo URI info
 * @return {@link ProcessMappingResponse} which holds the result of the mappings
 */
@PUT
@Path("/mapping/process")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Process Mapping", description = "Process Mapping by feeding input data")
@RequestBody(description = "Mapping file content", content = @Content(schema = @Schema(implementation = AtlasMapping.class)))
@ApiResponses({ @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ProcessMappingResponse.class)), description = "Return a mapping result"), @ApiResponse(responseCode = "204", description = "Skipped empty mapping execution") })
public Response processMappingRequest(InputStream request, @Context UriInfo uriInfo) {
    ProcessMappingRequest pmr = fromJson(request, ProcessMappingRequest.class);
    if (pmr.getAtlasMapping() != null) {
        throw new WebApplicationException("Whole mapping execution is not yet supported");
    }
    Mapping mapping = pmr.getMapping();
    if (mapping == null) {
        return Response.noContent().build();
    }
    Audits audits = null;
    try {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Preview request: {}", new String(toJson(mapping)));
        }
        audits = previewContext.processPreview(mapping);
    } catch (AtlasException e) {
        throw new WebApplicationException("Unable to process mapping preview", e);
    }
    ProcessMappingResponse response = new ProcessMappingResponse();
    response.setMapping(mapping);
    if (audits != null) {
        response.setAudits(audits);
    }
    byte[] serialized = toJson(response);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Preview outcome: {}", new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : Audits(io.atlasmap.v2.Audits) WebApplicationException(javax.ws.rs.WebApplicationException) ProcessMappingResponse(io.atlasmap.v2.ProcessMappingResponse) Mapping(io.atlasmap.v2.Mapping) AtlasMapping(io.atlasmap.v2.AtlasMapping) AtlasException(io.atlasmap.api.AtlasException) ProcessMappingRequest(io.atlasmap.v2.ProcessMappingRequest) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) RequestBody(io.swagger.v3.oas.annotations.parameters.RequestBody)

Example 82 with Info

use of io.swagger.v3.oas.models.info.Info in project atlasmap by atlasmap.

the class AtlasService method listLibraryClasses.

/**
 * Retrieves a list of available Java library class names from uploaded JARs.
 * @param uriInfo URI info
 * @return class names
 */
@GET
@Path("/library/list")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List Library Classes", description = "Retrieves a list of available Java library class names from uploaded JARs.")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(type = "ArrayList<String>")), description = "Return a list of loadable class names"))
public Response listLibraryClasses(@Context UriInfo uriInfo) {
    ArrayList<String> classNames;
    try {
        classNames = libraryLoader.getLibraryClassNames();
    } catch (Exception e) {
        if (LOG.isDebugEnabled()) {
            LOG.error("Library class retrieval error.", e);
        }
        throw new WebApplicationException("Error retrieving class names from uploaded JARs.");
    }
    byte[] serialized = toJson(classNames);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasException(io.atlasmap.api.AtlasException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 83 with Info

use of io.swagger.v3.oas.models.info.Info in project atlasmap by atlasmap.

the class AtlasService method listFieldActions.

/**
 * Retrieves a list of available field action.
 * @param uriInfo URI info
 * @return {@link ActionDetails} serialized to JSON
 */
@GET
@Path("/fieldActions")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "List FieldActions", description = "Retrieves a list of available field action")
@ApiResponses(@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = ActionDetails.class)), description = "Return a list of field action detail"))
public Response listFieldActions(@Context UriInfo uriInfo) {
    ActionDetails details = new ActionDetails();
    if (atlasContextFactory == null || atlasContextFactory.getFieldActionService() == null) {
        return Response.ok().entity(toJson(details)).build();
    }
    details.getActionDetail().addAll(atlasContextFactory.getFieldActionService().listActionDetails());
    byte[] serialized = toJson(details);
    if (LOG.isDebugEnabled()) {
        LOG.debug(new String(serialized));
    }
    return Response.ok().entity(serialized).build();
}
Also used : ActionDetails(io.atlasmap.v2.ActionDetails) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 84 with Info

use of io.swagger.v3.oas.models.info.Info in project openremote by openremote.

the class ManagerWebService method init.

@Override
public void init(Container container) throws Exception {
    super.init(container);
    String rootRedirectPath = getString(container.getConfig(), ROOT_REDIRECT_PATH, ROOT_REDIRECT_PATH_DEFAULT);
    // Modify swagger object mapper to match ours
    configureObjectMapper(Json.mapper());
    Json.mapper().addMixIn(ServerVariable.class, ServerVariableMixin.class);
    // Add swagger resource
    OpenAPI oas = new OpenAPI().servers(Collections.singletonList(new Server().url("/api/{realm}/").variables(new ServerVariables().addServerVariable("realm", new ServerVariable()._default("master"))))).schemaRequirement("openid", new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(new OAuthFlows().authorizationCode(new OAuthFlow().authorizationUrl("/auth/realms/master/protocol/openid-connect/auth").refreshUrl("/auth/realms/master/protocol/openid-connect/token").tokenUrl("/auth/realms/master/protocol/openid-connect/token")))).security(Collections.singletonList(new SecurityRequirement().addList("openid")));
    Info info = new Info().title("OpenRemote Manager REST API").description("This is the documentation for the OpenRemote Manager HTTP REST API.  Please see the [wiki](https://github.com/openremote/openremote/wiki) for more info.").contact(new Contact().email("info@openremote.io")).license(new License().name("AGPL 3.0").url("https://www.gnu.org/licenses/agpl-3.0.en.html"));
    oas.info(info);
    SwaggerConfiguration oasConfig = new SwaggerConfiguration().resourcePackages(Stream.of("org.openremote.model.*").collect(Collectors.toSet())).openAPI(oas);
    OpenApiResource openApiResource = new OpenApiResource();
    openApiResource.openApiConfiguration(oasConfig);
    addApiSingleton(openApiResource);
    initialised = true;
    ResteasyDeployment resteasyDeployment = createResteasyDeployment(container, getApiClasses(), apiSingletons, true);
    // Serve REST API
    HttpHandler apiHandler = createApiHandler(container, resteasyDeployment);
    if (apiHandler != null) {
        // Authenticating requests requires a realm, either we receive this in a header or
        // we extract it (e.g. from request path segment) and set it as a header before
        // processing the request
        HttpHandler baseApiHandler = apiHandler;
        apiHandler = exchange -> {
            String path = exchange.getRelativePath().substring(API_PATH.length());
            Matcher realmSubMatcher = PATTERN_REALM_SUB.matcher(path);
            if (!realmSubMatcher.matches()) {
                exchange.setStatusCode(NOT_FOUND.getStatusCode());
                throw new WebApplicationException(NOT_FOUND);
            }
            // Extract realm from path and push it into REQUEST_HEADER_REALM header
            String realm = realmSubMatcher.group(1);
            // Move the realm from path segment to header
            exchange.getRequestHeaders().put(HttpString.tryFromString(REALM_PARAM_NAME), realm);
            URI url = fromUri(exchange.getRequestURL()).replacePath(realmSubMatcher.group(2)).build();
            exchange.setRequestURI(url.toString(), true);
            exchange.setRequestPath(url.getPath());
            exchange.setRelativePath(url.getPath());
            baseApiHandler.handleRequest(exchange);
        };
    }
    // Serve deployment files unsecured (explicitly map deployment folders to request paths)
    builtInAppDocRoot = Paths.get(getString(container.getConfig(), APP_DOCROOT, APP_DOCROOT_DEFAULT));
    customAppDocRoot = Paths.get(getString(container.getConfig(), CUSTOM_APP_DOCROOT, CUSTOM_APP_DOCROOT_DEFAULT));
    HttpHandler defaultHandler = null;
    if (Files.isDirectory(customAppDocRoot)) {
        HttpHandler customBaseFileHandler = createFileHandler(container, customAppDocRoot, null);
        defaultHandler = exchange -> {
            if (exchange.getRelativePath().isEmpty() || "/".equals(exchange.getRelativePath())) {
                exchange.setRelativePath("/index.html");
            }
            customBaseFileHandler.handleRequest(exchange);
        };
    }
    PathHandler deploymentHandler = defaultHandler != null ? new PathHandler(defaultHandler) : new PathHandler();
    // Serve deployment files
    if (Files.isDirectory(builtInAppDocRoot)) {
        HttpHandler appBaseFileHandler = createFileHandler(container, builtInAppDocRoot, null);
        HttpHandler appFileHandler = exchange -> {
            if (exchange.getRelativePath().isEmpty() || "/".equals(exchange.getRelativePath())) {
                exchange.setRelativePath("/index.html");
            }
            // Reinstate the full path
            exchange.setRelativePath(exchange.getRequestPath());
            appBaseFileHandler.handleRequest(exchange);
        };
        deploymentHandler.addPrefixPath(MANAGER_APP_PATH, appFileHandler);
        deploymentHandler.addPrefixPath(SWAGGER_APP_PATH, appFileHandler);
        deploymentHandler.addPrefixPath(CONSOLE_LOADER_APP_PATH, appFileHandler);
        deploymentHandler.addPrefixPath(SHARED_PATH, appFileHandler);
    }
    // Redirect / to default app
    if (rootRedirectPath != null) {
        getRequestHandlers().add(new RequestHandler("Default app redirect", exchange -> exchange.getRequestPath().equals("/"), exchange -> {
            LOG.finer("Handling root request, redirecting client to default app");
            new RedirectHandler(redirect(exchange, rootRedirectPath)).handleRequest(exchange);
        }));
    }
    if (apiHandler != null) {
        getRequestHandlers().add(pathStartsWithHandler("REST API Handler", API_PATH, apiHandler));
    }
    // This will try and handle any request that makes it to this handler
    getRequestHandlers().add(new RequestHandler("Deployment files", exchange -> true, deploymentHandler));
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Json(io.swagger.v3.core.util.Json) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) WebService(org.openremote.container.web.WebService) UriBuilder.fromUri(javax.ws.rs.core.UriBuilder.fromUri) ValueUtil.configureObjectMapper(org.openremote.model.util.ValueUtil.configureObjectMapper) OpenApiResource(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource) ServletInfo(io.undertow.servlet.api.ServletInfo) MapAccess.getString(org.openremote.container.util.MapAccess.getString) HttpString(io.undertow.util.HttpString) RedirectHandler(io.undertow.server.handlers.RedirectHandler) Servlets(io.undertow.servlet.Servlets) HashSet(java.util.HashSet) License(io.swagger.v3.oas.models.info.License) PathHandler(io.undertow.server.handlers.PathHandler) Matcher(java.util.regex.Matcher) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) OpenAPI(io.swagger.v3.oas.models.OpenAPI) io.swagger.v3.oas.models.security(io.swagger.v3.oas.models.security) ServerVariables(io.swagger.v3.oas.models.servers.ServerVariables) URI(java.net.URI) Path(java.nio.file.Path) REALM_PARAM_NAME(org.openremote.model.Constants.REALM_PARAM_NAME) Files(java.nio.file.Files) Collection(java.util.Collection) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) Info(io.swagger.v3.oas.models.info.Info) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) HttpHandler(io.undertow.server.HttpHandler) Container(org.openremote.model.Container) IdentityService(org.openremote.container.security.IdentityService) Server(io.swagger.v3.oas.models.servers.Server) Stream(java.util.stream.Stream) Contact(io.swagger.v3.oas.models.info.Contact) Paths(java.nio.file.Paths) ServerVariable(io.swagger.v3.oas.models.servers.ServerVariable) WebApplicationException(javax.ws.rs.WebApplicationException) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) RedirectBuilder.redirect(io.undertow.util.RedirectBuilder.redirect) ServerVariables(io.swagger.v3.oas.models.servers.ServerVariables) HttpHandler(io.undertow.server.HttpHandler) Server(io.swagger.v3.oas.models.servers.Server) WebApplicationException(javax.ws.rs.WebApplicationException) Matcher(java.util.regex.Matcher) RedirectHandler(io.undertow.server.handlers.RedirectHandler) License(io.swagger.v3.oas.models.info.License) CanonicalPathHandler(io.undertow.server.handlers.CanonicalPathHandler) PathHandler(io.undertow.server.handlers.PathHandler) MapAccess.getString(org.openremote.container.util.MapAccess.getString) HttpString(io.undertow.util.HttpString) ServletInfo(io.undertow.servlet.api.ServletInfo) Info(io.swagger.v3.oas.models.info.Info) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) ServerVariable(io.swagger.v3.oas.models.servers.ServerVariable) URI(java.net.URI) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) Contact(io.swagger.v3.oas.models.info.Contact) OpenApiResource(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Example 85 with Info

use of io.swagger.v3.oas.models.info.Info in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method testIssue343Parameter.

@Test
public void testIssue343Parameter() {
    String yaml = "openapi: 3.0.0\n" + "servers: []\n" + "info:\n" + "  description: bleh\n" + "  version: 2.0.0\n" + "  title: Test\n" + "paths:\n" + "  /foo:\n" + "    post:\n" + "      parameters:\n" + "        - in: query\n" + "          name: skip\n" + "          schema:\n" + "            type: integer\n" + "            format: int32\n" + "            multipleOf: 3\n" + "      responses:\n" + "        '200':\n" + "          description: OK\n" + "      requestBody:\n" + "        content:\n" + "          application/json:\n" + "            schema:\n" + "              type: object\n" + "              additionalProperties:\n" + "                type: string\n" + "        required: true\n" + "components:\n" + "  schemas:\n" + "    Fun:\n" + "      properties:\n" + "        id:\n" + "          type: integer\n" + "          format: int32\n" + "          multipleOf: 5\n" + "        mySet:\n" + "          type: array\n" + "          uniqueItems: true\n" + "          items:\n" + "            type: string";
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    SwaggerParseResult result = parser.readContents(yaml, null, null);
    OpenAPI openAPI = result.getOpenAPI();
    QueryParameter qp = (QueryParameter) openAPI.getPaths().get("/foo").getPost().getParameters().get(0);
    assertEquals(new BigDecimal("3"), qp.getSchema().getMultipleOf());
    RequestBody bp = openAPI.getPaths().get("/foo").getPost().getRequestBody();
    Schema schema = bp.getContent().get("application/json").getSchema();
    assertTrue(schema.getAdditionalProperties() != null);
    IntegerSchema id = (IntegerSchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("id");
    assertEquals(id.getMultipleOf(), new BigDecimal("5"));
    ArraySchema ap = (ArraySchema) openAPI.getComponents().getSchemas().get("Fun").getProperties().get("mySet");
    assertTrue(ap.getUniqueItems());
}
Also used : QueryParameter(io.swagger.v3.oas.models.parameters.QueryParameter) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) DateSchema(io.swagger.v3.oas.models.media.DateSchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) DateTimeSchema(io.swagger.v3.oas.models.media.DateTimeSchema) ByteArraySchema(io.swagger.v3.oas.models.media.ByteArraySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) BinarySchema(io.swagger.v3.oas.models.media.BinarySchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPIV3Parser(io.swagger.v3.parser.OpenAPIV3Parser) OpenAPI(io.swagger.v3.oas.models.OpenAPI) BigDecimal(java.math.BigDecimal) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)91 OpenAPI (io.swagger.v3.oas.models.OpenAPI)77 OpenAPIV3Parser (io.swagger.v3.parser.OpenAPIV3Parser)60 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)56 Info (io.swagger.v3.oas.models.info.Info)39 Schema (io.swagger.v3.oas.models.media.Schema)24 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)22 StringSchema (io.swagger.v3.oas.models.media.StringSchema)22 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)19 Components (io.swagger.v3.oas.models.Components)18 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)18 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)17 Parameter (io.swagger.v3.oas.models.parameters.Parameter)17 ByteArraySchema (io.swagger.v3.oas.models.media.ByteArraySchema)15 QueryParameter (io.swagger.v3.oas.models.parameters.QueryParameter)15 ParseOptions (io.swagger.v3.parser.core.models.ParseOptions)15 BinarySchema (io.swagger.v3.oas.models.media.BinarySchema)14 MapSchema (io.swagger.v3.oas.models.media.MapSchema)14 DateSchema (io.swagger.v3.oas.models.media.DateSchema)13 DateTimeSchema (io.swagger.v3.oas.models.media.DateTimeSchema)13