use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method jaxRsApplicationToOpenApi.
/**
* Processes a JAX-RS {@link Application} and creates an {@link OpenAPI} model. Performs
* annotation scanning and other processing. Returns a model unique to that single JAX-RS
* app.
* @param applicationClass
*/
private OpenAPIImpl jaxRsApplicationToOpenApi(ClassInfo applicationClass) {
OpenAPIImpl oai = new OpenAPIImpl();
oai.setOpenapi(OpenApiConstants.OPEN_API_VERSION);
// Get the @ApplicationPath info and save it for later (also support @Path which seems nonstandard but common).
// //////////////////////////////////////
AnnotationInstance appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_APPLICATION_PATH);
if (appPathAnno == null) {
appPathAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_PATH);
}
if (appPathAnno != null) {
this.currentAppPath = appPathAnno.value().asString();
} else {
this.currentAppPath = "/";
}
// Get the @OpenAPIDefinition annotation and process it.
// //////////////////////////////////////
AnnotationInstance openApiDefAnno = JandexUtil.getClassAnnotation(applicationClass, OpenApiConstants.DOTNAME_OPEN_API_DEFINITION);
if (openApiDefAnno != null) {
processDefinition(oai, openApiDefAnno);
}
// Process @SecurityScheme annotations
// //////////////////////////////////////
List<AnnotationInstance> securitySchemeAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SECURITY_SCHEME, OpenApiConstants.DOTNAME_SECURITY_SCHEMES);
for (AnnotationInstance annotation : securitySchemeAnnotations) {
String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SECURITY_SCHEME_NAME);
if (name == null && JandexUtil.isRef(annotation)) {
name = JandexUtil.nameFromRef(annotation);
}
if (name != null) {
SecurityScheme securityScheme = readSecurityScheme(annotation);
Components components = ModelUtil.components(oai);
components.addSecurityScheme(name, securityScheme);
}
}
// Process @Server annotations
// /////////////////////////////////
List<AnnotationInstance> serverAnnotations = JandexUtil.getRepeatableAnnotation(applicationClass, OpenApiConstants.DOTNAME_SERVER, OpenApiConstants.DOTNAME_SERVERS);
for (AnnotationInstance annotation : serverAnnotations) {
Server server = readServer(annotation);
oai.addServer(server);
}
return oai;
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readSecurityScheme.
/**
* Reads a SecurityScheme annotation into a model.
* @param annotation
*/
private SecurityScheme readSecurityScheme(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @SecurityScheme annotation.");
SecurityScheme securityScheme = new SecuritySchemeImpl();
securityScheme.setType(JandexUtil.enumValue(annotation, OpenApiConstants.PROP_TYPE, org.eclipse.microprofile.openapi.models.security.SecurityScheme.Type.class));
securityScheme.setDescription(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_DESCRIPTION));
securityScheme.setName(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_API_KEY_NAME));
securityScheme.setIn(JandexUtil.enumValue(annotation, OpenApiConstants.PROP_IN, org.eclipse.microprofile.openapi.models.security.SecurityScheme.In.class));
securityScheme.setScheme(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_SCHEME));
securityScheme.setBearerFormat(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_BEARER_FORMAT));
securityScheme.setFlows(readOAuthFlows(annotation.value(OpenApiConstants.PROP_FLOWS)));
securityScheme.setOpenIdConnectUrl(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_OPEN_ID_CONNECT_URL));
securityScheme.setRef(JandexUtil.refValue(annotation, RefType.SecurityScheme));
return securityScheme;
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project wildfly-swarm by wildfly-swarm.
the class FilterUtil method filterSecuritySchemes.
/**
* Filters the given models.
* @param filter
* @param models
*/
private static void filterSecuritySchemes(OASFilter filter, Map<String, SecurityScheme> models) {
if (models == null) {
return;
}
Collection<String> keys = new ArrayList<>(models.keySet());
for (String key : keys) {
SecurityScheme model = models.get(key);
filterSecurityScheme(filter, model);
if (filter.filterSecurityScheme(model) == null) {
models.remove(key);
}
}
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project Payara by payara.
the class ComponentsImpl method merge.
public static void merge(Components from, Components to, boolean override, ApiContext context) {
if (from == null) {
return;
}
// Handle @Schema
if (from.getSchemas() != null) {
for (Entry<String, Schema> fromEntry : from.getSchemas().entrySet()) {
final String schemaName = fromEntry.getKey();
if (schemaName != null) {
final Schema fromSchema = fromEntry.getValue();
final Schema toSchema = to.getSchemas().getOrDefault(schemaName, new SchemaImpl());
SchemaImpl.merge(fromSchema, toSchema, override, context);
to.addSchema(schemaName, toSchema);
}
}
}
// Handle @Callback
if (from.getCallbacks() != null) {
for (String callbackName : from.getCallbacks().keySet()) {
if (callbackName != null) {
Callback newCallback = new CallbackImpl();
CallbackImpl.merge(from.getCallbacks().get(callbackName), newCallback, override, context);
to.addCallback(callbackName, newCallback);
}
}
}
// Handle @ExampleObject
if (from.getExamples() != null) {
for (String exampleName : from.getExamples().keySet()) {
if (exampleName != null) {
Example newExample = new ExampleImpl();
ExampleImpl.merge(from.getExamples().get(exampleName), newExample, override);
to.addExample(exampleName, newExample);
}
}
}
// Handle @Header
if (from.getHeaders() != null) {
for (String headerName : from.getHeaders().keySet()) {
if (headerName != null) {
Header newHeader = new HeaderImpl();
HeaderImpl.merge(from.getHeaders().get(headerName), newHeader, override, context);
to.addHeader(headerName, newHeader);
}
}
}
// Handle @Link
if (from.getLinks() != null) {
for (String linkName : from.getLinks().keySet()) {
if (linkName != null) {
Link newLink = new LinkImpl();
LinkImpl.merge(from.getLinks().get(linkName), newLink, override);
to.addLink(linkName, newLink);
}
}
}
// Handle @Parameter
if (from.getParameters() != null) {
for (String parameterName : from.getParameters().keySet()) {
if (parameterName != null) {
Parameter newParameter = new ParameterImpl();
ParameterImpl.merge(from.getParameters().get(parameterName), newParameter, override, context);
to.addParameter(parameterName, newParameter);
}
}
}
// Handle @RequestBody
if (from.getRequestBodies() != null) {
for (String requestBodyName : from.getRequestBodies().keySet()) {
if (requestBodyName != null) {
RequestBody newRequestBody = new RequestBodyImpl();
RequestBodyImpl.merge(from.getRequestBodies().get(requestBodyName), newRequestBody, override, context);
to.addRequestBody(requestBodyName, newRequestBody);
}
}
}
// Handle @APIResponse
if (from.getResponses() != null) {
for (String responseName : from.getResponses().keySet()) {
if (responseName != null) {
APIResponse newResponse = new APIResponseImpl();
APIResponseImpl.merge(from.getResponses().get(responseName), newResponse, override, context);
to.addResponse(responseName, newResponse);
}
}
}
// Handle @SecurityScheme
if (from.getSecuritySchemes() != null) {
for (String securitySchemeName : from.getSecuritySchemes().keySet()) {
if (securitySchemeName != null) {
SecurityScheme newSecurity = new SecuritySchemeImpl();
SecuritySchemeImpl.merge(from.getSecuritySchemes().get(securitySchemeName), newSecurity, override);
to.addSecurityScheme(securitySchemeName, newSecurity);
}
}
}
}
use of org.eclipse.microprofile.openapi.models.security.SecurityScheme in project Payara by payara.
the class ApplicationProcessor method visitSecurityScheme.
@Override
public void visitSecurityScheme(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
String securitySchemeName = annotation.getValue("securitySchemeName", String.class);
SecurityScheme securityScheme = SecuritySchemeImpl.createInstance(annotation, context);
if (securitySchemeName != null && !securitySchemeName.isEmpty()) {
SecurityScheme newScheme = context.getApi().getComponents().getSecuritySchemes().getOrDefault(securitySchemeName, new SecuritySchemeImpl());
context.getApi().getComponents().addSecurityScheme(securitySchemeName, newScheme);
SecuritySchemeImpl.merge(securityScheme, newScheme, true);
}
}
Aggregations