Skip to content

Commit 9755d74

Browse files
committed
Version 4 - navigation aids in routes; improvements; new OpenAPI generator
1 parent f1ad631 commit 9755d74

File tree

10 files changed

+2668
-4274
lines changed

10 files changed

+2668
-4274
lines changed

CHANGELOG.md

+44
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,50 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Version 4.0.0 - 2025-01-27
9+
10+
### Added
11+
12+
- Adds support for the OSRM format and navigation aids.
13+
- Explicitly documented more properties on the geocoding feature model.
14+
- Adds support for the `foursquare` data source.
15+
- Documents the elevation interval parameter on certain routing requests.
16+
17+
### Changed
18+
19+
- BREAKING: This unfortunately means that some properties of the route response model, due to how the OpenAPI generator handles these models (it does not know how to generate variant models yet).
20+
- BREAKING: Renamed models containing Valhalla and Pelias in their names to be generic. These now have rout(e|ing) or geocod(e|ing) prefixes.
21+
- BREAKING: Removed one layer of nesting in the API namespace.
22+
- Switched to [OpenAPI Generator](https://openapi-generator.tech/docs/generators/kotlin/) as the previous plugin appears to be abandoned.
23+
24+
### Migration notes
25+
26+
#### Imports
27+
28+
API imports have changed slightly, removing one level of nesting.
29+
Simply remove the `apis` package from the path like so:
30+
31+
```diff
32+
- import com.stadiamaps.api.apis.GeocodingApi
33+
+ import com.stadiamaps.api.GeocodingApi
34+
```
35+
36+
#### Renamed types
37+
38+
Several geocoding and routing types have been renamed to reflect their purpose better.
39+
All types beginning with `Pelias` (e.g. `PeliasLayer`) now have a `Geocoding` prefix (e.g. `GeocodingLayer`).
40+
Similarly, all types with a `Valhalla` prefix (e.g. `ValhallaLanguage`) now have a `Routing` prefix (e.g. `RoutingLanguage`).
41+
42+
#### Routing API model changes
43+
44+
Some properties of `Route200Response` are now optional.
45+
This is due to a bug in the OpenAPI generator for Kotlin,
46+
which coalesces all properties into a single model rather than having two variations on the model based on format.
47+
When requesting a route with navigation aids (`format = RouteRequest.Format.osrm`),
48+
the `routes` property will contain the enhanced route information.
49+
Existing code using the original compact format will continue using the `trip` property.
50+
When you receive a successful response, your code can safely use the nun-null assertion operator (`!!`).
51+
852
## Version 3.2.1 - 2024-08-15
953

1054
### Fixed

RELEASE.md

-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ To export the private key, you can run the following command (requires passphara
1919
```shell
2020
gpg --output mavencentral.pgp --armor --export-secret-key you@example.com
2121
```
22-

example/src/main/kotlin/Main.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import com.stadiamaps.api.apis.GeocodingApi
2-
import com.stadiamaps.api.apis.GeospatialApi
3-
import com.stadiamaps.api.apis.RoutingApi
1+
import com.stadiamaps.api.GeocodingApi
2+
import com.stadiamaps.api.GeospatialApi
3+
import com.stadiamaps.api.RoutingApi
44
import com.stadiamaps.api.auth.ApiKeyAuth
55
import com.stadiamaps.api.infrastructure.ApiClient
66
import com.stadiamaps.api.models.*

generated-client/build.gradle.kts

+68-28
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
}
5+
dependencies {
6+
classpath("org.yaml:snakeyaml:2.0")
7+
}
8+
}
9+
110
import org.gradle.api.DefaultTask
211
import org.gradle.api.tasks.Input
312
import org.gradle.api.tasks.OutputFile
413
import org.gradle.api.tasks.TaskAction
5-
import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode
14+
15+
import org.yaml.snakeyaml.Yaml
16+
import org.yaml.snakeyaml.constructor.SafeConstructor
617

718
plugins {
819
kotlin("jvm")
9-
id("org.hidetake.swagger.generator") version "2.19.2"
20+
id("org.openapi.generator") version "7.11.0"
1021
`maven-publish`
1122
signing
1223
id("org.jetbrains.dokka") version "1.9.20"
1324
id("tech.yanand.maven-central-publish") version "1.1.1"
1425
}
1526

1627
val stagingDir = layout.buildDirectory.dir("staging-deploy").get()
28+
val generatedClientDir = layout.buildDirectory.dir("generated").get()
1729

1830
repositories {
1931
mavenCentral()
@@ -22,8 +34,6 @@ repositories {
2234
dependencies {
2335
val retrofitVersion: String by project
2436

25-
swaggerCodegen("org.openapitools:openapi-generator-cli:7.5.0")
26-
2737
// Dependencies of the generated code. Check out `build.gradle` in your build folder later if you're curious.
2838
val moshiVersion = "1.15.1"
2939
implementation("com.squareup.moshi:moshi-kotlin:$moshiVersion")
@@ -70,23 +80,58 @@ tasks.register("downloadOpenAPISpec", DownloadResource::class.java) {
7080
target = File("openapi.yaml")
7181
}
7282

73-
tasks.named("generateSwaggerCode").configure {
83+
tasks.register("patchOpenAPISpec") {
84+
doLast {
85+
val openApiFile = file("openapi.yaml")
86+
val originalText = openApiFile.readText()
87+
88+
// We have to do some post-processing of the YAML spec here,
89+
// because of https://github.com/OpenAPITools/openapi-generator/issues/18167.
90+
// The way the Kotlin OpenAPI generator works for `oneOf` models,
91+
// the result is a superset of all the properties of the
92+
93+
// Parse the document with SnakeYAML
94+
val yaml = Yaml()
95+
val root = yaml.load<Map<String, Any>>(originalText)?.toMutableMap() ?: mutableMapOf()
96+
97+
// Remove the required Valhalla route response properties (trip in this case)
98+
val components = (root["components"] as? Map<*, *>)!!.toMutableMap()
99+
val schemas = (components["schemas"] as? Map<*, *>)!!.toMutableMap()
100+
101+
val routeResponse = (schemas["routeResponse"] as? Map<*, *>)!!.toMutableMap()
102+
routeResponse.remove("required")
103+
schemas["routeResponse"] = routeResponse
104+
105+
val osrmBaseApiResponse = (schemas["osrmBaseApiResponse"] as? Map<*, *>)!!.toMutableMap()
106+
osrmBaseApiResponse.remove("required")
107+
schemas["osrmBaseApiResponse"] = osrmBaseApiResponse
108+
109+
components["schemas"] = schemas
110+
root["components"] = components
111+
112+
openApiFile.writeText(yaml.dump(root))
113+
114+
}
115+
}
116+
117+
tasks.named("patchOpenAPISpec").configure {
74118
dependsOn("downloadOpenAPISpec")
75119
}
76120

121+
tasks.named("openApiGenerate").configure {
122+
dependsOn("patchOpenAPISpec")
123+
}
124+
77125
tasks.named<Jar>("sourcesJar").configure {
78-
dependsOn("generateSwaggerCode")
126+
dependsOn("openApiGenerate")
79127
}
80128

81129
tasks.dokkaHtml {
82-
dependsOn("generateSwaggerCode")
83-
outputDirectory.set(buildDir.resolve("dokkaHtml"))
130+
dependsOn("openApiGenerate")
131+
outputDirectory.set(layout.buildDirectory.dir("dokkaHtml"))
84132
dokkaSourceSets {
85133
configureEach {
86-
includeNonPublic.set(false)
87134
reportUndocumented.set(true)
88-
skipEmptyPackages.set(true)
89-
skipDeprecated.set(false)
90135
jdkVersion.set(11)
91136
}
92137
}
@@ -98,31 +143,26 @@ tasks.register<Jar>("dokkaJavadocJar") {
98143
from(tasks.dokkaHtml)
99144
}
100145

101-
swaggerSources {
102-
register("stadiamaps") {
103-
val validationTask = validation
104-
validationTask.dependsOn("downloadOpenAPISpec")
105-
106-
setInputFile(file("openapi.yaml"))
107-
code(delegateClosureOf<GenerateSwaggerCode> {
108-
language = "kotlin"
109-
library = "jvm-retrofit2"
110-
additionalProperties = mapOf("groupId" to "com.stadiamaps", "packageName" to "com.stadiamaps.api")
111-
dependsOn(validationTask)
112-
})
113-
}
146+
openApiGenerate {
147+
generatorName.set("kotlin")
148+
library.set("jvm-retrofit2")
149+
groupId.set("com.stadiamaps")
150+
inputSpec.set(file("openapi.yaml").path)
151+
apiPackage.set("com.stadiamaps.api")
152+
packageName.set("com.stadiamaps.api")
153+
modelPackage.set("com.stadiamaps.api.models")
154+
outputDir.set(generatedClientDir.toString())
114155
}
115156

116157
// Comment this out if you do NOT want the code gen to run every time you build.
117158
// There is an HTTP cache by default, so it won't necessarily make a request every single build.
118159
tasks.compileKotlin.configure {
119-
dependsOn(tasks.generateSwaggerCode)
160+
dependsOn(tasks.openApiGenerate)
120161
}
121162

122163
sourceSets {
123164
val main by getting
124-
val stadiamaps by swaggerSources.getting
125-
main.kotlin.srcDir("${stadiamaps.code.outputDir}/src/main/kotlin")
165+
main.kotlin.srcDir("${generatedClientDir}/src/main/kotlin")
126166
}
127167

128168
publishing {
@@ -145,7 +185,7 @@ publishing {
145185
create<MavenPublication>("publication") {
146186
groupId = "com.stadiamaps"
147187
artifactId = "api"
148-
version = "3.2.1"
188+
version = "4.0.0"
149189

150190
from(components["java"])
151191

0 commit comments

Comments
 (0)