forked from apache/dubbo-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
609d867
commit 3fa3c5a
Showing
11 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...ubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-advance/case-configuration.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# 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 |
23 changes: 23 additions & 0 deletions
23
...ced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-advance/case-version.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
66 changes: 66 additions & 0 deletions
66
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-openapi-advance/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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</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> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId> | ||
</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> | ||
<version>6.1.5</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
35 changes: 35 additions & 0 deletions
35
...rest-openapi-advance/src/main/java/org/apache/dubbo/rest/openapi/advance/DemoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
|
||
package org.apache.dubbo.rest.openapi.advance; | ||
|
||
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(String name); | ||
|
||
@Mapping(path = "/hi", method = HttpMethods.POST) | ||
String hello(User user, @Param(value = "c", type = ParamType.Header) int count); | ||
|
||
@Mapping | ||
String helloUser(User user); | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...-openapi-advance/src/main/java/org/apache/dubbo/rest/openapi/advance/DemoServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.apache.dubbo.rest.openapi.advance; | ||
|
||
import org.apache.dubbo.config.annotation.DubboService; | ||
import org.apache.dubbo.remoting.http12.rest.OpenAPI; | ||
import org.apache.dubbo.remoting.http12.rest.Operation; | ||
import org.apache.dubbo.remoting.http12.rest.Schema; | ||
|
||
@DubboService | ||
@OpenAPI(infoTitle = "Dubbo OpenAPI", infoDescription = "This API provides greeting services for users.", infoVersion = "v1", docDescription = "API for greeting users with their names and titles.") | ||
public class DemoServiceImpl implements DemoService { | ||
|
||
@Operation(description = "Returns a greeting message with the provided name.") | ||
@Override | ||
public String hello(@Schema(description = "Name of the person to greet") String name) { | ||
return "Hello " + name; | ||
} | ||
|
||
@Operation(description = "Returns a greeting message with user's title and name, along with a count.") | ||
@Override | ||
public String hello( | ||
@Schema(description = "User object containing title and name") User user, | ||
@Schema(description = "Number of times to greet") int count) { | ||
return "Hello " + user.getTitle() + ". " + user.getName() + ", " + count; | ||
} | ||
|
||
@Operation(description = "Returns a greeting message with user's title and name.") | ||
@Override | ||
public String helloUser(@Schema(description = "User object containing title and name") User user) { | ||
return "Hello " + user.getTitle() + ". " + user.getName(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...enapi-advance/src/main/java/org/apache/dubbo/rest/openapi/advance/OpenAPIApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.apache.dubbo.rest.openapi.advance; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class OpenAPIApplication { | ||
public static void main(String[] args) { | ||
SpringApplication.run(OpenAPIApplication.class, args); | ||
System.out.println("dubbo service started"); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...triple-rest-openapi-advance/src/main/java/org/apache/dubbo/rest/openapi/advance/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.apache.dubbo.rest.openapi.advance; | ||
|
||
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; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...-triple-rest/dubbo-samples-triple-rest-openapi-advance/src/main/resources/application.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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-basic | ||
dubbo: | ||
application: | ||
name: ${spring.application.name} | ||
qos-enable: false | ||
protocol: | ||
name: tri | ||
port: 50052 | ||
triple: | ||
verbose: true | ||
triple: | ||
rest: | ||
openapi: | ||
enabled: true | ||
registry: | ||
id: zk-registry | ||
address: zookeeper://127.0.0.1:2181 | ||
server: | ||
port: 8082 |
32 changes: 32 additions & 0 deletions
32
...mples-triple-rest/dubbo-samples-triple-rest-openapi-advance/src/main/resources/log4j2.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
51 changes: 51 additions & 0 deletions
51
...-openapi-advance/src/test/java/org/apache/dubbo/rest/openapi/advance/test/ConsumerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.openapi.advance.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")); | ||
Assert.assertTrue(result.contains("/org.apache.dubbo.rest.demo.DemoService/hi")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters