Search in sources :

Example 16 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project powerauth-push-server by wultra.

the class PushDeviceController method updateDeviceStatus.

/**
 * Update activation status for given device registration.
 * @param request Status update request.
 * @return Status update response.
 * @throws PushServerException In case request object is invalid.
 */
@RequestMapping(value = "status/update", method = { RequestMethod.POST, RequestMethod.PUT })
@Operation(summary = "Update device status", description = "Update the status of given device registration based on the associated activation ID. " + "This can help assure that registration is in non-active state and cannot receive personal messages.")
public Response updateDeviceStatus(@RequestBody UpdateDeviceStatusRequest request) throws PushServerException {
    try {
        if (request == null) {
            throw new PushServerException("Request object must not be empty");
        }
        logger.info("Received updateDeviceStatus request, activation ID: {}", request.getActivationId());
        String errorMessage = UpdateDeviceStatusRequestValidator.validate(request);
        if (errorMessage != null) {
            throw new PushServerException(errorMessage);
        }
        String activationId = request.getActivationId();
        ActivationStatus activationStatus = request.getActivationStatus();
        List<PushDeviceRegistrationEntity> device = pushDeviceRepository.findByActivationId(activationId);
        if (device != null) {
            if (activationStatus == null) {
                // Activation status was not received via callback data, retrieve it from PowerAuth server
                activationStatus = client.getActivationStatus(activationId).getActivationStatus();
            }
            for (PushDeviceRegistrationEntity registration : device) {
                registration.setActive(activationStatus.equals(ActivationStatus.ACTIVE));
                pushDeviceRepository.save(registration);
            }
        }
        logger.info("The updateDeviceStatus request succeeded, activation ID: {}", request.getActivationId());
        return new Response();
    } catch (PowerAuthClientException ex) {
        logger.warn(ex.getMessage(), ex);
        throw new PushServerException("Update device status failed because activation status is unknown");
    }
}
Also used : Response(io.getlime.core.rest.model.base.response.Response) GetActivationStatusResponse(com.wultra.security.powerauth.client.v3.GetActivationStatusResponse) PushServerException(io.getlime.push.errorhandling.exceptions.PushServerException) PushDeviceRegistrationEntity(io.getlime.push.repository.model.PushDeviceRegistrationEntity) PowerAuthClientException(com.wultra.security.powerauth.client.model.error.PowerAuthClientException) ActivationStatus(com.wultra.security.powerauth.client.v3.ActivationStatus) Operation(io.swagger.v3.oas.annotations.Operation)

Example 17 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project openhab-core by openhab.

the class SitemapResource method getSitemapData.

@GET
@Path("/{sitemapname: [a-zA-Z_0-9]+}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(operationId = "getSitemapByName", summary = "Get sitemap by name.", responses = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = SitemapDTO.class))) })
public Response getSitemapData(@Context HttpHeaders headers, @HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @Parameter(description = "language") @Nullable String language, @PathParam("sitemapname") @Parameter(description = "sitemap name") String sitemapname, @QueryParam("type") String type, @QueryParam("jsoncallback") @DefaultValue("callback") String callback, @QueryParam("includeHidden") @Parameter(description = "include hidden widgets") boolean includeHiddenWidgets) {
    final Locale locale = localeService.getLocale(language);
    logger.debug("Received HTTP GET request from IP {} at '{}' for media type '{}'.", request.getRemoteAddr(), uriInfo.getPath(), type);
    SitemapDTO responseObject = getSitemapBean(sitemapname, uriInfo.getBaseUriBuilder().build(), locale, includeHiddenWidgets);
    return Response.ok(responseObject).build();
}
Also used : Locale(java.util.Locale) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Operation(io.swagger.v3.oas.annotations.Operation)

Example 18 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.

the class OpenAPIDeserializerTest method readComponentsObject.

@Test(dataProvider = "data")
public void readComponentsObject(JsonNode rootNode) throws Exception {
    final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
    final SwaggerParseResult result = deserializer.deserialize(rootNode);
    Assert.assertNotNull(result);
    final OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);
    Assert.assertEquals(openAPI.getOpenapi(), "3.0.1");
    final Components component = openAPI.getComponents();
    Assert.assertNotNull(component);
    Assert.assertNotNull(component.getCallbacks());
    Assert.assertEquals(component.getCallbacks().get("heartbeat").get("$request.query.heartbeat-url").getPost().getResponses().get("200").getDescription(), "Consumer acknowledged the callback");
    // System.out.println(component.getCallbacks().get("referenced"));
    Assert.assertEquals(component.getCallbacks().get("failed").get("$response.body#/failedUrl").getPost().getResponses().get("200").getDescription(), "Consumer acknowledged the callback failed");
    Assert.assertNotNull(component.getExamples());
    Assert.assertEquals(component.getExamples().get("cat").getSummary(), "An example of a cat");
    Assert.assertNotNull(component.getExamples().get("cat").getValue());
    Assert.assertNotNull(component.getHeaders());
    Assert.assertEquals(component.getHeaders().get("X-Rate-Limit-Limit").getDescription(), "The number of allowed requests in the current period");
    Assert.assertEquals(component.getHeaders().get("X-Rate-Limit-Limit").getSchema().getType(), "integer");
    Assert.assertNotNull(component.getLinks());
    Assert.assertEquals(component.getLinks().get("unsubscribe").getOperationId(), "cancelHookCallback");
    Assert.assertNotNull(component.getLinks().get("unsubscribe").getParameters());
    Assert.assertEquals(component.getLinks().get("unsubscribe").getExtensions().get("x-link"), "link extension");
    Assert.assertNotNull(component.getParameters());
    Assert.assertEquals(component.getParameters().get("skipParam").getName(), "skip");
    Assert.assertEquals(component.getParameters().get("skipParam").getIn(), "query");
    Assert.assertEquals(component.getParameters().get("skipParam").getDescription(), "number of items to skip");
    assertTrue(component.getParameters().get("skipParam").getRequired());
    Assert.assertEquals(component.getParameters().get("skipParam").getSchema().getType(), "integer");
    Assert.assertNotNull(component.getRequestBodies());
    Assert.assertEquals(component.getRequestBodies().get("requestBody1").getDescription(), "request body in components");
    Assert.assertEquals(component.getRequestBodies().get("requestBody1").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/Pet");
    Assert.assertEquals(component.getRequestBodies().get("requestBody1").getContent().get("application/xml").getSchema().get$ref(), "#/components/schemas/Pet");
    Assert.assertEquals(component.getRequestBodies().get("requestBody2").getContent().get("application/json").getSchema().getType().toString(), "array");
    Assert.assertNotNull(component.getRequestBodies().get("requestBody2").getContent().get("application/json").getSchema());
    Assert.assertNotNull(component.getResponses());
    Assert.assertEquals(component.getResponses().get("NotFound").getDescription(), "Entity not found.");
    Assert.assertEquals(component.getResponses().get("IllegalInput").getDescription(), "Illegal input for operation.");
    Assert.assertEquals(component.getResponses().get("GeneralError").getDescription(), "General Error");
    Assert.assertEquals(component.getResponses().get("GeneralError").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/ExtendedErrorModel");
    Assert.assertNotNull(component.getSchemas());
    Assert.assertEquals(component.getSchemas().get("Category").getType(), "object");
    Assert.assertEquals(component.getSchemas().get("ApiResponse").getRequired().get(0), "name");
    Assert.assertEquals(component.getSchemas().get("Order").getType(), "object");
    Assert.assertEquals(component.getSchemas().get("Order").getNot().getType(), "integer");
    assertTrue(component.getSchemas().get("Order").getAdditionalProperties() instanceof Schema);
    Schema additionalProperties = (Schema) component.getSchemas().get("Order").getAdditionalProperties();
    Assert.assertEquals(additionalProperties.getType(), "integer");
    Schema schema = (Schema) component.getSchemas().get("Order").getProperties().get("status");
    Map<String, Schema> properties = (Map<String, Schema>) component.getSchemas().get("Order").getProperties();
    Assert.assertNotNull(properties);
    Assert.assertEquals(properties.get("status").getType(), "string");
    Assert.assertEquals(properties.get("status").getDescription(), "Order Status");
    Assert.assertEquals(properties.get("status").getEnum().get(0), "placed");
    Assert.assertNotNull(component.getSecuritySchemes());
    Assert.assertEquals(component.getSecuritySchemes().get("petstore_auth").getType().toString(), "oauth2");
    Assert.assertEquals(component.getSecuritySchemes().get("petstore_auth").getFlows().getImplicit().getAuthorizationUrl(), "http://petstore.swagger.io/oauth/dialog");
    // TODO
    Assert.assertNotNull(component.getSecuritySchemes().get("petstore_auth").getFlows().getImplicit().getScopes());
    Assert.assertNotNull(component.getExtensions());
    assertTrue(component.getExtensions().containsKey("x-component"));
    Object object = component.getExtensions().get("x-component");
    assertTrue(object instanceof List);
    List elements = (List) object;
    Assert.assertEquals(elements.size(), 1);
    Map<String, Object> map = (Map) elements.get(0);
    Assert.assertEquals(map.get("url"), "http://component.swagger.io/v2/swagger.json");
    Assert.assertEquals(map.get("format"), "OAS");
    Assert.assertEquals(map.get("version"), "3.0");
    Map<String, Object> converter = (Map<String, Object>) map.get("converter");
    Assert.assertNotNull(converter);
    Assert.assertEquals(converter.get("url"), "https://github.com/mermade/oas3");
    Assert.assertEquals(converter.get("version"), "1.2.3");
    object = component.getExtensions().get("x-api-title");
    assertTrue(object instanceof String);
    Assert.assertEquals("pet store test api in components", object.toString());
}
Also used : Components(io.swagger.v3.oas.models.Components) 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) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) SwaggerParseResult(io.swagger.v3.parser.core.models.SwaggerParseResult) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 19 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getCallbacks.

public Map<String, Callback> getCallbacks(ObjectNode node, String location, ParseResult result, boolean underComponents) {
    if (node == null) {
        return null;
    }
    Map<String, Callback> callbacks = new LinkedHashMap<>();
    Set<String> keys = getKeys(node);
    for (String key : keys) {
        if (underComponents) {
            if (!Pattern.matches("^[a-zA-Z0-9\\.\\-_]+$", key)) {
                result.warning(location, "Callback key " + key + " doesn't adhere to regular expression " + "^[a-zA-Z0-9\\.\\-_]+$");
            }
        }
        Callback callback = getCallback((ObjectNode) node.get(key), location, result);
        if (callback != null) {
            callbacks.put(key, callback);
        }
    }
    return callbacks;
}
Also used : Callback(io.swagger.v3.oas.models.callbacks.Callback)

Example 20 with Callback

use of io.swagger.v3.oas.annotations.callbacks.Callback in project swagger-parser by swagger-api.

the class PathsProcessor method updateRefs.

protected void updateRefs(PathItem path, String pathRef) {
    if (path.getParameters() != null) {
        List<Parameter> params = path.getParameters();
        for (Parameter param : params) {
            updateRefs(param, pathRef);
        }
    }
    List<Operation> ops = path.readOperations();
    for (Operation op : ops) {
        if (op.getParameters() != null) {
            for (Parameter param : op.getParameters()) {
                updateRefs(param, pathRef);
            }
        }
        if (op.getResponses() != null) {
            for (ApiResponse response : op.getResponses().values()) {
                updateRefs(response, pathRef);
            }
        }
        if (op.getRequestBody() != null) {
            updateRefs(op.getRequestBody(), pathRef);
        }
        if (op.getCallbacks() != null) {
            Map<String, Callback> callbacks = op.getCallbacks();
            for (String name : callbacks.keySet()) {
                Callback callback = callbacks.get(name);
                if (callback != null) {
                    for (String callbackName : callback.keySet()) {
                        PathItem pathItem = callback.get(callbackName);
                        updateRefs(pathItem, pathRef);
                    }
                }
            }
        }
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Callback(io.swagger.v3.oas.models.callbacks.Callback) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse)

Aggregations

Callback (io.swagger.v3.oas.models.callbacks.Callback)19 Operation (io.swagger.v3.oas.models.Operation)13 PathItem (io.swagger.v3.oas.models.PathItem)13 OpenAPI (io.swagger.v3.oas.models.OpenAPI)12 Parameter (io.swagger.v3.oas.models.parameters.Parameter)9 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)9 Test (org.testng.annotations.Test)9 Components (io.swagger.v3.oas.models.Components)7 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)6 Schema (io.swagger.v3.oas.models.media.Schema)6 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 Operation (io.swagger.v3.oas.annotations.Operation)4 Example (io.swagger.v3.oas.models.examples.Example)4 Link (io.swagger.v3.oas.models.links.Link)4 StringSchema (io.swagger.v3.oas.models.media.StringSchema)4 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)4 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4