Convert strings to enums #2153

Closed
opened 2026-02-06 21:47:57 +03:00 by OVERLORD · 7 comments
Owner

Originally created by @nielsvanvelzen on GitHub (Sep 27, 2020).

A lot of our API uses strings to communicate where enums would be preferable. Converting those properties to enums will help the apiclient generation and automatically documents all valid values, causing less errors introduced via misspelling or wrong capitalization.

For example: the image API contains a parameter called "format". I know the value can be "png". But can it also be "bmp"? You won't know if the server just says it's a string, an enum will always make sure all available options are exposed and no more or less.

Missing types

Feel free to leave a comment (or edit this post directly) to add types not listed

File name - Property - Pull Request

Api

  • Jellyfin.Api/Controllers/ImageController - GetItemImage.format - #4259
  • Jellyfin.Api/Controllers/SessionController PostCapabilities.supportedCommands - #4252
  • Jellyfin.Api/Controllers/SubtitleController - GetSubtitle.format

Common fields

Most of these are used in multiple controllers

  • Jellyfin.Api/Controllers/* - *.fields - #4302
  • Jellyfin.Api/Controllers/* - *.filters - #4303
  • Jellyfin.Api/Controllers/* - *.sortBy
  • Jellyfin.Api/Controllers/* - *.sortOrder - #5091
  • Jellyfin.Api/Controllers/* - *.excludeItemTypes
  • Jellyfin.Api/Controllers/* - *.excludeLocationTypes - #4304
  • Jellyfin.Api/Controllers/* - *.includeItemTypes
  • Jellyfin.Api/Controllers/* - *.imageTypes - #4305
  • Jellyfin.Api/Controllers/* - *.enableImageTypes - #4305
  • Jellyfin.Api/Controllers/* - *.mediaTypes
  • Jellyfin.Api/Controllers/* - *.personTypes
  • Jellyfin.Api/Controllers/* - *.libraryContentType
  • Jellyfin.Api/Controllers/* - *.collectionType

Models

  • MediaBrowser/Model/Session/ClientCapabilities - PlayableMediaTypes
  • MediaBrowser/Model/Session/ClientCapabilities - SupportedCommands
  • MediaBrowser/Model/Dto/BaseItemDto - Type

WebSockets

  • MediaBrowser.Model/Session/GeneralCommand - Name - #4192
  • MediaBrowser.Model/Net/WebSocketMessage - MessageType - #4210

Helping out

Want to help fix these issues? Awesome! Please leave a comment which type you're working on (and check if no-one else it working on it already) and link to this issue when creating your pull request.

For questions about the code or discussing something else our Matrix channels are open 24/7!

Originally created by @nielsvanvelzen on GitHub (Sep 27, 2020). A lot of our API uses strings to communicate where enums would be preferable. Converting those properties to enums will help the apiclient generation and automatically documents all valid values, causing less errors introduced via misspelling or wrong capitalization. For example: the image API contains a parameter called "format". I know the value can be "png". But can it also be "bmp"? You won't know if the server just says it's a string, an enum will always make sure all available options are exposed and no more or less. ## Missing types _Feel free to leave a comment (or edit this post directly) to add types not listed_ **File name** - **Property** - **Pull Request** ### Api - [x] Jellyfin.Api/Controllers/ImageController - GetItemImage.format - #4259 - [x] Jellyfin.Api/Controllers/SessionController PostCapabilities.supportedCommands - #4252 - [ ] Jellyfin.Api/Controllers/SubtitleController - GetSubtitle.format ### Common fields _Most of these are used in multiple controllers_ - [x] Jellyfin.Api/Controllers/* - *.fields - #4302 - [x] Jellyfin.Api/Controllers/* - *.filters - #4303 - [ ] Jellyfin.Api/Controllers/* - *.sortBy - [x] Jellyfin.Api/Controllers/* - *.sortOrder - #5091 - [ ] Jellyfin.Api/Controllers/* - *.excludeItemTypes - [x] Jellyfin.Api/Controllers/* - *.excludeLocationTypes - #4304 - [ ] Jellyfin.Api/Controllers/* - *.includeItemTypes - [x] Jellyfin.Api/Controllers/* - *.imageTypes - #4305 - [x] Jellyfin.Api/Controllers/* - *.enableImageTypes - #4305 - [ ] Jellyfin.Api/Controllers/* - *.mediaTypes - [ ] Jellyfin.Api/Controllers/* - *.personTypes - [ ] Jellyfin.Api/Controllers/* - *.libraryContentType - [ ] Jellyfin.Api/Controllers/* - *.collectionType ### Models - [ ] MediaBrowser/Model/Session/ClientCapabilities - PlayableMediaTypes - [x] MediaBrowser/Model/Session/ClientCapabilities - SupportedCommands - [ ] MediaBrowser/Model/Dto/BaseItemDto - Type ### WebSockets - [x] MediaBrowser.Model/Session/GeneralCommand - Name - #4192 - [x] MediaBrowser.Model/Net/WebSocketMessage - MessageType - #4210 ## Helping out Want to help fix these issues? Awesome! Please leave a comment which type you're working on (and check if no-one else it working on it already) and link to this issue when creating your pull request. For questions about the code or discussing something else our [Matrix channels](https://jellyfin.org/docs/general/getting-help.html) are open 24/7!
Author
Owner

@skyfrk commented on GitHub (Oct 1, 2020):

I'll take on Jellyfin.Api/Controllers/SessionController PostCapabilities.supportedCommands and MediaBrowser/Model/Session/ClientCapabilities - SupportedCommands in one PR.

@skyfrk commented on GitHub (Oct 1, 2020): I'll take on `Jellyfin.Api/Controllers/SessionController PostCapabilities.supportedCommands` and `MediaBrowser/Model/Session/ClientCapabilities - SupportedCommands` in one PR.
Author
Owner

@ConfusedPolarBear commented on GitHub (Oct 2, 2020):

I can convert Jellyfin.Api/Controllers/ImageController - GetItemImage.format.

@ConfusedPolarBear commented on GitHub (Oct 2, 2020): I can convert `Jellyfin.Api/Controllers/ImageController - GetItemImage.format`.
Author
Owner

@crobibero commented on GitHub (Oct 10, 2020):

Notes: sortBy, orderBy can't be easily converted

includeItemTypes, excludeItemTypes, mediaTypes, personTypes, collectionType
need to stay as string because they're used in the librarydb mess.

@crobibero commented on GitHub (Oct 10, 2020): Notes: `sortBy`, `orderBy` can't be easily converted `includeItemTypes`, `excludeItemTypes`, `mediaTypes`, `personTypes`, `collectionType` need to stay as string because they're used in the librarydb mess.
Author
Owner

@nielsvanvelzen commented on GitHub (Oct 10, 2020):

It's unfortunate we can't convert those right now. Do you think it's possible when the database migration is done?

@nielsvanvelzen commented on GitHub (Oct 10, 2020): It's unfortunate we can't convert those right now. Do you think it's possible when the database migration is done?
Author
Owner

@crobibero commented on GitHub (Oct 10, 2020):

Yep, they can all be changed once database migration is done, or if we were to change how the query is generated (boooooo)

@crobibero commented on GitHub (Oct 10, 2020): Yep, they can all be changed once database migration is done, or if we were to change how the query is generated (boooooo)
Author
Owner

@crobibero commented on GitHub (Oct 10, 2020):

Todo- change all enum to be not-plural

@crobibero commented on GitHub (Oct 10, 2020): Todo- change all enum to be not-plural
Author
Owner

@nielsvanvelzen commented on GitHub (May 16, 2021):

Closing this issue now as it became slightly outdated, most (but not all 😉) properties use enums now!

@nielsvanvelzen commented on GitHub (May 16, 2021): Closing this issue now as it became slightly outdated, most (but not all 😉) properties use enums now!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/jellyfin#2153