in geronimo-openapi-impl/src/main/java/org/apache/geronimo/microprofile/openapi/impl/processor/AnnotationProcessor.java [959:1025]
private ParameterImpl mapParameter(
final AnnotatedTypeElement annotatedElement,
final Supplier<org.eclipse.microprofile.openapi.models.Components> components,
final Parameter parameter) {
final ParameterImpl impl = new ParameterImpl();
impl.description(parameter.description());
impl.required(parameter.required());
impl.name(parameter.name());
impl.in(of(parameter.in())
.filter(s -> s != ParameterIn.DEFAULT).map(Enum::name)
.map(org.eclipse.microprofile.openapi.models.parameters.Parameter.In::valueOf)
.orElse(null));
impl.style(of(parameter.style())
.filter(s -> s != ParameterStyle.DEFAULT).map(Enum::name)
.map(org.eclipse.microprofile.openapi.models.parameters.Parameter.Style::valueOf)
.orElse(null));
impl.allowEmptyValue(parameter.allowEmptyValue());
impl.allowReserved(parameter.allowReserved());
impl.schema(ofNullable(schemaProcessor.mapSchema(components, parameter.schema(), null))
.map(s -> s.externalDocs(mapExternalDocumentation(parameter.schema().externalDocs())))
.orElseGet(() -> {
if (annotatedElement == null) {
return null;
}
return schemaProcessor.mapSchemaFromClass(components, annotatedElement.getType());
}));
if (impl.getSchema() != null && impl.getSchema().getType() == null && annotatedElement != null) {
schemaProcessor.fillSchema(components, annotatedElement.getType(), impl.getSchema(), null);
}
of(parameter.content()).filter(it -> it.length > 0).map(Stream::of).ifPresent(c -> {
final ContentImpl content = new ContentImpl();
content.putAll(c.collect(
toMap(it -> of(it.mediaType()).filter(v -> !v.isEmpty()).orElse("*/*"), it -> {
final MediaType mediaType = mapContent(components, it);
if (mediaType.getSchema() == null && annotatedElement != null) {
mediaType.schema(schemaProcessor.mapSchemaFromClass(components, annotatedElement.getType()));
}
return mediaType;
})));
impl.content(content);
});
of(parameter.example()).filter(v -> !v.isEmpty()).ifPresent(impl::example);
if (parameter.examples().length > 0) {
impl.examples(Stream.of(parameter.examples()).collect(toMap(
it -> of(it.name()).filter(n -> !n.isEmpty()).orElseGet(() -> it.ref()), this::mapExample)));
}
if (annotatedElement != null) {
if (annotatedElement.isAnnotationPresent(HeaderParam.class)) {
final HeaderParam annotation = annotatedElement.getAnnotation(HeaderParam.class);
impl.in(org.eclipse.microprofile.openapi.models.parameters.Parameter.In.HEADER);
mapParameterName(impl, annotation.value());
} else if (annotatedElement.isAnnotationPresent(CookieParam.class)) {
final CookieParam annotation = annotatedElement.getAnnotation(CookieParam.class);
impl.in(org.eclipse.microprofile.openapi.models.parameters.Parameter.In.COOKIE);
mapParameterName(impl, annotation.value());
} else if (annotatedElement.isAnnotationPresent(PathParam.class)) {
final PathParam annotation = annotatedElement.getAnnotation(PathParam.class);
impl.in(org.eclipse.microprofile.openapi.models.parameters.Parameter.In.PATH);
mapParameterName(impl, annotation.value());
} else if (annotatedElement.isAnnotationPresent(QueryParam.class)) {
final QueryParam annotation = annotatedElement.getAnnotation(QueryParam.class);
impl.in(org.eclipse.microprofile.openapi.models.parameters.Parameter.In.QUERY);
mapParameterName(impl, annotation.value());
}
}
return impl;
}