Skip to content

Commit e12665b

Browse files
committed
feat: Add dubbo sample with CI validation
Adds a new sample generator configuration for dubbo. The existing GitHub workflow for Java samples is updated to build and test this new sample automatically.
1 parent 55d4eae commit e12665b

24 files changed

Lines changed: 1820 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Samples Java Dubbo
2+
3+
on:
4+
push:
5+
paths:
6+
- 'samples/server/petstore/java-dubbo/**'
7+
pull_request:
8+
paths:
9+
- 'samples/server/petstore/java-dubbo/**'
10+
11+
jobs:
12+
build:
13+
name: Build Java Dubbo
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
sample:
19+
# servers
20+
- samples/server/petstore/java-dubbo
21+
steps:
22+
- uses: actions/checkout@v5
23+
- uses: actions/setup-java@v5
24+
with:
25+
distribution: 'temurin'
26+
java-version: 17
27+
- name: Cache maven dependencies
28+
uses: actions/cache@v4
29+
env:
30+
cache-name: maven-repository
31+
with:
32+
path: |
33+
~/.m2
34+
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
35+
- name: Build
36+
working-directory: ${{ matrix.sample }}
37+
run: mvn clean package --no-transfer-progress

bin/configs/java-dubbo-server.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
generatorName: dubbo
2+
outputDir: samples/server/petstore/java-dubbo
3+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore.yaml
4+
templateDir: modules/openapi-generator/src/main/resources/java-dubbo
5+
additionalProperties:
6+
hideGenerationTimestamp: "true"
7+
artifactId: openapi-dubbo-server-petstore
8+
basePackage: "org.openapitools.example"
9+
title: "OpenAPI Petstore"
10+
serviceInterface: true
11+
serviceImplementation: true
12+
useTags: true
13+
dubboVersion: "3.2.18"
14+
javaVersion: "17"
15+
registryAddress: "zookeeper://127.0.0.1:2181"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# IMPORTANT: this file is generated with the option `openapiGeneratorIgnoreList` enabled
2+
# (--openapi-generator-ignore-list in CLI for example) so the entries below are pre-populated based
3+
# on the input provided by the users and this file will be overwritten every time when the option is
4+
# enabled (which is the exact opposite of the default behaviour to not overwrite
5+
# .openapi-generator-ignore if the file exists).
6+
7+
# OpenAPI Generator Ignore
8+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
9+
10+
# Use this file to prevent files from being overwritten by the generator.
11+
# The patterns follow closely to .gitignore or .dockerignore.
12+
13+
# As an example, the C# client generator defines ApiClient.cs.
14+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
15+
#ApiClient.cs
16+
17+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
18+
#foo/*/qux
19+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
20+
21+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
22+
#foo/**/qux
23+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
24+
25+
# You can also negate patterns with an exclamation (!).
26+
# For example, you can ignore all files in a docs folder with the file extension .md:
27+
#docs/*.md
28+
# Then explicitly reverse the ignore rule for a single file:
29+
#!docs/README.md
30+
31+
# The following entries are pre-populated based on the input obtained via
32+
# the option `openapiGeneratorIgnoreList` (--openapi-generator-ignore-list in CLI for example).
33+
# Dubbo generator explicitly disables .openapi-generator-ignore
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
README.md
2+
pom.xml
3+
src/main/java/org/openapitools/example/OpenAPI PetstoreApplication.java
4+
src/main/java/org/openapitools/example/api/consumer/PetServiceController.java
5+
src/main/java/org/openapitools/example/api/consumer/StoreServiceController.java
6+
src/main/java/org/openapitools/example/api/consumer/UserServiceController.java
7+
src/main/java/org/openapitools/example/api/interfaces/PetService.java
8+
src/main/java/org/openapitools/example/api/interfaces/StoreService.java
9+
src/main/java/org/openapitools/example/api/interfaces/UserService.java
10+
src/main/java/org/openapitools/example/api/provider/PetServiceImpl.java
11+
src/main/java/org/openapitools/example/api/provider/StoreServiceImpl.java
12+
src/main/java/org/openapitools/example/api/provider/UserServiceImpl.java
13+
src/main/java/org/openapitools/example/model/Category.java
14+
src/main/java/org/openapitools/example/model/ModelApiResponse.java
15+
src/main/java/org/openapitools/example/model/Order.java
16+
src/main/java/org/openapitools/example/model/Pet.java
17+
src/main/java/org/openapitools/example/model/Tag.java
18+
src/main/java/org/openapitools/example/model/User.java
19+
src/main/resources/application.yml
20+
src/test/java/org/openapitools/example/OpenAPI PetstoreApplicationTests.java
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.16.0-SNAPSHOT
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.openapitools</groupId>
7+
<artifactId>openapi-dubbo-server-petstore</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>OpenAPI Petstore</name>
12+
<description>This is a sample server Petstore server. For this sample, you can use the api key &#x60;special-key&#x60; to test the authorization filters.</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.7.18</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<java.version>17</java.version>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
25+
<dubbo.version>3.2.18</dubbo.version>
26+
</properties>
27+
28+
<dependencies>
29+
<!-- Spring Boot Web Starter -->
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-web</artifactId>
33+
</dependency>
34+
35+
<!-- Dubbo Spring Boot Starter -->
36+
<dependency>
37+
<groupId>org.apache.dubbo</groupId>
38+
<artifactId>dubbo-spring-boot-starter</artifactId>
39+
<version>${dubbo.version}</version>
40+
</dependency>
41+
42+
<!-- Dubbo -->
43+
<dependency>
44+
<groupId>org.apache.dubbo</groupId>
45+
<artifactId>dubbo</artifactId>
46+
<version>${dubbo.version}</version>
47+
</dependency>
48+
<!-- 注册中心依赖 - 根据Dubbo版本和registry-address自动选择 -->
49+
<!-- 当前配置: zookeeper://127.0.0.1:2181 (Dubbo 3.2.18) -->
50+
51+
<!-- Zookeeper 注册中心依赖 -->
52+
<!-- Dubbo 3.2 及之前版本使用聚合依赖 -->
53+
<dependency>
54+
<groupId>org.apache.dubbo</groupId>
55+
<artifactId>dubbo-dependencies-zookeeper</artifactId>
56+
<version>${dubbo.version}</version>
57+
<type>pom</type>
58+
</dependency>
59+
60+
61+
62+
63+
<!-- Test Dependencies -->
64+
<dependency>
65+
<groupId>org.springframework.boot</groupId>
66+
<artifactId>spring-boot-starter-test</artifactId>
67+
<scope>test</scope>
68+
</dependency>
69+
</dependencies>
70+
71+
<build>
72+
<plugins>
73+
<plugin>
74+
<groupId>org.springframework.boot</groupId>
75+
<artifactId>spring-boot-maven-plugin</artifactId>
76+
</plugin>
77+
<plugin>
78+
<groupId>org.apache.maven.plugins</groupId>
79+
<artifactId>maven-compiler-plugin</artifactId>
80+
<version>3.8.1</version>
81+
<configuration>
82+
<source>${java.version}</source>
83+
<target>${java.version}</target>
84+
<encoding>${project.build.sourceEncoding}</encoding>
85+
</configuration>
86+
</plugin>
87+
</plugins>
88+
</build>
89+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.openapitools.example;
2+
3+
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
4+
import org.springframework.boot.SpringApplication;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
7+
@SpringBootApplication
8+
@EnableDubbo(scanBasePackages = "org.openapitools.example")
9+
public class OpenAPIPetstoreApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(OpenAPIPetstoreApplication.class, args);
13+
}
14+
15+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.openapitools.example.api.consumer;
2+
3+
import org.openapitools.example.model.ModelApiResponse;
4+
import org.openapitools.example.model.Pet;
5+
import org.openapitools.example.model.*;
6+
import org.openapitools.example.api.interfaces.PetService;
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.time.OffsetDateTime;
10+
import java.time.LocalDate;
11+
import java.time.LocalDateTime;
12+
import org.apache.dubbo.config.annotation.DubboReference;
13+
import org.springframework.web.bind.annotation.*;
14+
import javax.annotation.Generated;
15+
16+
17+
@Generated(value = "org.openapitools.codegen.languages.DubboCodegen", comments = "Generator version: 7.16.0-SNAPSHOT")
18+
19+
@RestController
20+
@RequestMapping("/pet")
21+
public class PetServiceController {
22+
23+
@DubboReference
24+
private PetService petService;
25+
26+
@RequestMapping(method = RequestMethod.POST, value = "/")
27+
public Pet addPet(
28+
@RequestParam(name = "pet") Pet pet
29+
) {
30+
return petService.addPet(pet);
31+
}
32+
33+
@RequestMapping(method = RequestMethod.DELETE, value = "/{petId}")
34+
public void deletePet(
35+
@RequestParam(name = "petId") Long petId,
36+
@RequestParam(name = "apiKey") String apiKey
37+
) {
38+
petService.deletePet(petId, apiKey);
39+
}
40+
41+
@RequestMapping(method = RequestMethod.GET, value = "/findByStatus")
42+
public List<Pet> findPetsByStatus(
43+
@RequestParam(name = "status") List<String> status
44+
) {
45+
return petService.findPetsByStatus(status);
46+
}
47+
48+
@RequestMapping(method = RequestMethod.GET, value = "/findByTags")
49+
public List<Pet> findPetsByTags(
50+
@RequestParam(name = "tags") List<String> tags
51+
) {
52+
return petService.findPetsByTags(tags);
53+
}
54+
55+
@RequestMapping(method = RequestMethod.GET, value = "/{petId}")
56+
public Pet getPetById(
57+
@RequestParam(name = "petId") Long petId
58+
) {
59+
return petService.getPetById(petId);
60+
}
61+
62+
@RequestMapping(method = RequestMethod.PUT, value = "/")
63+
public Pet updatePet(
64+
@RequestParam(name = "pet") Pet pet
65+
) {
66+
return petService.updatePet(pet);
67+
}
68+
69+
@RequestMapping(method = RequestMethod.POST, value = "/{petId}")
70+
public void updatePetWithForm(
71+
@RequestParam(name = "petId") Long petId,
72+
@RequestParam(name = "name") String name,
73+
@RequestParam(name = "status") String status
74+
) {
75+
petService.updatePetWithForm(petId, name, status);
76+
}
77+
78+
@RequestMapping(method = RequestMethod.POST, value = "/{petId}/uploadImage")
79+
public ModelApiResponse uploadFile(
80+
@RequestParam(name = "petId") Long petId,
81+
@RequestParam(name = "additionalMetadata") String additionalMetadata,
82+
@RequestParam(name = "_file") org.springframework.web.multipart.MultipartFile _file
83+
) {
84+
return petService.uploadFile(petId, additionalMetadata, _file);
85+
}
86+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.openapitools.example.api.consumer;
2+
3+
import org.openapitools.example.model.Order;
4+
import org.openapitools.example.model.*;
5+
import org.openapitools.example.api.interfaces.StoreService;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.time.OffsetDateTime;
9+
import java.time.LocalDate;
10+
import java.time.LocalDateTime;
11+
import org.apache.dubbo.config.annotation.DubboReference;
12+
import org.springframework.web.bind.annotation.*;
13+
import javax.annotation.Generated;
14+
15+
16+
@Generated(value = "org.openapitools.codegen.languages.DubboCodegen", comments = "Generator version: 7.16.0-SNAPSHOT")
17+
18+
@RestController
19+
@RequestMapping("/store")
20+
public class StoreServiceController {
21+
22+
@DubboReference
23+
private StoreService storeService;
24+
25+
@RequestMapping(method = RequestMethod.DELETE, value = "/order/{orderId}")
26+
public void deleteOrder(
27+
@RequestParam(name = "orderId") String orderId
28+
) {
29+
storeService.deleteOrder(orderId);
30+
}
31+
32+
@RequestMapping(method = RequestMethod.GET, value = "/inventory")
33+
public Map<String, Integer> getInventory(
34+
) {
35+
return storeService.getInventory();
36+
}
37+
38+
@RequestMapping(method = RequestMethod.GET, value = "/order/{orderId}")
39+
public Order getOrderById(
40+
@RequestParam(name = "orderId") Long orderId
41+
) {
42+
return storeService.getOrderById(orderId);
43+
}
44+
45+
@RequestMapping(method = RequestMethod.POST, value = "/order")
46+
public Order placeOrder(
47+
@RequestParam(name = "order") Order order
48+
) {
49+
return storeService.placeOrder(order);
50+
}
51+
}

0 commit comments

Comments
 (0)