Skip to content

feat: add common interfaces#457

Merged
dargmuesli merged 5 commits into
spotify-web-api-java:betafrom
fm-sys:common-interfaces
Apr 29, 2026
Merged

feat: add common interfaces#457
dargmuesli merged 5 commits into
spotify-web-api-java:betafrom
fm-sys:common-interfaces

Conversation

@fm-sys

@fm-sys fm-sys commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

I'm working on a project, where I'm sometimes getting a PlaylistSimplified and sometimes a Playlist. As I only need the basic properties, it would save me a lot of boilerplate code if I could downcast both classes to IPlaylist instead of writing my own conversion methods and model classes.

Therefore, this pull request introduces new interfaces to unify the representation of Spotify model objects (Album, Artist, Playlist, Show, Episode, and Track), and updates the corresponding model classes to implement these interfaces. This especially benefits applications implementing this library by providing common interfaces for full and simplified versions of model objects.

I've added no tests, as interfaces only provide the contract, not the implementation, and the model class specific implementations are already tested.

The change is done in a way it shouldn't break any code of existing applications. I've targeted the beta branch and would be happy if this PR could be included in the final v10 release.

@fm-sys

fm-sys commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

Right now, I've placed all new common interfaces in an interfaces subfolder. We could move IModelObject.java and IPlaylistItem.java in there as well for consistency (there are breaking changes in v10 anyway). Or don't do it for backward compatibility. I'm undecided about this one, so let me know :)

@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 49.84%. Comparing base (a069569) to head (57276dd).
⚠️ Report is 6 commits behind head on beta.

Additional details and impacted files
@@            Coverage Diff            @@
##               beta     #457   +/-   ##
=========================================
  Coverage     49.84%   49.84%           
  Complexity      582      582           
=========================================
  Files           243      243           
  Lines          8626     8626           
  Branches       1054     1054           
=========================================
  Hits           4300     4300           
  Misses         3526     3526           
  Partials        800      800           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a set of shared model interfaces (Album, Artist, Playlist, Show, Episode, Track) so callers can treat full and simplified Spotify model objects uniformly, and updates the corresponding model classes to implement those interfaces.

Changes:

  • Added new common interfaces under se.michaelthelin.spotify.model_objects.interfaces (e.g., IPlaylist, ITrack, etc.).
  • Updated full + simplified specification model classes (and AlbumSimplifiedSpecial) to implement the new interfaces.
  • Enabled simplified Track/Episode to be treated as playlist items via ITrack/IEpisode extending IPlaylistItem.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/se/michaelthelin/spotify/model_objects/specification/TrackSimplified.java Implements ITrack to unify simplified Track usage.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Track.java Implements ITrack to unify full Track usage.
src/main/java/se/michaelthelin/spotify/model_objects/specification/ShowSimplified.java Implements IShow for common Show access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Show.java Implements IShow for common Show access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/PlaylistSimplified.java Implements IPlaylist for common Playlist access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Playlist.java Implements IPlaylist for common Playlist access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/EpisodeSimplified.java Implements IEpisode for common Episode access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Episode.java Implements IEpisode for common Episode access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/ArtistSimplified.java Implements IArtist for common Artist access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Artist.java Implements IArtist for common Artist access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/AlbumSimplified.java Implements IAlbum for common Album access.
src/main/java/se/michaelthelin/spotify/model_objects/specification/Album.java Implements IAlbum for common Album access.
src/main/java/se/michaelthelin/spotify/model_objects/special/AlbumSimplifiedSpecial.java Implements IAlbum to include the “special” simplified album in the common contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/ITrack.java New interface defining shared Track contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/IShow.java New interface defining shared Show contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/IPlaylist.java New interface defining shared Playlist contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/IEpisode.java New interface defining shared Episode contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/IArtist.java New interface defining shared Artist contract.
src/main/java/se/michaelthelin/spotify/model_objects/interfaces/IAlbum.java New interface defining shared Album contract.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fm-sys

fm-sys commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

IEpisode and ITrack furthermore share similarities which could be unified inside IPlaylistItem, however they currently do not share the same method names:

  • getAudioPreviewUrl vs getPreviewUrl
  • getExplicit vs getIsExplicit
  • getPlayable vs getIsPlayable

However, renaming these would also be a breaking change…

@dargmuesli

Copy link
Copy Markdown
Member

As this PR targets beta, breaking changes are ok. As long as this repo's source code stays in sync with Spotify's api docs, I'm fine with such changes!

@fm-sys fm-sys marked this pull request as draft April 13, 2026 14:39

@dargmuesli dargmuesli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rerequest me as reviewer once not draft anymore 🙌

@fm-sys fm-sys force-pushed the common-interfaces branch from 9d14a94 to d6700e3 Compare April 13, 2026 20:08
@fm-sys fm-sys force-pushed the common-interfaces branch from d6700e3 to 01f413e Compare April 13, 2026 20:10
@fm-sys

fm-sys commented Apr 13, 2026

Copy link
Copy Markdown
Contributor Author

As long as this repo's source code stays in sync with Spotify's api docs, I'm fine with such changes!

@dargmuesli thanks for your reply :)

Let me ask a follow up question:

In the Spotify docs, it's explicit and is_playable for Episode and Track, while one uses preview_url and the other uses audio_preview_url. Exactly sticking to the API would also mean that we cannot have a common preview URL method.

Track.java currently uses getIsPlayable, getIsExplicit, getPreviewUrl, Episodes has getPlayable, getExplicit and getAudioPreviewUrl. Personally I would say, let's use the ones we already have for Tracks as they are probably used more and rename the Episode counterparts (although this would not be 100% in line with the official Spotify API doc).


But as I don't really like the felling to break code intentionally and to do not block the remaining PR, I would suggest not unifying these methods for now. Let me know whether you have a preference, despite that the PR would be ready for review.

@fm-sys fm-sys marked this pull request as ready for review April 13, 2026 20:20
@fm-sys fm-sys requested a review from dargmuesli April 22, 2026 20:54
@dargmuesli

Copy link
Copy Markdown
Member

I think I've used the is prefix uniformly earlier and then have stuck to the api spec naming in more recent additions. Yes, that should be aligned, in a separate PR.

For now, I've added a minor change that should allow for types to be more specific and not be reduced to iHasTotal only. Please check and let me know if you're fine with that!

@dargmuesli dargmuesli changed the title add common interfaces feat: add common interfaces Apr 29, 2026
@fm-sys

fm-sys commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Initially I actually had a generic version IPlaylist<T>, which however caused the type of getItems to get unusable. Therefore, I switched to IHasTotal, however your T extends IHasTotal solution is even more elegant :)

@dargmuesli dargmuesli merged commit 7ef43d2 into spotify-web-api-java:beta Apr 29, 2026
6 checks passed
@dargmuesli dargmuesli mentioned this pull request Apr 29, 2026
@dargmuesli

Copy link
Copy Markdown
Member

Version 10.0.0-RC3 should be available shortly.

@fm-sys fm-sys deleted the common-interfaces branch April 29, 2026 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants