This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch openapi2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9356982806e90aaade3e85d52be036df7155491b Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Mar 27 10:00:21 2024 +0100 CAMEL-20557: Rest DSL to use openapi spec directly --- .../DefaultRestOpenapiProcessorStrategy.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java index 2f4c9eaa996..0ac3b7de488 100644 --- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java +++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/DefaultRestOpenapiProcessorStrategy.java @@ -23,6 +23,7 @@ import java.util.stream.Collectors; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.media.Content; import joptsimple.internal.Strings; import org.apache.camel.AsyncCallback; import org.apache.camel.AsyncProducer; @@ -112,7 +113,25 @@ public class DefaultRestOpenapiProcessorStrategy extends ServiceSupport .map(Enum::name) .sorted() .collect(Collectors.toList()), ","); - phc.addHttpEndpoint(uri, verbs, null, null, null); + String consumes = null; + String produces = null; + for (var o : p.getValue().readOperations()) { + if (o.getRequestBody() != null) { + Content c = o.getRequestBody().getContent(); + if (c != null) { + consumes = Strings.join(c.keySet().stream().sorted().collect(Collectors.toList()), ","); + } + } + if (o.getResponses() != null) { + for (var a : o.getResponses().values()) { + Content c = a.getContent(); + if (c != null) { + produces = Strings.join(c.keySet().stream().sorted().collect(Collectors.toList()), ","); + } + } + } + } + phc.addHttpEndpoint(uri, verbs, consumes, produces, null); uris.add(uri); } }