Search in sources :

Example 1 with Oas20Scopes

use of io.apicurio.datamodels.openapi.v2.models.Oas20Scopes in project apicurio-data-models by Apicurio.

the class Oas20DataModelReader method readSecurityScheme.

/**
 * @see io.apicurio.datamodels.core.io.DataModelReader#readSecurityScheme(java.lang.Object, io.apicurio.datamodels.core.models.common.SecurityScheme)
 */
public void readSecurityScheme(Object json, SecurityScheme node) {
    Oas20SecurityScheme scheme = (Oas20SecurityScheme) node;
    String flow = JsonCompat.consumePropertyString(json, Constants.PROP_FLOW);
    String authorizationUrl = JsonCompat.consumePropertyString(json, Constants.PROP_AUTHORIZATION_URL);
    String tokenUrl = JsonCompat.consumePropertyString(json, Constants.PROP_TOKEN_URL);
    Object scopes = JsonCompat.consumeProperty(json, Constants.PROP_SCOPES);
    scheme.flow = flow;
    scheme.authorizationUrl = authorizationUrl;
    scheme.tokenUrl = tokenUrl;
    if (scopes != null) {
        Oas20Scopes scopesModel = scheme.createScopes();
        this.readScopes(scopes, scopesModel);
        scheme.scopes = scopesModel;
    }
    super.readSecurityScheme(json, scheme);
}
Also used : Oas20SecurityScheme(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme) Oas20Scopes(io.apicurio.datamodels.openapi.v2.models.Oas20Scopes)

Example 2 with Oas20Scopes

use of io.apicurio.datamodels.openapi.v2.models.Oas20Scopes in project apicurio-data-models by Apicurio.

the class OasUnexpectedSecurityRequirementScopesRule method visitSecurityRequirement.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
 */
@Override
public void visitSecurityRequirement(SecurityRequirement node) {
    List<String> snames = node.getSecurityRequirementNames();
    snames.forEach(sname -> {
        Oas20SecurityDefinitions sdefs = ((Oas20Document) node.ownerDocument()).securityDefinitions;
        if (hasValue(sdefs)) {
            Oas20SecurityScheme scheme = sdefs.getSecurityScheme(sname);
            if (hasValue(scheme)) {
                if (equals(scheme.type, "oauth2")) {
                    Oas20Scopes definedScopes = scheme.scopes;
                    List<String> requiredScopes = node.getScopes(sname);
                    this.reportIfInvalid(isValidScopes(requiredScopes, definedScopes), node, null, map("sname", sname));
                }
            }
        }
    });
}
Also used : Oas20SecurityDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityDefinitions) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20SecurityScheme(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme) Oas20Scopes(io.apicurio.datamodels.openapi.v2.models.Oas20Scopes)

Aggregations

Oas20Scopes (io.apicurio.datamodels.openapi.v2.models.Oas20Scopes)2 Oas20SecurityScheme (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)1 Oas20SecurityDefinitions (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityDefinitions)1