-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dubbo-triple-rest-swagger samples
- Loading branch information
1 parent
609d867
commit 11bf02b
Showing
11 changed files
with
509 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...vanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-swagger/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,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.SwaggerApplication | ||
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
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-swagger/case-versions.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] |
67 changes: 67 additions & 0 deletions
67
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-swagger/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,67 @@ | ||
<?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> | ||
</parent> | ||
|
||
<artifactId>dubbo-samples-triple-rest-swagger</artifactId> | ||
|
||
<properties> | ||
<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.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> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rest-swagger</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> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
82 changes: 82 additions & 0 deletions
82
...samples-triple-rest-swagger/src/main/java/org/apache/dubbo/rest/swagger/HelloService.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,82 @@ | ||
/* | ||
* 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.swagger; | ||
|
||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; | ||
|
||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.info.Contact; | ||
import io.swagger.v3.oas.annotations.info.Info; | ||
import io.swagger.v3.oas.annotations.info.License; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@OpenAPIDefinition( | ||
info = @Info( | ||
title = "Dubbo Greeting API", | ||
version = "1.0.0", | ||
description = "This API provides greeting and health-check services.", | ||
contact = @Contact( | ||
name = "Dubbo Support", | ||
email = "[email protected]", | ||
url = "https://github.com/apache/dubbo/" | ||
|
||
), | ||
license = @License( | ||
name = "Apache 2.0", | ||
url = "https://www.apache.org/licenses/LICENSE-2.0.html" | ||
) | ||
), | ||
tags = { | ||
@Tag(name = "HelloService", description = "Provides greeting and health-check operations.") | ||
} | ||
) | ||
@EnableDubbo | ||
public interface HelloService { | ||
/** | ||
* Returns a personalized greeting message based on the user's details. | ||
* | ||
* @param user The user object containing details. | ||
* @return A greeting message. | ||
*/ | ||
@Operation(summary = "Get personalized greeting", description = "Returns a greeting message based on the user's details") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "Successfully returned greeting"), | ||
@ApiResponse(responseCode = "400", description = "Invalid user data provided"), | ||
@ApiResponse(responseCode = "500", description = "Internal server error") | ||
}) | ||
String sayHello( | ||
@Parameter(description = "The user object containing user details", required = true) | ||
User user | ||
); | ||
|
||
/** | ||
* Checks the health status of the service. | ||
* | ||
* @return Health status of the service. | ||
*/ | ||
@Operation(summary = "Health Check", description = "Checks if the service is running properly.") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", description = "Service is healthy"), | ||
@ApiResponse(responseCode = "500", description = "Service is down") | ||
}) | ||
String healthCheck(); | ||
} |
47 changes: 47 additions & 0 deletions
47
...les-triple-rest-swagger/src/main/java/org/apache/dubbo/rest/swagger/HelloServiceImpl.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,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. | ||
*/ | ||
package org.apache.dubbo.rest.swagger; | ||
|
||
import org.apache.dubbo.config.annotation.DubboService; | ||
|
||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
/** | ||
* Implementation of HelloService interface. | ||
*/ | ||
@DubboService | ||
public class HelloServiceImpl implements HelloService { | ||
|
||
@Override | ||
public String sayHello(User user) { | ||
return "Hello, " + user.getName() + "! You are " + user.getAge() + " years old and enjoy " | ||
+ String.join(", ", user.getHobbies()) + "."; | ||
} | ||
|
||
@Override | ||
public String healthCheck() { | ||
return "Service is running fine."; | ||
} | ||
|
||
/** | ||
* A hidden method not exposed in API documentation. | ||
*/ | ||
@Hidden | ||
public void hiddenMethod() { | ||
System.out.println("This method is hidden and won't appear in the API documentation."); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...s-triple-rest-swagger/src/main/java/org/apache/dubbo/rest/swagger/SwaggerApplication.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,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.swagger; | ||
|
||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
@EnableDubbo | ||
public class SwaggerApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SwaggerApplication.class, args); | ||
System.out.println("dubbo service started"); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...t/dubbo-samples-triple-rest-swagger/src/main/java/org/apache/dubbo/rest/swagger/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,84 @@ | ||
/* | ||
* 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.swagger; | ||
|
||
import java.util.List; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
/** | ||
* Represents a user with details for demonstration purposes. | ||
*/ | ||
@Schema(description = "Represents a user with name, age, and hobbies.") | ||
public class User { | ||
|
||
@Schema(description = "Unique identifier of the user", example = "123") | ||
private Long id; | ||
|
||
@Schema(description = "Name of the user", example = "Liang He") | ||
private String name; | ||
|
||
@Schema(description = "Age of the user", example = "19") | ||
private Integer age; | ||
|
||
@Schema(description = "List of user's hobbies", example = "[\"reading\", \"traveling\"]") | ||
private List<String> hobbies; | ||
|
||
public User() {} | ||
|
||
public User(Long id, String name, Integer age, List<String> hobbies) { | ||
this.id = id; | ||
this.name = name; | ||
this.age = age; | ||
this.hobbies = hobbies; | ||
} | ||
|
||
// Getters and Setters | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(Integer age) { | ||
this.age = age; | ||
} | ||
|
||
public List<String> getHobbies() { | ||
return hobbies; | ||
} | ||
|
||
public void setHobbies(List<String> hobbies) { | ||
this.hobbies = hobbies; | ||
} | ||
} |
Oops, something went wrong.