This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new f8a4d0d22 add openapi sample (#1197)
f8a4d0d22 is described below

commit f8a4d0d2256e1222b253ef1d389c30e0a827fe82
Author: heliang666s <[email protected]>
AuthorDate: Thu Jan 16 12:24:45 2025 +0800

    add openapi sample (#1197)
---
 .../case-configuration.yml                         | 48 ++++++++++++
 .../case-versions.conf                             | 23 ++++++
 .../pom.xml                                        | 86 ++++++++++++++++++++++
 .../org/apache/dubbo/rest/demo/DemoService.java    | 31 ++++++++
 .../apache/dubbo/rest/demo/DemoServiceImpl.java    | 34 +++++++++
 .../apache/dubbo/rest/demo/OpenApiApplication.java | 33 +++++++++
 .../main/java/org/apache/dubbo/rest/demo/User.java | 42 +++++++++++
 .../src/main/resources/application.yml             | 35 +++++++++
 .../src/main/resources/log4j2.xml                  | 32 ++++++++
 .../apache/dubbo/rest/demo/test/ConsumerIT.java    | 51 +++++++++++++
 2-advanced/dubbo-samples-triple-rest/pom.xml       |  1 +
 11 files changed, 416 insertions(+)

diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-configuration.yml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-configuration.yml
new file mode 100644
index 000000000..e9bcca477
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-configuration.yml
@@ -0,0 +1,48 @@
+# 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.
+
+services:
+  zookeeper:
+    image: zookeeper:latest
+
+  provider:
+    type: app
+    basedir: .
+    mainClass: org.apache.dubbo.rest.demo.OpenApiApplication
+    systemProps:
+      - zookeeper.address=zookeeper
+      - zookeeper.port=2181
+      - dubbo.port=50052
+    waitPortsBeforeRun:
+      - zookeeper:2181
+    checkPorts:
+      - 50052
+    checkLog: "dubbo service started"
+    depends_on:
+      - zookeeper
+      -
+  test:
+    type: test
+    basedir: .
+    tests:
+      - "**/*IT.class"
+    systemProps:
+      - dubbo.address=provider
+    waitPortsBeforeRun:
+      - provider:50052
+    depends_on:
+      - provider
+
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-versions.conf
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-versions.conf
new file mode 100644
index 000000000..f2f919d31
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/case-versions.conf
@@ -0,0 +1,23 @@
+#
+# 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.
+#
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.3.*
+spring.version=6.*
+java.version= [>= 17]
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/pom.xml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/pom.xml
new file mode 100644
index 000000000..afd8138dd
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0";
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.dubbo</groupId>
+    <artifactId>dubbo-samples-triple-rest</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+    <relativePath>../pom.xml</relativePath>
+  </parent>
+
+  <artifactId>dubbo-samples-triple-rest-openapi-basic</artifactId>
+
+  <properties>
+    <maven.compiler.source>17</maven.compiler.source>
+    <maven.compiler.target>17</maven.compiler.target>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <dubbo.version>3.3.3-SNAPSHOT</dubbo.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.dubbo</groupId>
+      <artifactId>dubbo-spring-boot-starter</artifactId>
+      <version>${dubbo.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.dubbo</groupId>
+      <artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
+      <version>${dubbo.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.dubbo</groupId>
+      <artifactId>dubbo-rest-openapi</artifactId>
+      <version>${dubbo.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-log4j2</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-test</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
+
+
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
new file mode 100644
index 000000000..10a3f2931
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.rest.demo;
+
+import org.apache.dubbo.remoting.http12.HttpMethods;
+import org.apache.dubbo.remoting.http12.rest.Mapping;
+import org.apache.dubbo.remoting.http12.rest.Param;
+import org.apache.dubbo.remoting.http12.rest.ParamType;
+
+public interface DemoService {
+
+    String hello(User user, int count);
+
+    String helloUser(User user);
+
+}
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
new file mode 100644
index 000000000..71f2abe6c
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.rest.demo;
+
+import org.apache.dubbo.config.annotation.DubboService;
+
+@DubboService
+public class DemoServiceImpl implements DemoService {
+
+    @Override
+    public String hello(User user, int count) {
+        return "Hello " + user.getTitle() + ". " + user.getName() + ", " + 
count;
+    }
+
+    @Override
+    public String helloUser(User user) {
+        return "Hello " + user.getTitle() + ". " + user.getName();
+    }
+}
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/OpenApiApplication.java
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/OpenApiApplication.java
new file mode 100644
index 000000000..e628b9f0f
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/OpenApiApplication.java
@@ -0,0 +1,33 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.rest.demo;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+@EnableDubbo
+public class OpenApiApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(OpenApiApplication.class, args);
+        System.out.println("dubbo service started");
+    }
+}
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/User.java
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/User.java
new file mode 100644
index 000000000..15d34d6ca
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/java/org/apache/dubbo/rest/demo/User.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.rest.demo;
+
+public class User {
+
+    private String title;
+
+    private String name;
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+}
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/application.yml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/application.yml
new file mode 100644
index 000000000..ea7335cd1
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/application.yml
@@ -0,0 +1,35 @@
+# 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.
+
+spring:
+  application:
+    name: dubbo-springboot-triple-rest-openapi
+dubbo:
+  application:
+    name: ${spring.application.name}
+    qos-enable: false
+  protocol:
+    name: tri
+    port: 50052
+    triple:
+      rest:
+        openapi:
+          enabled: true
+  registry:
+    id: zk-registry
+    address: zookeeper://127.0.0.1:2181
+server:
+  port: 8082
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/log4j2.xml
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/log4j2.xml
new file mode 100644
index 000000000..f21b6cb1c
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/main/resources/log4j2.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+<Configuration status="WARN">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT" follow="true">
+            <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta} 
%style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue} 
%style{-|}{White} 
%m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}" 
disableAnsi="false" charset="UTF-8"/>
+        </Console>
+    </Appenders>
+    <Loggers>
+        <Root level="info">
+            <AppenderRef ref="Console"/>
+        </Root>
+        <Logger name="org.apache.dubbo.rpc.protocol.tri" level="debug"/>
+        <Logger name="org.apache.dubbo.remoting.http12" level="debug"/>
+        <Logger name="org.apache.dubbo.config" level="warn"/>
+    </Loggers>
+</Configuration>
diff --git 
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
new file mode 100644
index 000000000..837be147d
--- /dev/null
+++ 
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-basic/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+package org.apache.dubbo.rest.demo.test;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.web.client.RestClient;
+
+
+@SpringBootTest
+public class ConsumerIT {
+
+    private static final String HOST = System.getProperty("dubbo.address", 
"localhost");
+    private final RestClient webClient = RestClient.create();
+
+    @DubboReference(url = "tri://${dubbo.address:localhost}:50052")
+
+    private static String toUri(String path) {
+        return "http://"; + HOST + ":50052/" + path;
+    }
+
+    @Test
+    public void helloWithRest() {
+        String result = webClient.get().
+                uri(toUri("/dubbo/openapi/api-docs")).
+                retrieve().
+                body(String.class);
+        System.out.println(result);
+        Assert.assertNotNull("OpenAPI documentation response should not be 
null", result);
+        
Assert.assertTrue(result.contains("/org.apache.dubbo.rest.demo.DemoService/hello"));
+        
Assert.assertTrue(result.contains("/org.apache.dubbo.rest.demo.DemoService/helloUser"));
+    }
+}
diff --git a/2-advanced/dubbo-samples-triple-rest/pom.xml 
b/2-advanced/dubbo-samples-triple-rest/pom.xml
index d0910334d..be051a32a 100644
--- a/2-advanced/dubbo-samples-triple-rest/pom.xml
+++ b/2-advanced/dubbo-samples-triple-rest/pom.xml
@@ -46,6 +46,7 @@
     <module>dubbo-samples-triple-rest-basic</module>
     <module>dubbo-samples-triple-rest-jaxrs</module>
     <module>dubbo-samples-triple-rest-springmvc</module>
+    <module>dubbo-samples-triple-rest-openapi-basic</module>
     <module>dubbo-samples-triple-rest-spring-security</module>
   </modules>
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to