Skip to content
Permalink
Browse files
GERONIMO-6612 GERONIMO-6613 mojo misread method parameter annotations…
… and avoid some empty data in the openapi.json
  • Loading branch information
rmannibucau committed Aug 1, 2018
1 parent cce5caf commit abd695bed67d082146148c55b5a295749f113afa
Showing 3 changed files with 64 additions and 15 deletions.
@@ -236,10 +236,18 @@ private Operation buildOperation(final OpenAPI api, final AnnotatedMethodElement

if (opOpt.isPresent()) {
final org.eclipse.microprofile.openapi.annotations.Operation op = opOpt.get();
operation.operationId(op.operationId());
operation.summary(op.summary());
if (!op.operationId().isEmpty()) {
operation.operationId(op.operationId());
} else {
operation.operationId(m.getName());
}
if (!op.summary().isEmpty()) {
operation.summary(op.summary());
}
operation.deprecated(op.deprecated());
operation.description(op.description());
if (!op.description().isEmpty()) {
operation.description(op.description());
}
} else {
operation.operationId(m.getName());
}
@@ -336,7 +344,9 @@ private Operation buildOperation(final OpenAPI api, final AnnotatedMethodElement
.orElseGet(() -> new ParameterImpl().schema(schemaProcessor.mapSchemaFromClass(api.getComponents(), it.getType()))))
.filter(Objects::nonNull).collect(toList()));
Stream.of(m.getParameters())
.filter(p -> p.isAnnotationPresent(RequestBody.class) || (!p.isAnnotationPresent(Suspended.class) && !p.isAnnotationPresent(Context.class)))
.filter(p -> p.isAnnotationPresent(RequestBody.class) ||
(!p.isAnnotationPresent(Suspended.class) && !p.isAnnotationPresent(Context.class) &&
!p.isAnnotationPresent(Parameter.class) && !hasJaxRsParams(p)))
.findFirst()
.ifPresent(p -> operation.requestBody(mapRequestBody(api.getComponents(), ofNullable(p.getAnnotation(RequestBody.class))
.orElseGet(() -> m.getAnnotation(RequestBody.class)))));
@@ -669,8 +679,12 @@ private org.eclipse.microprofile.openapi.models.parameters.RequestBody mapReques
final org.eclipse.microprofile.openapi.models.parameters.RequestBody impl = new RequestBodyImpl()
.content(new ContentImpl());
if (requestBody != null) {
impl.description(requestBody.description());
impl.ref(requestBody.ref());
if (!requestBody.description().isEmpty()) {
impl.description(requestBody.description());
}
if (!requestBody.ref().isEmpty()) {
impl.ref(requestBody.ref());
}
impl.required(requestBody.required());
impl.getContent().putAll(Stream.of(requestBody.content()).collect(toMap(
it -> of(it.mediaType()).filter(v -> !v.isEmpty()).orElse("*/*"),
@@ -805,10 +819,18 @@ private org.eclipse.microprofile.openapi.models.parameters.Parameter mapParamete

private Example mapExample(final ExampleObject exampleObject) {
final ExampleImpl impl = new ExampleImpl();
impl.description(exampleObject.description());
impl.externalValue(exampleObject.externalValue());
impl.value(exampleObject.value());
impl.summary(exampleObject.summary());
if (!exampleObject.description().isEmpty()) {
impl.description(exampleObject.description());
}
if (!exampleObject.externalValue().isEmpty()) {
impl.externalValue(exampleObject.externalValue());
}
if (!exampleObject.value().isEmpty()) { // todo: type
impl.value(exampleObject.value());
}
if (!exampleObject.summary().isEmpty()) {
impl.summary(exampleObject.summary());
}
return impl;
}

@@ -882,9 +904,16 @@ private org.eclipse.microprofile.openapi.models.tags.Tag mapTag(final Tag tag) {

private org.eclipse.microprofile.openapi.models.ExternalDocumentation mapExternalDocumentation(
final ExternalDocumentation externalDocumentation) {
if (externalDocumentation.url().isEmpty() && externalDocumentation.description().isEmpty()) {
return null;
}
final ExternalDocumentationImpl impl = new ExternalDocumentationImpl();
impl.url(externalDocumentation.url());
impl.description(externalDocumentation.description());
if (!externalDocumentation.url().isEmpty()) {
impl.url(externalDocumentation.url());
}
if (!externalDocumentation.description().isEmpty()) {
impl.description(externalDocumentation.description());
}
return impl;
}

@@ -58,7 +58,6 @@ public org.eclipse.microprofile.openapi.models.media.Schema mapSchemaFromClass(

public void fillSchema(final org.eclipse.microprofile.openapi.models.Components components, final Type model,
final org.eclipse.microprofile.openapi.models.media.Schema schema) {
schema.items(new SchemaImpl());
if (Class.class.isInstance(model)) {
if (boolean.class == model) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.BOOLEAN);
@@ -72,6 +71,7 @@ public void fillSchema(final org.eclipse.microprofile.openapi.models.Components
// todo cache schema in components and just set the ref here - jsonb mapping based
final Class from = Class.class.cast(model);
ofNullable(from.getAnnotation(Schema.class)).ifPresent(s -> sets(components, Schema.class.cast(s), schema));
schema.items(new SchemaImpl());
schema.properties(new HashMap<>());
Class<?> current = from;
while (current != null && current != Object.class) {
@@ -86,11 +86,11 @@ public void fillSchema(final org.eclipse.microprofile.openapi.models.Components
}
}
} else {
schema.items(new SchemaImpl());
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
if (ParameterizedType.class.isInstance(model)) {
final ParameterizedType pt = ParameterizedType.class.cast(model);
if (pt.getActualTypeArguments().length == 1 && Class.class.isInstance(pt.getActualTypeArguments()[0])) {
schema.items(new SchemaImpl());
fillSchema(components, Class.class.cast(pt.getActualTypeArguments()[0]), schema.getItems());
}
}
@@ -156,7 +156,27 @@ public Class<?> getDeclaringClass() {
@Override
public AnnotatedTypeElement[] getParameters() {
return Stream.of(delegate.getParameters())
.map(p -> new ClassElement(p.getType()))
.map(p -> new AnnotatedTypeElement() {
@Override
public Type getType() {
return p.getParameterizedType();
}

@Override
public <T extends Annotation> T getAnnotation(final Class<T> annotationClass) {
return p.getAnnotation(annotationClass);
}

@Override
public Annotation[] getAnnotations() {
return p.getAnnotations();
}

@Override
public Annotation[] getDeclaredAnnotations() {
return p.getDeclaredAnnotations();
}
})
.toArray(AnnotatedTypeElement[]::new);
}

0 comments on commit abd695b

Please sign in to comment.