Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AUD-1375] Prepare User and Track APIs for Type Generation #2778

Merged
merged 25 commits into from
Apr 1, 2022

Conversation

rickyrombo
Copy link
Contributor

@rickyrombo rickyrombo commented Mar 29, 2022

Description

Preview API docs: http://34.66.46.158:4567/#audius-api-docs

Users

  • Renames <string:user_id> to <string:id> in the route params for users so that it doesn't conflict with the user_id query param and cause problems with the swagger.json output
  • Creates current_user_parser, pagination_parser, and pagination_with_current_user_parser which can be used between different responses so we don't have to keep redefining the same parameters, and added help text explaining what the parameters are
  • Fixes documentation for user challenges
  • Fixes documentation for associated wallets/get user by associated wallet
  • Changes some operation IDs to be better names, moving the more verbose descriptions to the description field

Tracks

  • Split apart repeated OperationIDs (trending, underground trending, recommendations - anything with two routes) to two differently documented routes (still functionally equivalent) to get rid of operation ID conflicts
  • Added descriptions and IDs to every route
  • Ensured all params were documented and all requests had an expect
  • TODO: Figure out what's going on with /by_id and the "explore" endpoints. I have some hot takes here, mainly as the explore endpoints are dependent on the user:
    • We shouldn't have a /by_id endpoint, we should update the root /tracks endpoint to take IDs
      • Also: needs to be authed for unlisted tracks via middleware?
    • tracks/under_the_radar isn't actually "Under the Radar" (yet) it's just a feed. It should be /my/feed* or /users/{id}/followees/activity (and be authed?)
    • Once we have under the radar for real on DN, it should be /my/smart-playlists/under-the-radar*
    • tracks/best_new_releases should be /my/smart-playlists/new-releases* (and be authed?)
    • tracks/most_loved should be /my/smart-playlists/most-loved* (and be authed?)

*For all of these, could also go for /users/{id} instead of /my or even just dropping the my, but I do like the idea of making it authed (no need to allow users to see each other's unless shared?) and grouping the smart playlists together. Open to ideas, but I don't think they should be on the root /tracks route and I prefer hyphens for routes over snake casing

Notes/Qs/Callouts

  • Many endpoints are missing an offset for pagination. Seems intentional for some, but others might not necessarily need to be so restrictive (eg. remixables)?
  • Limits are defaulted differently on some endpoints. Can we standardize? If not, I can do a pass and override as necessary. Did a pass and ensured default limits stay the same.
  • Added caching in some places, double check that's ok? Removed this
  • Same with @record_metrics?
    • Seems like this should be fine. Only added in a few full API endpoints
  • Do we really need responses defined everywhere?
    • I vote no, but no change for now
  • Was there a reason for the separate parser per route? Can add back via copy()s but wasn't sure if it was necessary. Might still be good to have for future maintenance?
    • Nobody seems to have an opinion on this
  • Should probably generate the API docs and host them some where for a copy proofread
  • Are there any APIs we want to make sure are always unlisted (even from our autogen?)
  • Do we want to autogen full or non-full or both?
    • Autogenning both
  • Get Track (v1/full) still uses get_unlisted_track. When is Marcus gonna clean this up??? 👀
    • GET ON IT
  • Normalized attribute order as best I could. Up for debate, but for now I made the order:
    1. @record_metrics
    2. @api.doc
    3. @api.expect
    4. @api.marshal_with
    5. @cache

Tests

There should be no functional changes from this PR ❗ - Everything I touched should only impact documentation. If you think something I did will affect functionality, let me know so I can make sure it gets tested. I do want to avoid testing each API individually 😨

How will this change be monitored? Are there sufficient logs?

Copy link
Contributor

@jowlee jowlee left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

Some notes:

  • I don't think we want to drop the trending version everywhere - as it is used when migrating default trending versions for a consistent user experience
  • One things that's not consistent everywhere is the responses in the ns.doc - in some places we have it and in other we don't (Note that it's not too useful even when we have it bc it's the same everywhere)
  • Since user_id was converted to id in the url params, do we want to update track_id to id in its respective route param for consistency? I don't it doesn't conflict so I'm fine either way

discovery-provider/src/api/v1/helpers.py Outdated Show resolved Hide resolved
class DescriptiveArgument(reqparse.Argument):
"""
A version of reqparse.Argument that takes an additional "description" param.
The "description" is used in the Swagger JSON generation and takes priority over "help".
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved


@full_ns.route(
"/recommended",
defaults={"version": DEFAULT_TRENDING_VERSIONS[TrendingType.TRACKS].name},
strict_slashes=False,
)
@full_ns.route("/recommended/<string:version>")
class FullRecommendedTrack(Resource):
class FullRecommendedTracks(Resource):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want to drop the ability to specify the version - it should help with migrations of default trending versions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added FullRecommendedTracksWithVersion to replace this route here which the same thing. It needs to be separate so that they can have different operation IDs (we can't have two routes with the same ID)

discovery-provider/src/api/v1/users.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/users.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/users.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/users.py Outdated Show resolved Hide resolved
@@ -838,7 +824,7 @@ def get(self, user_id):
)


@full_ns.route("/content_node/<string:replica_type>")
@full_ns.route("/content_node/<string:replica_type>", doc=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jowlee Thoughts on leaving this out of the typegen/documentation? (and/or any other endpoints that might be worth hiding?)

@rickyrombo
Copy link
Contributor Author

I don't think we want to drop the trending version everywhere - as it is used when migrating default trending versions for a consistent user experience

(addressed inline - it shouldn't be missing, just moved)

One things that's not consistent everywhere is the responses in the ns.doc - in some places we have it and in other we don't (Note that it's not too useful even when we have it bc it's the same everywhere)

Yeah I noticed this too - should we just remove it? I don't think it's adding any value...

Since user_id was converted to id in the url params, do we want to update track_id to id in its respective route param for consistency? I don't it doesn't conflict so I'm fine either way

No strong feelings here, I left it to reduce footprint of this change but could easily go the other way. I would have preferred to keep them user_id and track_id but alas the former I cannot, so I can see the argument for consistency.

@rickyrombo rickyrombo changed the title [AUD-1375] Prepare User API for Type Generation [AUD-1375] Prepare User and Track API for Type Generation Mar 29, 2022
@rickyrombo rickyrombo changed the title [AUD-1375] Prepare User and Track API for Type Generation [AUD-1375] Prepare User and Track APIs for Type Generation Mar 29, 2022
Copy link
Contributor

@piazzatron piazzatron left a comment

Choose a reason for hiding this comment

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

Re: Added caching in some places, double check that's ok? - do we know which endpoints we added caching for? Would like to double check this is safe

Copy link
Contributor Author

@rickyrombo rickyrombo left a comment

Choose a reason for hiding this comment

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

Added comments where cache was added

Removed added caching

discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
discovery-provider/src/api/v1/tracks.py Outdated Show resolved Hide resolved
@rickyrombo rickyrombo merged commit 01db549 into master Apr 1, 2022
@rickyrombo rickyrombo deleted the mjp-api-gen branch April 1, 2022 03:46
@AudiusProject AudiusProject deleted a comment from linear bot Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants