use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitParameter.
@Override
public void visitParameter(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
Parameter matchedParam = null;
Boolean hidden = annotation.getValue("hidden", Boolean.class);
if (hidden != null && hidden) {
return;
}
Parameter parameter = ParameterImpl.createInstance(annotation, context);
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
matchedParam = findOperationParameterFor((org.glassfish.hk2.classmodel.reflect.Parameter) element, context);
}
if (element instanceof MethodModel) {
matchedParam = findOperationParameterFor(parameter, (MethodModel) element, context);
}
if (matchedParam != null) {
ParameterImpl.merge(parameter, matchedParam, true, context);
// If a content was added, and a schema type exists, reconfigure the schema type
if (matchedParam.getContent() != null && !matchedParam.getContent().getMediaTypes().isEmpty() && matchedParam.getSchema() != null && matchedParam.getSchema().getType() != null) {
SchemaType type = matchedParam.getSchema().getType();
matchedParam.setSchema(null);
for (MediaType mediaType : matchedParam.getContent().getMediaTypes().values()) {
if (mediaType.getSchema() == null) {
mediaType.setSchema(new SchemaImpl());
}
mediaType.getSchema().setType(ModelUtils.mergeProperty(mediaType.getSchema().getType(), type, false));
}
}
}
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitProduces.
@Override
public void visitProduces(AnnotationModel produces, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel && context.getWorkingOperation() != null) {
for (APIResponse response : context.getWorkingOperation().getResponses().getAPIResponses().values()) {
if (response != null) {
// Find the wildcard return type
if (response.getContent() != null && response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
MediaType wildcardMedia = response.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
// Merge the wildcard return type with the valid response types
// This keeps the specific details of a reponse type that has a schema
List<String> mediaTypes = produces.getValue("value", List.class);
for (String mediaType : mediaTypes) {
MediaType held = response.getContent().getMediaType(getContentType(mediaType));
if (held == null) {
response.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
} else {
MediaTypeImpl.merge(held, wildcardMedia, true);
}
}
// If there is an @Produces, remove the wildcard
response.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
}
}
}
}
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitConsumes.
@Override
public void visitConsumes(AnnotationModel consumes, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel && context.getWorkingOperation() != null) {
RequestBody requestBody = context.getWorkingOperation().getRequestBody();
if (requestBody != null) {
// Find the wildcard return type
if (requestBody.getContent() != null && requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
MediaType wildcardMedia = requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
// Copy the wildcard return type to the valid request body types
List<String> mediaTypes = consumes.getValue("value", List.class);
for (String mediaType : mediaTypes) {
requestBody.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
}
// If there is an @Consumes, remove the wildcard
requestBody.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
}
}
}
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitSchemaFieldOrMethod.
private void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod, ExtensibleType<?> declaringType, String typeName, ApiContext context) {
assert (fieldOrMethod instanceof FieldModel) || (fieldOrMethod instanceof MethodModel);
Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
if (hidden == null || !hidden) {
// Get the schema object name
String schemaName = ModelUtils.getSchemaName(context, fieldOrMethod);
SchemaImpl schema = SchemaImpl.createInstance(schemaAnnotation, context);
// Get the parent schema object name
String parentName = null;
AnnotationModel classSchemaAnnotation = context.getAnnotationInfo(declaringType).getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class);
if (classSchemaAnnotation != null) {
parentName = classSchemaAnnotation.getValue("name", String.class);
}
if (parentName == null || parentName.isEmpty()) {
parentName = declaringType.getSimpleName();
}
// Get or create the parent schema object
final Components components = context.getApi().getComponents();
Schema parentSchema = components.getSchemas().getOrDefault(parentName, new SchemaImpl());
components.addSchema(parentName, parentSchema);
Schema property = parentSchema.getProperties().getOrDefault(schemaName, new SchemaImpl());
parentSchema.addProperty(schemaName, property);
if (schema.isRequired()) {
parentSchema.addRequired(schemaName);
}
if (property.getRef() == null) {
property.setType(ModelUtils.getSchemaType(typeName, context));
}
SchemaImpl.merge(schema, property, true, context);
}
}
use of org.glassfish.hk2.classmodel.reflect.MethodModel in project Payara by payara.
the class ApplicationProcessor method visitServer.
@Override
public void visitServer(AnnotationModel server, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
Server newServer = new ServerImpl();
context.getWorkingOperation().addServer(newServer);
ServerImpl.merge(ServerImpl.createInstance(server, context), newServer, true);
}
}
Aggregations