use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.
the class ExternalRefProcessor method processRefToExternalSecurityScheme.
public String processRefToExternalSecurityScheme(String $ref, RefFormat refFormat) {
String renamedRef = cache.getRenamedRef($ref);
if (renamedRef != null) {
return renamedRef;
}
final SecurityScheme securityScheme = cache.loadRef($ref, refFormat, SecurityScheme.class);
if (securityScheme == null) {
// stop! There's a problem. retain the original ref
LOGGER.warn("unable to load model reference from `" + $ref + "`. It may not be available " + "or the reference isn't a valid model schema");
return $ref;
}
String newRef;
if (openAPI.getComponents() == null) {
openAPI.setComponents(new Components());
}
Map<String, SecurityScheme> securitySchemeMap = openAPI.getComponents().getSecuritySchemes();
if (securitySchemeMap == null) {
securitySchemeMap = new LinkedHashMap<>();
}
final String possiblyConflictingDefinitionName = computeDefinitionName($ref);
SecurityScheme existingSecurityScheme = securitySchemeMap.get(possiblyConflictingDefinitionName);
if (existingSecurityScheme != null) {
LOGGER.debug("A model for " + existingSecurityScheme + " already exists");
if (existingSecurityScheme.get$ref() != null) {
// use the new model
existingSecurityScheme = null;
}
}
newRef = possiblyConflictingDefinitionName;
cache.putRenamedRef($ref, newRef);
if (existingSecurityScheme == null) {
// don't overwrite existing model reference
openAPI.getComponents().addSecuritySchemes(newRef, securityScheme);
cache.addReferencedKey(newRef);
String file = $ref.split("#/")[0];
if (securityScheme.get$ref() != null) {
RefFormat format = computeRefFormat(securityScheme.get$ref());
if (isAnExternalRefFormat(format)) {
securityScheme.set$ref(processRefToExternalSecurityScheme(securityScheme.get$ref(), format));
} else {
processRefToExternalSecurityScheme(file + securityScheme.get$ref(), RefFormat.RELATIVE);
}
}
}
return newRef;
}
use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.
the class SecuritySchemeProcessor method processSecurityScheme.
public SecurityScheme processSecurityScheme(SecurityScheme securityScheme) {
if (securityScheme.get$ref() != null) {
RefFormat refFormat = computeRefFormat(securityScheme.get$ref());
String $ref = securityScheme.get$ref();
SecurityScheme newSecurityScheme = cache.loadRef($ref, refFormat, SecurityScheme.class);
if (newSecurityScheme != null) {
return newSecurityScheme;
}
}
return securityScheme;
}
use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.
the class SwaggerConverter method convertApiKeySecurityScheme.
private SecurityScheme convertApiKeySecurityScheme(SecuritySchemeDefinition definition) {
SecurityScheme securityScheme = new SecurityScheme();
ApiKeyAuthDefinition apiKeyAuthDefinition = (ApiKeyAuthDefinition) definition;
securityScheme.setType(SecurityScheme.Type.APIKEY);
securityScheme.setName(apiKeyAuthDefinition.getName());
securityScheme.setIn(SecurityScheme.In.valueOf(apiKeyAuthDefinition.getIn().toString()));
return securityScheme;
}
use of io.swagger.v3.oas.models.security.SecurityScheme in project swagger-parser by swagger-api.
the class SwaggerConverter method convert.
private SecurityScheme convert(SecuritySchemeDefinition definition) {
SecurityScheme securityScheme;
switch(definition.getType()) {
case "basic":
securityScheme = createBasicSecurityScheme();
break;
case "apiKey":
securityScheme = convertApiKeySecurityScheme(definition);
break;
case "oauth2":
securityScheme = convertOauth2SecurityScheme(definition);
break;
default:
securityScheme = new SecurityScheme();
}
securityScheme.setDescription(definition.getDescription());
securityScheme.setExtensions(convert(definition.getVendorExtensions()));
return securityScheme;
}
use of io.swagger.v3.oas.models.security.SecurityScheme in project flow by vaadin.
the class OpenAPIObjectGenerator method createBasicModel.
private OpenAPI createBasicModel() {
OpenAPI openAPI = new OpenAPI();
Info info = new Info();
info.setTitle(configuration.getApplicationTitle());
info.setVersion(configuration.getApplicationApiVersion());
openAPI.setInfo(info);
Paths paths = new Paths();
openAPI.setPaths(paths);
Server server = new Server();
server.setUrl(configuration.getServerUrl());
server.setDescription(configuration.getServerDescription());
openAPI.setServers(Collections.singletonList(server));
Components components = new Components();
SecurityScheme vaadinConnectOAuth2Scheme = new SecurityScheme().type(SecurityScheme.Type.OAUTH2).flows(new OAuthFlows().password(new OAuthFlow().tokenUrl(VAADIN_CONNECT_OAUTH2_TOKEN_URL).scopes(new Scopes())));
components.addSecuritySchemes(VAADIN_CONNECT_OAUTH2_SECURITY_SCHEME, vaadinConnectOAuth2Scheme);
openAPI.components(components);
return openAPI;
}
Aggregations