Skip to content

Commit

Permalink
add spring server generator
Browse files Browse the repository at this point in the history
Committed-by: [email protected] from Dev container
  • Loading branch information
zhanglei1949 committed Jan 13, 2025
1 parent 6f55b76 commit 976cc1a
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 106 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ flex/interactive/sdk/python/gs_interactive/rest.py
!flex/interactive/sdk/python/gs_interactive/models/long_text.py


interactive_engine/groot-http/.openapi-generator/
interactive_engine/groot-http/src/test/
interactive_engine/groot-http/src/main/resources/
interactive_engine/groot-http/src/main/java/org/
interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/api/
interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/
interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/*.java
!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java
!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java
!interactive_engine/groot-http/src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java

**/.cache/

**/*.ci-friendly-pom.xml
Expand Down
18 changes: 18 additions & 0 deletions flex/interactive/sdk/generate_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ function do_gen_python() {
eval $cmd
}


function do_gen_spring() {
echo "Generating Spring API"
OUTPUT_PATH="${CUR_DIR}/../../../interactive_engine/groot-http"
GROOT_PACKAGE_NAME="com.alibaba.graphscope.groot"
GROOT_ARTIFACT_ID="groot-http"
additional_properties="apiPackage=${GROOT_PACKAGE_NAME}.service.api,modelPackage=${GROOT_PACKAGE_NAME}.service.models,artifactId=${GROOT_ARTIFACT_ID},groupId=${GROUP_ID},invokerPackage=${GROOT_PACKAGE_NAME}"
export JAVA_OPTS="-Dlog.level=${LOG_LEVEL}"
cmd="openapi-generator-cli generate -i ${OPENAPI_SPEC_PATH} -g spring -o ${OUTPUT_PATH}"
cmd=" ${cmd} --additional-properties=${additional_properties}"
echo "Running command: ${cmd}"

eval $cmd
}

function do_gen() {
# expect only one argument
if [ $# -ne 1 ]; then
Expand All @@ -97,6 +112,9 @@ function do_gen() {
python)
do_gen_python
;;
spring)
do_gen_spring
;;
*)
err "Unsupported language: $lang"
usage
Expand Down
165 changes: 59 additions & 106 deletions flex/openapi/openapi_interactive.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1320,137 +1320,91 @@ components:
$ref: '#/components/schemas/AnyValue'
PrimitiveType:
x-body-name: primitive_type
allOf:
- $ref: '#/components/schemas/BaseGSDataType'
- type: object
required:
- primitive_type
properties:
primitive_type:
type: string
enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64,
DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING]
# The DT_STRING is added for backward compatibility, it should be replaced by StringType
example: DT_SIGNED_INT32
BaseStringType:
x-body-name: base_string_type
type: object
required:
- string_type
required:
- primitive_type
properties:
string_type:
primitive_type:
type: string
discriminator:
propertyName: string_type
# enum: [DT_SIGNED_INT32, DT_UNSIGNED_INT32, DT_SIGNED_INT64, DT_UNSIGNED_INT64,
# DT_BOOL, DT_FLOAT, DT_DOUBLE, DT_STRING]
# The DT_STRING is added for backward compatibility, it should be replaced by StringType
example: DT_SIGNED_INT32
LongText:
x-body-name: long_text
allOf:
- $ref: '#/components/schemas/BaseStringType'
- type: object
additionalProperties: false
required:
- long_text
properties:
long_text:
type: string
nullable: true
type: object
additionalProperties: false
required:
- long_text
properties:
long_text:
type: string
nullable: true
FixedChar:
x-body-name: fixed_char
allOf:
- $ref: '#/components/schemas/BaseStringType'
- type: object
additionalProperties: false
type: object
additionalProperties: false
required:
- char
properties:
char:
type: object
required:
- char
- fixed_length
properties:
char:
type: object
required:
- fixed_length
properties:
fixed_length:
type: integer
fixed_length:
type: integer
VarChar:
x-body-name: var_char
allOf:
- $ref: '#/components/schemas/BaseStringType'
- type: object
additionalProperties: false
type: object
additionalProperties: false
required:
- var_char
properties:
var_char:
type: object
required:
- var_char
- max_length
properties:
var_char:
type: object
required:
- max_length
properties:
max_length:
type: integer
max_length:
type: integer
StringType:
x-body-name: string_type
allOf:
- $ref: '#/components/schemas/BaseGSDataType'
- type: object
required:
- string
properties:
string:
oneOf:
- $ref: '#/components/schemas/LongText'
- $ref: '#/components/schemas/FixedChar'
- $ref: '#/components/schemas/VarChar'
BaseTemporalType:
x-body-name: base_temporal_type
type: object
required:
- temporal_type
required:
- string
properties:
temporal_type:
type: string
discriminator:
propertyName: temporal_type
string:
oneOf:
- $ref: '#/components/schemas/LongText'
- $ref: '#/components/schemas/FixedChar'
- $ref: '#/components/schemas/VarChar'
TimeStampType:
x-body-name: time_stamp_type
allOf:
- $ref: '#/components/schemas/BaseTemporalType'
- type: object
required:
- timestamp
properties:
timestamp:
type: string
type: object
required:
- timestamp
properties:
timestamp:
type: string
DateType:
x-body-name: date_type
allOf:
- $ref: '#/components/schemas/BaseTemporalType'
- type: object
required:
- date32
properties:
date32:
type: string
type: object
required:
- date32
properties:
date32:
type: string
TemporalType:
x-body-name: temporal_type
allOf:
- $ref: '#/components/schemas/BaseGSDataType'
- type: object
required:
- temporal
properties:
temporal:
oneOf:
- $ref: '#/components/schemas/TimeStampType'
- $ref: '#/components/schemas/DateType'
BaseGSDataType:
x-body-name: base_gs_data_type
type: object
required:
- type_name
- temporal
properties:
type_name:
type: string
discriminator:
propertyName: type_name
temporal:
oneOf:
- $ref: '#/components/schemas/TimeStampType'
- $ref: '#/components/schemas/DateType'
GSDataType:
x-body-name: gs_data_type
oneOf:
Expand Down Expand Up @@ -2157,4 +2111,3 @@ components:
type: array
items:
$ref: '#/components/schemas/EdgeRequest'

31 changes: 31 additions & 0 deletions interactive_engine/groot-http/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

src/main/java/com/alibaba/graphscope/groot/service/models/GSDataType.java
src/main/java/com/alibaba/graphscope/groot/service/models/StringTypeString.java
src/main/java/com/alibaba/graphscope/groot/service/models/TemporalTypeTemporal.java

README.md

pom.xml
21 changes: 21 additions & 0 deletions interactive_engine/groot-http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# OpenAPI generated server

Spring Boot Server

## Overview
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.


The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
The specification is available to download using the following url:
http://localhost:8080/v3/api-docs/

Start your server as a simple java application

You can view the api documentation in swagger-ui by pointing to
http://localhost:8080/swagger-ui.html

Change default port value in application.properties
82 changes: 82 additions & 0 deletions interactive_engine/groot-http/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.graphscope</groupId>
<artifactId>groot-http</artifactId>
<packaging>jar</packaging>
<name>groot-http</name>
<version>1.0.0</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<springdoc.version>1.6.14</springdoc.version>
<swagger-ui.version>5.3.1</swagger-ui.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.15</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<!--SpringDoc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
<!-- @Nullable annotation -->
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading

0 comments on commit 976cc1a

Please sign in to comment.