Search in sources :

Example 1 with SecurityRequirementImpl

use of org.wildfly.swarm.microprofile.openapi.api.models.security.SecurityRequirementImpl in project wildfly-swarm by wildfly-swarm.

the class OpenApiParser method readSecurityRequirement.

/**
 * Reads a {@link APIResponses} OpenAPI node.
 * @param node
 */
private SecurityRequirement readSecurityRequirement(JsonNode node) {
    if (node == null || !node.isObject()) {
        return null;
    }
    SecurityRequirementImpl model = new SecurityRequirementImpl();
    for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
        String fieldName = fieldNames.next();
        JsonNode scopesNode = node.get(fieldName);
        List<String> scopes = readStringArray(scopesNode);
        if (scopes == null) {
            model.addScheme(fieldName);
        } else {
            model.addScheme(fieldName, scopes);
        }
    }
    return model;
}
Also used : SecurityRequirementImpl(org.wildfly.swarm.microprofile.openapi.api.models.security.SecurityRequirementImpl) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with SecurityRequirementImpl

use of org.wildfly.swarm.microprofile.openapi.api.models.security.SecurityRequirementImpl in project wildfly-swarm by wildfly-swarm.

the class OpenApiAnnotationScanner method readSecurityRequirement.

/**
 * Reads a single SecurityRequirement annotation.
 * @param annotation
 */
private SecurityRequirement readSecurityRequirement(AnnotationInstance annotation) {
    String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_NAME);
    if (name != null) {
        List<String> scopes = JandexUtil.stringListValue(annotation, OpenApiConstants.PROP_SCOPES);
        SecurityRequirement requirement = new SecurityRequirementImpl();
        if (scopes == null) {
            requirement.addScheme(name);
        } else {
            requirement.addScheme(name, scopes);
        }
        return requirement;
    }
    return null;
}
Also used : SecurityRequirementImpl(org.wildfly.swarm.microprofile.openapi.api.models.security.SecurityRequirementImpl) SecurityRequirement(org.eclipse.microprofile.openapi.models.security.SecurityRequirement)

Aggregations

SecurityRequirementImpl (org.wildfly.swarm.microprofile.openapi.api.models.security.SecurityRequirementImpl)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SecurityRequirement (org.eclipse.microprofile.openapi.models.security.SecurityRequirement)1