Search in sources :

Example 86 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class WebAuthnRegisteredDevicesEndpoint method delete.

/**
 * Delete.
 *
 * @param username     the username
 * @param credentialId the credential id
 * @throws Exception the exception
 */
@Operation(summary = "Remove device registration for username and credential id", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "credentialId", required = true) })
@DeleteMapping(path = "{username}/{credentialId}", produces = MediaType.APPLICATION_JSON_VALUE)
public void delete(@PathVariable final String username, @PathVariable final String credentialId) throws Exception {
    val ba = ByteArray.fromBase64Url(credentialId);
    registrationStorage.getObject().getRegistrationByUsernameAndCredentialId(username, ba).ifPresent(registration -> registrationStorage.getObject().removeRegistrationByUsername(username, registration));
}
Also used : lombok.val(lombok.val) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 87 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class WebAuthnRegisteredDevicesEndpoint method write.

/**
 * Write.
 *
 * @param username the username
 * @param record   the record
 * @return the boolean
 * @throws Exception the exception
 */
@PostMapping(path = "{username}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Add device registration for username", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "record", required = true) })
public boolean write(@PathVariable final String username, @RequestParam final String record) throws Exception {
    val json = EncodingUtils.decodeBase64ToString(record);
    val registration = WebAuthnUtils.getObjectMapper().readValue(json, CredentialRegistration.class);
    return registrationStorage.getObject().addRegistrationByUsername(username, registration);
}
Also used : lombok.val(lombok.val) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 88 with Operation

use of io.swagger.v3.oas.models.Operation in project cas by apereo.

the class WebAuthnRegisteredDevicesEndpoint method importAccount.

/**
 * Import account.
 *
 * @param request the request
 * @return the http status
 * @throws Exception the exception
 */
@Operation(summary = "Import a device registration as a JSON document")
@PostMapping(path = "/import", consumes = MediaType.APPLICATION_JSON_VALUE)
public HttpStatus importAccount(final HttpServletRequest request) throws Exception {
    val requestBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
    LOGGER.trace("Submitted account: [{}]", requestBody);
    val account = WebAuthnUtils.getObjectMapper().readValue(requestBody, new TypeReference<CredentialRegistration>() {
    });
    LOGGER.trace("Storing account: [{}]", account);
    registrationStorage.getObject().addRegistrationByUsername(account.getUsername(), account);
    return HttpStatus.CREATED;
}
Also used : lombok.val(lombok.val) CredentialRegistration(com.yubico.data.CredentialRegistration) PostMapping(org.springframework.web.bind.annotation.PostMapping) Operation(io.swagger.v3.oas.annotations.Operation)

Example 89 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testBooleanAdditionalPropertiesDeserialization.

@Test(description = "it should deserialize a boolean additionalProperties")
public void testBooleanAdditionalPropertiesDeserialization() throws Exception {
    Operation operation = Json.mapper().readValue(jsonAdditionalPropertiesBoolean, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof ObjectSchema);
    assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
    Assert.assertFalse((Boolean) responseSchema.getAdditionalProperties());
    operation = Json.mapper().readValue(jsonAdditionalPropertiesBooleanTrue, Operation.class);
    response = operation.getResponses().get("200");
    assertNotNull(response);
    responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    assertTrue(responseSchema instanceof MapSchema);
    assertTrue(responseSchema.getAdditionalProperties() instanceof Boolean);
    Assert.assertTrue((Boolean) responseSchema.getAdditionalProperties());
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 90 with Operation

use of io.swagger.v3.oas.models.Operation in project swagger-core by swagger-api.

the class MapPropertyDeserializerTest method testMapDeserializationVendorExtensions.

@Test(description = "vendor extensions should be included with object type")
public void testMapDeserializationVendorExtensions() throws Exception {
    Operation operation = Json.mapper().readValue(json, Operation.class);
    ApiResponse response = operation.getResponses().get("200");
    assertNotNull(response);
    Schema responseSchema = response.getContent().get("*/*").getSchema();
    assertNotNull(responseSchema);
    MapSchema mp = (MapSchema) responseSchema;
    assertTrue(mp.getExtensions().size() > 0);
    assertNotNull(mp.getExtensions().get("x-foo"));
    assertEquals(mp.getExtensions().get("x-foo"), "vendor x");
}
Also used : MapSchema(io.swagger.v3.oas.models.media.MapSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) Operation(io.swagger.v3.oas.models.Operation) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Aggregations

Operation (io.swagger.v3.oas.annotations.Operation)177 Operation (io.swagger.v3.oas.models.Operation)174 OpenAPI (io.swagger.v3.oas.models.OpenAPI)141 Test (org.testng.annotations.Test)129 PathItem (io.swagger.v3.oas.models.PathItem)108 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)99 Schema (io.swagger.v3.oas.models.media.Schema)68 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)62 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)59 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)55 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)51 ArrayList (java.util.ArrayList)51 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)50 StringSchema (io.swagger.v3.oas.models.media.StringSchema)48 MediaType (io.swagger.v3.oas.models.media.MediaType)44 Path (javax.ws.rs.Path)44 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)43 Content (io.swagger.v3.oas.models.media.Content)42 lombok.val (lombok.val)42 Parameter (io.swagger.v3.oas.models.parameters.Parameter)39