You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/05/04 10:51:54 UTC
[camel-kamelets-examples] branch main updated: CAMEL-17819: camel-jbang - Can we support --opena-api like camel-k have
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets-examples.git
The following commit(s) were added to refs/heads/main by this push:
new a02de4b CAMEL-17819: camel-jbang - Can we support --opena-api like camel-k have
a02de4b is described below
commit a02de4b7752ed87b1a0018906c0b524836192d3f
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed May 4 12:51:45 2022 +0200
CAMEL-17819: camel-jbang - Can we support --opena-api like camel-k have
---
.gitignore | 1 +
jbang/open-api/README.md | 24 ++++++++++++++++++++
jbang/open-api/greetings-api.json | 46 +++++++++++++++++++++++++++++++++++++++
jbang/open-api/greetings.groovy | 26 ++++++++++++++++++++++
4 files changed, 97 insertions(+)
diff --git a/.gitignore b/.gitignore
index 2f7896d..4b906b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
target/
+.camel-jbang/
\ No newline at end of file
diff --git a/jbang/open-api/README.md b/jbang/open-api/README.md
new file mode 100644
index 0000000..b81b253
--- /dev/null
+++ b/jbang/open-api/README.md
@@ -0,0 +1,24 @@
+# Open API examples
+
+Find useful examples about how to expose an Open API specification in a Camel integration.
+
+## Greetings example
+
+Run the examples running
+
+```
+camel run --open-api greetings-api.json greetings.groovy
+```
+
+Then you can test by calling the hello endpoint, ie:
+
+```
+$ curl -i http://localhost:8080/camel/greetings/jack
+HTTP/1.1 200 OK
+Accept: */*
+name: hello
+User-Agent: curl/7.68.0
+transfer-encoding: chunked
+
+Hello from jack
+```
\ No newline at end of file
diff --git a/jbang/open-api/greetings-api.json b/jbang/open-api/greetings-api.json
new file mode 100644
index 0000000..48e8f9e
--- /dev/null
+++ b/jbang/open-api/greetings-api.json
@@ -0,0 +1,46 @@
+{
+ "swagger" : "2.0",
+ "info" : {
+ "version" : "1.0",
+ "title" : "Greeting REST API"
+ },
+ "host" : "",
+ "basePath" : "/camel/",
+ "tags" : [ {
+ "name" : "greetings",
+ "description" : "Greeting to {name}"
+ } ],
+ "schemes" : [ "http" ],
+ "paths" : {
+ "/greetings/{name}" : {
+ "get" : {
+ "tags" : [ "greetings" ],
+ "operationId" : "greeting-api",
+ "parameters" : [ {
+ "name" : "name",
+ "in" : "path",
+ "required" : true,
+ "type" : "string"
+ } ],
+ "responses" : {
+ "200" : {
+ "description" : "Output type",
+ "schema" : {
+ "$ref" : "#/definitions/Greetings"
+ }
+ }
+ }
+ }
+ }
+ },
+ "definitions" : {
+ "Greetings" : {
+ "type" : "object",
+ "properties" : {
+ "greetings" : {
+ "type" : "string"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/jbang/open-api/greetings.groovy b/jbang/open-api/greetings.groovy
new file mode 100644
index 0000000..90a09ce
--- /dev/null
+++ b/jbang/open-api/greetings.groovy
@@ -0,0 +1,26 @@
+// camel-k: language=groovy
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+// kamel run --dev --name greetings --open-api greetings-api.json greetings.groovy
+//
+
+from('direct:greeting-api')
+ .to('log:api?showAll=true&multiline=true')
+ .setBody()
+ .simple('Hello from ${headers.name}')