Repository navigation
feat(codegen)!: generate the data requests and their SpotifyApi methods from the spec - #487
Conversation
…ds from the spec codegen/generate.py renders every data request class, and the SpotifyApi method that creates it, from spec/openapi.yaml. codegen/requests.yaml maps each class to its operation and records the few deliberate departures from the spec (search types, top artists/tracks, a split reorder/replace operation, a missing model). Two classes stay hand-written: the generic top-artists-and-tracks request and the JPEG cover upload. The generated API follows the spec, so where the hand-written one differed it changes: - setters use the wire name (additional_types, include_external, snapshot_id) - SpotifyApi methods take the required parameters, typed like their setters, instead of varargs, arrays or JsonArray overloads - body arrays and objects are List<String> and Map<String, Object> instead of JsonArray and JsonObject, serialized by AbstractRequest - a body field duplicating a query parameter is dropped; Spotify ignores it when the query parameter is sent - parameters the spec no longer lists are gone (country, timestamp) - return types follow the response schema (GetSeveralAudiobooksRequest returns Audiobook[], GetCategoryPlaylistsRequest FeaturedPlaylists) - recently played takes after/before as Unix milliseconds, as the spec says, instead of a formatted date POST and PUT keep always sending a JSON body. Refs #461
- CI regenerates the request classes and fails when the committed ones differ (PyYAML in a throwaway venv) - AGENTS.md and CONTRIBUTING.md describe adding an endpoint through codegen/requests.yaml instead of writing the class by hand - MIGRATION.md lists every changed SpotifyApi method, builder setter and return type, taken from the japicmp report against 10.1.0 - ci/check-docs.py treats any older major version as the past side of the guide, not only v9, so v10 names can be listed Refs #461
e939634 to
2c679ae
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Generated setters drop existing URI-count, volume, repeat-state, and offset constraints, allowing invalid arguments to reach the API even with assertions enabled.
6 open issues
What changed in this PR
Makes the OpenAPI specification the source of truth for v11 data requests and their SpotifyApi factory methods, introducing breaking API changes and migrating callers.
Changes:
- Generates request parameters, documentation, deprecations, validation, and response handling from the spec.
- Adds collection/map body serialization and shared response-parsing helpers.
- Updates tests, examples, contributor guidance, and CI checks for generated-code drift.
This pull request requires changes. Six moderate validation regressions remain: the library check, remove, and save requests lose their 40-URI limits; playback volume loses its upper bound of 100; repeat mode loses its restriction to track, context, or off; and current-user playlist pagination loses its maximum offset of 100,000. These setters now accept invalid inputs even with assertions enabled. Preserve these constraints in the spec or generator and regenerate the affected setters.
| File | Description |
|---|---|
src/test/java/se/michaelthelin/spotify/requests/data/users/UnfollowArtistsOrUsersRequestTest.java |
Uses comma-separated query IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/users/FollowPlaylistRequestTest.java |
Sets optional visibility through the builder. |
src/test/java/se/michaelthelin/spotify/requests/data/users/FollowArtistsOrUsersRequestTest.java |
Removes coverage for retired body-ID overloads. |
src/test/java/se/michaelthelin/spotify/requests/data/users/CheckIfUserFollowsPlaylistRequestTest.java |
Sets optional IDs through the builder. |
src/test/java/se/michaelthelin/spotify/requests/data/users/CheckCurrentUserFollowsArtistsOrUsersRequestTest.java |
Uses comma-separated query IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/tracks/SaveTracksForCurrentUserRequestTest.java |
Verifies list-valued IDs in the JSON body. |
src/test/java/se/michaelthelin/spotify/requests/data/tracks/GetSeveralAudioFeaturesRequestTest.java |
Uses comma-separated track IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/tracks/CheckUsersSavedTracksRequestTest.java |
Uses comma-separated track IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/shows/CheckUsersSavedShowsRequestTest.java |
Uses comma-separated show IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchTracksRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchShowsRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchPlaylistsRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchEpisodesRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchArtistsRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/simplified/SearchAlbumsRequestTest.java |
Uses the wire-named include_external setter. |
src/test/java/se/michaelthelin/spotify/requests/data/search/SearchRequestTest.java |
Uses the wire-named search setter. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/UpdatePlaylistsItemsReplaceRequestTest.java |
Tests builder-based replacement URIs. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/UpdatePlaylistsItemsReplaceDeprecatedRequestTest.java |
Migrates deprecated replacement request usage. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/UpdatePlaylistsItemsReorderRequestTest.java |
Sets reorder parameters through builders. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/UpdatePlaylistsItemsReorderDeprecatedRequestTest.java |
Migrates deprecated reorder request usage. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/RemovePlaylistItemsRequestTest.java |
Tests list input and the wire-named snapshot setter. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/RemovePlaylistItemsDeprecatedRequestTest.java |
Updates snapshot setter and body assertions. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/GetPlaylistRequestTest.java |
Uses additional_types. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/GetPlaylistItemsRequestTest.java |
Uses additional_types. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/GetPlaylistItemsDeprecatedRequestTest.java |
Uses additional_types. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/GetFeaturedPlaylistsRequestTest.java |
Removes unsupported country and timestamp parameters. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/GetCategoryPlaylistsRequestTest.java |
Tests the FeaturedPlaylists response wrapper. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/AddItemsToPlaylistRequestTest.java |
Tests query-based playlist additions. |
src/test/java/se/michaelthelin/spotify/requests/data/playlists/AddItemsToPlaylistDeprecatedRequestTest.java |
Migrates deprecated playlist-addition usage. |
src/test/java/se/michaelthelin/spotify/requests/data/player/TransferUsersPlaybackRequestTest.java |
Uses list-valued device IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/player/StartUsersPlaybackRequestTest.java |
Uses a map-valued playback offset. |
src/test/java/se/michaelthelin/spotify/requests/data/player/StartUsersPlaybackRequestNumericTest.java |
Tests collection/map body serialization. |
src/test/java/se/michaelthelin/spotify/requests/data/player/GetUsersCurrentlyPlayingTrackRequestTest.java |
Uses additional_types across fixtures. |
src/test/java/se/michaelthelin/spotify/requests/data/player/GetRecentlyPlayedRequestTest.java |
Expects Unix-millisecond query values. |
src/test/java/se/michaelthelin/spotify/requests/data/player/GetInformationAboutUsersCurrentPlaybackRequestTest.java |
Uses additional_types across fixtures. |
src/test/java/se/michaelthelin/spotify/requests/data/episodes/CheckUsersSavedEpisodesRequestTest.java |
Uses comma-separated episode IDs. |
src/test/java/se/michaelthelin/spotify/requests/data/audiobooks/GetSeveralAudiobooksRequestTest.java |
Expects the full Audiobook[] response type. |
src/test/java/se/michaelthelin/spotify/requests/data/albums/CheckUsersSavedAlbumsRequestTest.java |
Uses comma-separated album IDs. |
src/test/java/se/michaelthelin/spotify/ITest.java |
Updates shared timestamp, list, and map test values. |
src/main/java/se/michaelthelin/spotify/requests/data/users/UnfollowPlaylistRequest.java |
Adopts generated structure and documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/users/GetUsersProfileRequest.java |
Adopts generated profile-request documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/users/GetCurrentUsersProfileRequest.java |
Adopts generated profile-request structure. |
src/main/java/se/michaelthelin/spotify/requests/data/users/FollowPlaylistRequest.java |
Aligns builder metadata and deprecation with the spec. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/RemoveUsersSavedTracksRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/GetTracksAudioFeaturesRequest.java |
Adopts generated documentation and builder annotations. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/GetTracksAudioAnalysisRequest.java |
Adopts generated documentation and builder annotations. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/GetTrackRequest.java |
Adopts spec-derived parameter documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/GetSeveralTracksAudioFeaturesRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/tracks/CheckUsersSavedTracksRequest.java |
Uses shared Boolean-array parsing. |
src/main/java/se/michaelthelin/spotify/requests/data/shows/SaveShowsForCurrentUserRequest.java |
Adds JSON content type and generated validation. |
src/main/java/se/michaelthelin/spotify/requests/data/shows/GetUsersSavedShowsRequest.java |
Adopts generated paging documentation and checks. |
src/main/java/se/michaelthelin/spotify/requests/data/playlists/GetUsersPlaylistsRequest.java |
Adopts generated paging documentation and checks. |
src/main/java/se/michaelthelin/spotify/requests/data/playlists/GetPlaylistCoverImageRequest.java |
Adopts generated cover-request structure. |
src/main/java/se/michaelthelin/spotify/requests/data/playlists/GetCurrentUsersPlaylistsRequest.java |
Regenerates paging validation; loses the 100,000 maximum offset. |
src/main/java/se/michaelthelin/spotify/requests/data/player/TogglePlaybackShuffleRequest.java |
Adopts generated documentation and state checks. |
src/main/java/se/michaelthelin/spotify/requests/data/player/SkipToPreviousRequest.java |
Adopts generated playback documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/SkipToNextRequest.java |
Adopts generated playback documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/SetRepeatModeRequest.java |
Regenerates state handling; loses allowed-state validation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/SetPlaybackVolumeRequest.java |
Regenerates volume handling; loses the maximum of 100. |
src/main/java/se/michaelthelin/spotify/requests/data/player/SeekToPositionRequest.java |
Adopts generated seek-request documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/PausePlaybackRequest.java |
Adopts generated playback documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/GetUsersQueueRequest.java |
Adopts generated queue-request structure. |
src/main/java/se/michaelthelin/spotify/requests/data/player/GetAvailableDevicesRequest.java |
Adopts generated device-request documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/player/AddItemToPlaybackQueueRequest.java |
Aligns generated setter order and documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/markets/GetAvailableMarketsRequest.java |
Uses shared string-array parsing. |
src/main/java/se/michaelthelin/spotify/requests/data/library/SaveItemsToLibraryRequest.java |
Adds JSON content type; loses the 40-URI count check. |
src/main/java/se/michaelthelin/spotify/requests/data/library/RemoveItemsFromLibraryRequest.java |
Regenerates URI handling; loses the 40-URI count check. |
src/main/java/se/michaelthelin/spotify/requests/data/library/CheckUsersSavedItemsRequest.java |
Uses shared parsing; loses the 40-URI count check. |
src/main/java/se/michaelthelin/spotify/requests/data/genres/GetRecommendationGenresRequest.java |
Replaces custom genre-array parsing with a shared helper. |
src/main/java/se/michaelthelin/spotify/requests/data/episodes/SaveEpisodesForCurrentUserRequest.java |
Adds JSON content type and generated checks. |
src/main/java/se/michaelthelin/spotify/requests/data/episodes/RemoveEpisodesForCurrentUserRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/episodes/GetSeveralEpisodesRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/chapters/GetChapterRequest.java |
Aligns chapter-request documentation with the spec. |
src/main/java/se/michaelthelin/spotify/requests/data/categories/GetSingleBrowseCategoryRequest.java |
Updates generated documentation and locale validation. |
src/main/java/se/michaelthelin/spotify/requests/data/audiobooks/RemoveAudiobooksForCurrentUserRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/audiobooks/GetUsersSavedAudiobooksRequest.java |
Adopts generated paging documentation and checks. |
src/main/java/se/michaelthelin/spotify/requests/data/audiobooks/GetAudiobookRequest.java |
Aligns audiobook-request documentation with the spec. |
src/main/java/se/michaelthelin/spotify/requests/data/artists/GetSeveralArtistsRequest.java |
Updates generated documentation and ID validation. |
src/main/java/se/michaelthelin/spotify/requests/data/artists/GetArtistsTopTracksRequest.java |
Aligns generated top-tracks documentation. |
src/main/java/se/michaelthelin/spotify/requests/data/artists/GetArtistsRelatedArtistsRequest.java |
Adopts generated documentation and builder annotations. |
src/main/java/se/michaelthelin/spotify/requests/data/artists/GetArtistRequest.java |
Adopts generated artist-request structure. |
src/main/java/se/michaelthelin/spotify/requests/data/albums/SaveAlbumsForCurrentUserRequest.java |
Applies the spec ID limit and JSON content type. |
src/main/java/se/michaelthelin/spotify/requests/data/albums/RemoveAlbumsForCurrentUserRequest.java |
Applies the spec-derived 20-ID limit. |
src/main/java/se/michaelthelin/spotify/requests/data/albums/GetNewReleasesRequest.java |
Adopts generated paging documentation and checks. |
src/main/java/se/michaelthelin/spotify/requests/data/albums/GetAlbumRequest.java |
Adopts generated album-request structure. |
src/main/java/se/michaelthelin/spotify/requests/data/albums/CheckUsersSavedAlbumsRequest.java |
Uses shared parsing and the spec ID limit. |
src/main/java/se/michaelthelin/spotify/requests/AbstractRequest.java |
Serializes collection and map body values. |
src/main/java/se/michaelthelin/spotify/internal/RequestValues.java |
Wraps values into one-field body objects. |
src/main/java/se/michaelthelin/spotify/internal/ModelObjectJson.java |
Adds primitive-value response-parsing helpers. |
examples/data/users/UnfollowArtistsOrUsersExample.java |
Uses comma-separated query IDs. |
examples/data/users/FollowPlaylistExample.java |
Sets visibility through the builder. |
examples/data/users/FollowArtistsOrUsersExample.java |
Uses comma-separated query IDs. |
examples/data/users/CheckIfUserFollowsPlaylistExample.java |
Sets optional IDs through the builder. |
examples/data/users/CheckCurrentUserFollowsArtistsOrUsersExample.java |
Uses comma-separated query IDs. |
examples/data/tracks/SaveTracksForCurrentUserExample.java |
Supplies track IDs as a list. |
examples/data/tracks/GetSeveralTracksAudioFeaturesExample.java |
Uses comma-separated track IDs. |
examples/data/tracks/CheckUsersSavedTracksExample.java |
Uses comma-separated track IDs. |
examples/data/shows/CheckUsersSavedShowsExample.java |
Uses comma-separated show IDs. |
examples/data/search/simplified/SearchTracksExample.java |
Updates commented search-setter usage. |
examples/data/search/simplified/SearchShowsExample.java |
Updates commented search-setter usage. |
examples/data/search/simplified/SearchPlaylistsExample.java |
Updates commented search-setter usage. |
examples/data/search/simplified/SearchEpisodesExample.java |
Updates commented search-setter usage. |
examples/data/search/simplified/SearchArtistsExample.java |
Updates commented search-setter usage. |
examples/data/search/simplified/SearchAlbumsExample.java |
Updates commented search-setter usage. |
examples/data/search/SearchForItemExample.java |
Updates commented search-setter usage. |
examples/data/playlists/UpdatePlaylistsItemsReplaceExample.java |
Supplies replacement URIs through the builder. |
examples/data/playlists/UpdatePlaylistsItemsReplaceDeprecatedExample.java |
Migrates deprecated replacement request usage. |
examples/data/playlists/UpdatePlaylistsItemsReorderExample.java |
Sets reorder parameters through the builder. |
examples/data/playlists/UpdatePlaylistsItemsReorderDeprecatedExample.java |
Migrates deprecated reorder request usage. |
examples/data/playlists/RemovePlaylistItemsExample.java |
Updates commented snapshot-setter usage. |
examples/data/playlists/RemovePlaylistItemsDeprecatedExample.java |
Uses URI lists and the renamed snapshot setter. |
examples/data/playlists/GetPlaylistItemsExample.java |
Updates the commented additional-types setter. |
examples/data/playlists/GetPlaylistItemsDeprecatedExample.java |
Updates the commented additional-types setter. |
examples/data/playlists/GetPlaylistExample.java |
Updates the commented additional-types setter. |
examples/data/playlists/GetFeaturedPlaylistsExample.java |
Removes comments showing unsupported parameters. |
examples/data/playlists/GetCategoryPlaylistsExample.java |
Consumes the FeaturedPlaylists response wrapper. |
examples/data/playlists/AddItemsToPlaylistExample.java |
Supplies comma-separated URIs through the builder. |
examples/data/playlists/AddItemsToPlaylistDeprecatedExample.java |
Migrates deprecated playlist-addition usage. |
examples/data/player/TransferPlaybackExample.java |
Supplies device IDs as a list. |
examples/data/player/GetRecentlyPlayedTracksExample.java |
Shows millisecond timestamp arguments in comments. |
examples/data/player/GetPlaybackStateExample.java |
Updates the commented additional-types setter. |
examples/data/player/GetCurrentlyPlayingTrackExample.java |
Updates the commented additional-types setter. |
examples/data/episodes/CheckUsersSavedEpisodesExample.java |
Uses comma-separated episode IDs. |
examples/data/audiobooks/GetSeveralAudiobooksExample.java |
Consumes full Audiobook[] responses. |
examples/data/albums/CheckUsersSavedAlbumsExample.java |
Uses comma-separated album IDs. |
CONTRIBUTING.md |
Documents the generated-endpoint contribution workflow. |
ci/check-docs.py |
Recognizes older-major migration-guide references. |
AGENTS.md |
Documents generation and revised API conventions. |
.github/workflows/ci.yml |
Adds generated-output drift verification. |
Review effort: Balanced
The generator read integer bounds and enums from the schema, and mined the description only for "Maximum: N IDs" and "maximum of N items". Seven setters therefore lost a check the spec states: the 40-URI limit of the library endpoints, the single id of the playlist follow check, the 0 to 100 volume range, the three repeat states, and the 100,000 offset maximum of the two playlist endpoints. The vendored spec now carries the bounds as schema fields (enum on the repeat state, minimum and maximum on the volume and the two offset parameters), and the count-limit regex also reads "Maximum: N URIs" and "Maximum: N id". ArgumentChecksTest pins the restored checks at their boundaries.
|
While fixing these six I swept the spec for the same class of drop and found one more setter the review missed: CheckIfUserFollowsPlaylistRequest.ids used to assert a single id, and the spec's "Maximum: 1 id" phrasing (lowercase singular) fell through the generator's "Maximum: N IDs" regex. The same commit restores it. The fix has two parts. Where OpenAPI can express the constraint, the vendored spec/openapi.yaml now carries it as a schema field: enum on the repeat state, minimum and maximum on the volume and the two playlist offset parameters. Where it cannot (a count limit on a comma-separated string parameter), the generator's existing description regex now also reads "Maximum: N URIs" and "Maximum: N id". AGENTS.md notes that the vendored spec is the published spec plus these constraint fields, so a future spec refresh does not drop them, and ArgumentChecksTest pins every restored check at its boundary. |

Step 5 of the plan in #461, for v11 on
beta. It replaces the prototype in #486, which kept the 10.x API. Here the OpenAPI spec is the reference, and every place the generated API moves is recorded inMIGRATION.md. This branch is based onbetawithmainmerged in, so the API-gate andModelObjectswork it builds on is already present; the diff is the codegen change only.codegen/requests.yamlmaps each of the 106 data request classes to its specoperationIdin one line, with a handful of entries recording a deliberate departure from the spec: the eight typed search classes, top artists and tracks, the reorder/replace split of one operation, the recommendations method's arguments, and one model the spec doesn't have.codegen/generate.pyrenders every request class fromspec/openapi.yaml: the verb, path, query, path and body parameters with their Java types and argument checks, the Javadoc and deprecation, and how the response is read, including paging and cursor paging. It also writes theSpotifyApimethod that creates each request, between// <generated-…>markers. Two classes stay hand-written:GetUsersTopArtistsAndTracksRequest(generic over its item type) andAddCustomPlaylistCoverImageRequest(JPEG body). A new CI step regenerates the classes and fails when they differ from what's committed.The generated API follows the spec. A
SpotifyApimethod takes the operation's required parameters, typed like their setters, and optional parameters go on the builder; the old varargs,String[]andJsonArrayoverloads are gone. Each setter has the wire name, soadditionalTypesbecomesadditional_types,includeExternalbecomesinclude_external,snapshotIdbecomessnapshot_id, andpublicbecomespublic_. A body array is aList<String>and a body object aMap<String, Object>instead of GsonJsonArray/JsonObject, whichAbstractRequestserializes; an array of one-field objects such as[{"uri": …}]takes the field values and wraps them, soremovePlaylistItemsstill takes plain URIs. If a parameter exists in both the query and the body, only the query one is offered, because Spotify ignores the body copy when both are sent. POST and PUT always send a JSON body, as before.All the caller-facing changes are listed in
MIGRATION.md, taken from japicmp's report against 10.1.0 (66 removed and 49 added signatures, 2 changed return types).GetSeveralAudiobooksRequestreturnsAudiobook[]andGetCategoryPlaylistsRequestreturnsFeaturedPlaylists, following the response schema.country,timestampandalbum_typeare removed because the spec no longer has them. Two fixes fall out of following the spec:GetRecentlyPlayedTracksRequest.after/beforenow send Unix milliseconds instead of a formatted date, and deprecation now matches the spec everywhere, sofollowPlaylistandsaveTracksForCurrentUserare deprecated.Verified locally: 420 tests pass,
codegen/generate.py --checkreports no drift,ci/check-docs.pychecks all 115 examples, Javadoc passes doclint, and the examples module compiles.