-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate API models with openapi-generator plugin in new module (#992)
- Loading branch information
Showing
94 changed files
with
31,588 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include ':libTba', ':libImgur' | ||
include 'android' | ||
include 'android' | ||
include ':tba-api' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/build | ||
.openapi-generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# tba-api | ||
This module is intended to replace `:libTba`. `:libTba` is a generated set of TBA API models | ||
using [a fork of swagger-codegen](https://github.com/the-blue-alliance/swagger-codegen) to support | ||
features such as generating interfaces instead of concrete classes. That fork has not been updated | ||
in some time, and is no longer compatible with the latest swagger specs. | ||
|
||
This module aims to use [openapi-generator](https://github.com/OpenAPITools/openapi-generator) as-is | ||
to generate concrete classes. This should more easily facilitate updates to the plugin and swagger | ||
specs in the future, decreasing maintenance overhead. | ||
|
||
## Updating generated models & API interfaces | ||
To update the generated API models and Retrofit API interfaces, run `./gradlew tba-api:openApiGenerate`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
plugins { | ||
id 'java-library' | ||
id "org.openapi.generator" version "7.10.0" | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
openApiGenerate { | ||
generatorName.set("java") | ||
remoteInputSpec.set("https://www.thebluealliance.com/swagger/api_v3.json") | ||
outputDir.set("$projectDir") | ||
apiPackage.set("thebluealliance.api") | ||
invokerPackage.set("thebluealliance.api.client") | ||
modelPackage.set("thebluealliance.api.model") | ||
|
||
// We don't need the generated markdown docs, or tests | ||
generateApiDocumentation.set(false) | ||
generateModelDocumentation.set(false) | ||
generateApiTests.set(false) | ||
generateModelTests.set(false) | ||
|
||
// By default the generator creates a full project, including a github workflow, | ||
// gradle build files, etc. | ||
// Remove all that except the generated Java files, and a couple of support files that are referenced | ||
globalProperties.set([ | ||
apis : "", | ||
models : "", | ||
supportingFiles: "CollectionFormats.java,StringUtil.java", | ||
]) | ||
|
||
// We don't currently use the generated Retrofit interface because we are still on RxJava 1.x | ||
// In the future we can set configOptions.put("useRxJava2", "true") | ||
// and use the generated Retrofit interfaces as well. | ||
configOptions.put("library", "retrofit2") | ||
configOptions.put("serializationLibrary", "gson") | ||
} | ||
|
||
dependencies { | ||
// in java 9+ java.annotation.Generated moved to java.annotation.processing.Generated | ||
// so use this lib for back-compat | ||
implementation "javax.annotation:javax.annotation-api:1.3.2" | ||
implementation 'org.openapitools:jackson-databind-nullable:0.2.6' | ||
implementation "io.reactivex:rxjava:${rxJavaVersion}" | ||
implementation "com.squareup.retrofit2:retrofit:${retrofitVersion}" | ||
implementation "com.google.code.gson:gson:${gsonVersion}" | ||
implementation "com.google.code.findbugs:jsr305:3.0.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package thebluealliance.api; | ||
|
||
import thebluealliance.api.client.CollectionFormats.*; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.*; | ||
|
||
import okhttp3.RequestBody; | ||
import okhttp3.ResponseBody; | ||
import okhttp3.MultipartBody; | ||
|
||
import thebluealliance.api.model.GetStatus401Response; | ||
import thebluealliance.api.model.SearchIndex; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public interface DefaultApi { | ||
/** | ||
* | ||
* Gets a large blob of data that is used on the frontend for searching. May change without notice. | ||
* @param year Competition Year (or Season). Must be 4 digits. (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<SearchIndex> | ||
*/ | ||
@GET("search_index") | ||
Call<SearchIndex> getSearchIndex( | ||
@retrofit2.http.Path("year") Integer year, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
} |
173 changes: 173 additions & 0 deletions
173
tba-api/src/main/java/thebluealliance/api/DistrictApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package thebluealliance.api; | ||
|
||
import thebluealliance.api.client.CollectionFormats.*; | ||
|
||
import retrofit2.Call; | ||
import retrofit2.http.*; | ||
|
||
import okhttp3.RequestBody; | ||
import okhttp3.ResponseBody; | ||
import okhttp3.MultipartBody; | ||
|
||
import thebluealliance.api.model.Award; | ||
import thebluealliance.api.model.DistrictList; | ||
import thebluealliance.api.model.DistrictRanking; | ||
import thebluealliance.api.model.Event; | ||
import thebluealliance.api.model.EventDistrictPoints; | ||
import thebluealliance.api.model.EventSimple; | ||
import thebluealliance.api.model.GetStatus401Response; | ||
import thebluealliance.api.model.Team; | ||
import thebluealliance.api.model.TeamSimple; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public interface DistrictApi { | ||
/** | ||
* | ||
* Gets a list of awards in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<Award>> | ||
*/ | ||
@GET("district/{district_key}/awards") | ||
Call<List<Award>> getDistrictAwards( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<Event>> | ||
*/ | ||
@GET("district/{district_key}/events") | ||
Call<List<Event>> getDistrictEvents( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of event keys for events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<String>> | ||
*/ | ||
@GET("district/{district_key}/events/keys") | ||
Call<List<String>> getDistrictEventsKeys( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a short-form list of events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<EventSimple>> | ||
*/ | ||
@GET("district/{district_key}/events/simple") | ||
Call<List<EventSimple>> getDistrictEventsSimple( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of District objects with the given district abbreviation. This accounts for district abbreviation changes, such as MAR to FMA. | ||
* @param districtAbbreviation District abbreviation, eg `ne` or `fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<DistrictList>> | ||
*/ | ||
@GET("district/{district_abbreviation}/history") | ||
Call<List<DistrictList>> getDistrictHistory( | ||
@retrofit2.http.Path("district_abbreviation") String districtAbbreviation, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of team district rankings for the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<DistrictRanking>> | ||
*/ | ||
@GET("district/{district_key}/rankings") | ||
Call<List<DistrictRanking>> getDistrictRankings( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of `Team` objects that competed in events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<Team>> | ||
*/ | ||
@GET("district/{district_key}/teams") | ||
Call<List<Team>> getDistrictTeams( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of `Team` objects that competed in events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<String>> | ||
*/ | ||
@GET("district/{district_key}/teams/keys") | ||
Call<List<String>> getDistrictTeamsKeys( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a short-form list of `Team` objects that competed in events in the given district. | ||
* @param districtKey TBA District Key, eg `2016fim` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<TeamSimple>> | ||
*/ | ||
@GET("district/{district_key}/teams/simple") | ||
Call<List<TeamSimple>> getDistrictTeamsSimple( | ||
@retrofit2.http.Path("district_key") String districtKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of districts and their corresponding district key, for the given year. | ||
* @param year Competition Year (or Season). Must be 4 digits. (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<DistrictList>> | ||
*/ | ||
@GET("districts/{year}") | ||
Call<List<DistrictList>> getDistrictsByYear( | ||
@retrofit2.http.Path("year") Integer year, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets a list of team rankings for the Event. | ||
* @param eventKey TBA Event Key, eg `2016nytr` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<EventDistrictPoints> | ||
*/ | ||
@GET("event/{event_key}/district_points") | ||
Call<EventDistrictPoints> getEventDistrictPoints( | ||
@retrofit2.http.Path("event_key") String eventKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
/** | ||
* | ||
* Gets an array of districts representing each year the team was in a district. Will return an empty array if the team was never in a district. | ||
* @param teamKey TBA Team Key, eg `frc254` (required) | ||
* @param ifNoneMatch Value of the `ETag` header in the most recently cached response by the client. (optional) | ||
* @return Call<List<DistrictList>> | ||
*/ | ||
@GET("team/{team_key}/districts") | ||
Call<List<DistrictList>> getTeamDistricts( | ||
@retrofit2.http.Path("team_key") String teamKey, @retrofit2.http.Header("If-None-Match") String ifNoneMatch | ||
); | ||
|
||
} |
Oops, something went wrong.