Skip to content
Permalink
Browse files
GERONIMO-6614 flagging map as object for schemas
  • Loading branch information
rmannibucau committed Aug 1, 2018
1 parent abd695b commit 5e3fb88db681a39b0fdf32e1bdd4806c313e8079
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
@@ -348,7 +348,9 @@ private Operation buildOperation(final OpenAPI api, final AnnotatedMethodElement
(!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))
.ifPresent(p -> operation.requestBody(mapRequestBody(
produces.filter(it -> !it.isEmpty()).map(it -> it.iterator().next()).orElse(null), p,
api.getComponents(), ofNullable(p.getAnnotation(RequestBody.class))
.orElseGet(() -> m.getAnnotation(RequestBody.class)))));
return operation;
}
@@ -451,7 +453,7 @@ private void processComponents(final OpenAPI api, final Components components) {
if (components.requestBodies().length > 0) {
impl.requestBodies(Stream.of(components.requestBodies())
.collect(toMap(it -> of(it.name()).filter(n -> !n.isEmpty()).orElseGet(it::ref),
it -> mapRequestBody(impl, it))));
it -> mapRequestBody(null, null, impl, it))));
}
if (components.parameters().length > 0) {
impl.parameters(Stream.of(components.parameters())
@@ -587,7 +589,7 @@ private org.eclipse.microprofile.openapi.models.callbacks.Callback mapCallback(
if (co.parameters().length > 0) {
operation.parameters(mapParameters(components, co.parameters()));
}
operation.requestBody(mapRequestBody(components, co.requestBody()));
operation.requestBody(mapRequestBody(null, null, components, co.requestBody()));
if (co.security().length > 0) {
operation.security(Stream.of(co.security()).map(this::mapSecurity).collect(toList()));
}
@@ -674,7 +676,9 @@ private org.eclipse.microprofile.openapi.models.links.Link mapLink(final Link li
}

private org.eclipse.microprofile.openapi.models.parameters.RequestBody mapRequestBody(
final org.eclipse.microprofile.openapi.models.Components components, final RequestBody requestBody) {
final String defaultContentType, final AnnotatedTypeElement param,
final org.eclipse.microprofile.openapi.models.Components components,
final RequestBody requestBody) {

final org.eclipse.microprofile.openapi.models.parameters.RequestBody impl = new RequestBodyImpl()
.content(new ContentImpl());
@@ -689,6 +693,12 @@ private org.eclipse.microprofile.openapi.models.parameters.RequestBody mapReques
impl.getContent().putAll(Stream.of(requestBody.content()).collect(toMap(
it -> of(it.mediaType()).filter(v -> !v.isEmpty()).orElse("*/*"),
it -> mapContent(components, it))));
} else if (param != null && defaultContentType != null) {
impl.required(true);
}
if (impl.getContent().isEmpty() && param != null && defaultContentType != null) {
impl.getContent().put(defaultContentType, new MediaTypeImpl()
.schema(schemaProcessor.mapSchemaFromClass(components, param.getType())));
}
return impl;
}
@@ -87,12 +87,18 @@ 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])) {
if (Class.class.isInstance(pt.getRawType()) && Map.class.isAssignableFrom(Class.class.cast(pt.getRawType()))) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.OBJECT);
} else if (pt.getActualTypeArguments().length == 1 && Class.class.isInstance(pt.getActualTypeArguments()[0])) {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
fillSchema(components, Class.class.cast(pt.getActualTypeArguments()[0]), schema.getItems());
} else {
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
}
} else { // todo?
schema.type(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType.ARRAY);
}
}
}

0 comments on commit 5e3fb88

Please sign in to comment.