Skip to content

Commit 2c1a204

Browse files
authored
Merge pull request #51 from shinusuresh/update_api_spec_0.23.0
Generate model files as part of build process. Changes forked from PR #27
2 parents 9784d15 + 924900c commit 2c1a204

File tree

60 files changed

+2281
-6985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2281
-6985
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,6 @@ Please note we have a code of conduct, please follow it in all your interactions
99

1010
Before making a PR to this repository look out for the following guidelines.
1111

12-
## Guidelines for updating the client
13-
14-
- Head over to [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) and download the cli jar.
15-
- Download the latest api spec for typesense server from [typesense-api-spec](https://github.com/typesense/typesense-api-spec)
16-
- Create a new `config.json` and add the following content
17-
```json
18-
{
19-
"modelPackage" : "org.typesense.model",
20-
"apiPackage" : "org.typesense.api"
21-
}
22-
```
23-
- Run the following command:
24-
```bash
25-
java --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED \
26-
--add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED \
27-
--add-opens java.desktop/java.awt.font=ALL-UNNAMED -jar ~/apps/swagger-codegen-cli-3.0.20.jar generate \
28-
-i /path/to/typesense-api-spec/openapi.yml -l jaxrs-cxf-client -c config.json -o /tmp/model
29-
```
30-
- Now, copy the content under ```<out-dir>/src/gen/java/org/typesense/model``` and replace it with the content of the ```typesense-java/src/main/java/org/typesense/model``` folder in the `typesense-java` client repository.
31-
- And then make the necessary changes in `api` folder.
32-
33-
**NOTE**: The `model` directory is **read-only** make sure not to edit it.
34-
3512
## Publishing
3613

3714
Publishing requires the presence of a `~/.gradle.properties` file:

build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ plugins {
44
id 'maven-publish'
55
id 'io.github.gradle-nexus.publish-plugin' version "${nexusPluginVersion}"
66
id 'com.github.johnrengelman.shadow' version "${shadowJarPluginVersion}"
7+
id 'org.hidetake.swagger.generator' version '2.19.2'
78
}
89

10+
apply plugin: DownloadSpecsPlugin
11+
912
repositories {
1013
mavenCentral()
1114
}
@@ -62,6 +65,7 @@ dependencies {
6265
implementation "io.swagger.core.v3:swagger-annotations:${swaggerCoreV3Version}"
6366
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
6467
implementation "com.squareup.okhttp3:okhttp:${okhttp3Version}"
68+
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
6569

6670
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
6771
testImplementation "org.hamcrest:hamcrest-all:${hamcrestVersion}"
@@ -70,12 +74,30 @@ dependencies {
7074
integrationTestImplementation "org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}"
7175
integrationTestImplementation "org.hamcrest:hamcrest-all:${hamcrestVersion}"
7276
integrationTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}"
77+
78+
swaggerCodegen 'io.swagger.codegen.v3:swagger-codegen-cli:3.0.36'
7379
}
7480

7581
tasks.withType(Test).configureEach {
7682
useJUnitPlatform()
7783
}
7884

85+
swaggerSources {
86+
typesense {
87+
inputFile = file("$buildDir/openapi.yml")
88+
code {
89+
language = "java"
90+
configFile = file("swagger-config.json")
91+
components = ['models']
92+
}
93+
}
94+
}
95+
96+
swaggerSources.typesense.code.dependsOn downloadApiSpec
97+
compileJava.dependsOn swaggerSources.typesense.code
98+
sourceSets.main.java.srcDir "${swaggerSources.typesense.code.outputDir}/src/main/java"
99+
sourceSets.main.resources.srcDir "${swaggerSources.typesense.code.outputDir}/src/main/resources"
100+
79101
nexusPublishing {
80102
repositories {
81103
sonatype {

buildSrc/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins {
2+
id 'groovy'
3+
id 'groovy-gradle-plugin'
4+
}

buildSrc/settings.gralde

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import org.gradle.api.Plugin
2+
import org.gradle.api.Project
3+
4+
/**
5+
* Downloads Typesense API spec from https://github.com/typesense/typesense-api-spec/blob/master/openapi.yml
6+
*/
7+
class DownloadSpecsPlugin implements Plugin<Project> {
8+
9+
def specUrl = 'https://raw.githubusercontent.com/typesense/typesense-api-spec/master/openapi.yml'
10+
11+
@Override
12+
void apply(Project project) {
13+
project.tasks.register("downloadApiSpec") {
14+
println('Downloading spec')
15+
new File("${project.buildDir}/openapi.yml").withOutputStream { out ->
16+
new URL(specUrl).withInputStream { from -> out << from }
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)