Files
MusicPlayer/server/generated/api_json.gd
T
Sansan f7619baf34 Use /api/v1 with token authentication and typed responses
Closes #38, #39 and #40; adds the client side of #41.

- Every request goes to /api/v1. MusicServerClient gets a token with
  Settings.api_password the first time one is needed, reuses it, and on a
  401 gets a new one and sends the request once more. Switching server gets
  a new token too. Callers never see the token.
- Sync is started with POST, as MusicServer 5.0 requires.
- The client has every endpoint in the server's OpenAPI spec, including
  statistics, soundtracks and songs by UUID, version, downloads and tokens.
- tools/generate_api_types.gd generates a typed class per schema in
  server/openapi.json into server/generated/. Song info, statistics and
  versions are passed to callers as these classes. A list the server sends
  as null is an empty list.
- FakeHttpTransport hands out tokens and answers 401 without one, so every
  test goes through the token flow. New tests cover the token handling,
  every endpoint and each generated class.
2026-10-06 22:45:28 +02:00

37 lines
1.3 KiB
GDScript

# Generated by tools/generate_api_types.gd from server/openapi.json.
# Do not edit; change the server and generate again.
class_name ApiJson
extends RefCounted
## Reads fields from parsed JSON for the generated API classes. A field that is
## missing, null or of the wrong type gives the default instead.
static func get_string(data: Dictionary, key: String, default: String = "") -> String:
var value: Variant = data.get(key)
return value if value is String else default
static func get_int(data: Dictionary, key: String, default: int = 0) -> int:
var value: Variant = data.get(key)
return int(value) if value is int || value is float else default
static func get_float(data: Dictionary, key: String, default: float = 0.0) -> float:
var value: Variant = data.get(key)
return float(value) if value is int || value is float else default
static func get_bool(data: Dictionary, key: String, default: bool = false) -> bool:
var value: Variant = data.get(key)
return value if value is bool else default
static func get_array(data: Dictionary, key: String) -> Array:
var value: Variant = data.get(key)
return value if value is Array else []
static func get_dictionary(data: Dictionary, key: String) -> Dictionary:
var value: Variant = data.get(key)
return value if value is Dictionary else {}