Skip to content

Commit

Permalink
TSPS-320 Auto-generate thin python client based off of openapi.yml (#132
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mmorgantaylor authored Sep 23, 2024
1 parent ba055dd commit f4465f2
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation 'com.srcclr.gradle:com.srcclr.gradle.gradle.plugin:3.1.12'
implementation 'de.undercouch.download:de.undercouch.download.gradle.plugin:5.1.0'
implementation 'org.hidetake.swagger.generator:org.hidetake.swagger.generator.gradle.plugin:2.19.1'
implementation 'org.sonarqube:org.sonarqube.gradle.plugin:3.4.0.2513'
implementation 'org.sonarqube:org.sonarqube.gradle.plugin:5.1.0.4882'
// This is required due to a dependency conflict between jib and srcclr. Removing it will cause jib to fail.
implementation 'org.apache.commons:commons-compress:1.21'
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ compileJava {
dependsOn(spotlessApply)
}
}

2 changes: 1 addition & 1 deletion client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ dependencyManagement {
}

apply from: 'artifactory.gradle'
apply from: 'swagger.gradle'
apply from: 'java-client.gradle'
File renamed without changes.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 2 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
rootProject.name = 'terra-scientific-pipelines-service'
include('service', 'scripts', 'client', 'rawls-client')

gradle.ext.releaseVersion = "0.0.69-SNAPSHOT"
include 'scripts:git-hooks'
include('service', 'scripts', 'scripts:git-hooks', 'client', 'rawls-client', 'teaspoons-cli')
findProject(':scripts:git-hooks')?.name = 'git-hooks'

gradle.ext.releaseVersion = "0.0.69-SNAPSHOT"
15 changes: 15 additions & 0 deletions teaspoons-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Teaspoons CLI

## Python thin client auto-generation
We use the [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) to generate the "thin" Python client,
which is then used to build the Python-based "thick" CLI tool.

To generate the Python thin client, run the following command:
```bash
./gradlew :teaspoons-cli:openApiGenerate
```

This will produce generated files at `/teaspoons-cli/build/`.

Note we do not run the openApiGenerate task as part of the main Teaspoons build, as it is not necessary for the
service itself and we don't want any potential bugs in the CLI to affect the service.
7 changes: 7 additions & 0 deletions teaspoons-cli/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id 'org.openapi.generator' version '7.8.0'
}

apply plugin: 'java'

apply from: 'teaspoons-client.gradle'
18 changes: 18 additions & 0 deletions teaspoons-cli/teaspoons-client.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tasks.openApiGenerate {
generatorName.set("python")
inputSpec.set("$rootDir/common/openapi.yml")
outputDir.set("$rootDir/teaspoons-cli/build")
configOptions.put("projectName", "teaspoons-client")
configOptions.put("packageName", "teaspoons_client")
configOptions.put("packageVersion", "0.0.0")
configOptions.put("httpUserAgent", "teaspoons-client/0.0.0/python")
}

// we do NOT want to build this project when building the main service project, to prevent a bug in the cli code from breaking the main service build
//compileJava.dependsOn tasks.openApiGenerate

task customCleanUp(type:Delete) {
delete "${rootDir}/teaspoons-cli/build/"
}

tasks.clean.dependsOn(tasks.customCleanUp)

0 comments on commit f4465f2

Please sign in to comment.