Commit graph sonda/internal/api/openapi
Author SHA1 Message Date
tgiachi
762d424816 fix(about): unusable pages fall through, MusicBrainz switch, merged items
- A page that cannot be used (no text, an address off Wikipedia, a redirect that is
  never followed) is now an answer: the chain goes on to the next language and the
  outcome is stored. Before, it was a failure asked about again at every view, and
  redirects counted against the provider's breaker.
- The chain also needs the MusicBrainz provider to be on, since the id goes to it
  with its own contact: nothing is sent to MusicBrainz that the admin did not allow.
  The disclosure in the provider settings, the spec and the README say so.
- A Wikidata item that was merged into another is understood through the target: the
  entity's own id is returned, compared with the page's item and stored. Verified on
  the real API.
- The title shown is the one Wikidata names (with spaces), control characters are
  dropped from the text (PostgreSQL refuses NUL), the text is cut to at most 4000
  characters with the mark included, and a stored description is reported disabled
  when the provider is off.
- A read that started before the provider was switched off does not save its result.
- Tests: the real clients with a redirect and a page without text, merged items,
  MusicBrainz off, switching off during a read.
2026-11-11 21:45:20 +01:00
tgiachi
48cb903115 feat(about): artist descriptions from Wikipedia
- GET /artists/{id}/description shows what Wikipedia says about an artist: a short
  text with its page, a link and the licence (CC BY-SA 4.0).
- New provider "wikipedia" (off by default, no key, contact in the User-Agent, which
  Wikimedia requires). The way to the text is a chain of ids, never a name: the
  artist's MusicBrainz id, the Wikidata item MusicBrainz links to it, the Wikipedia
  page Wikidata names in the first configured language that has one. A page is used
  only if it is an article about that same item.
- [wikipedia] languages in the config (one to five codes of two or three lower case
  letters, checked before they are sent: an unknown site makes Wikidata answer with
  every language).
- Stored 30 days (a day when there was nothing to find), served stale if Wikipedia
  fails, removed with the provider's data (the purge now reports descriptions).
- MusicBrainz client: WikidataID. Wikipedia client for Wikidata and the summary,
  which also reads Wikidata's errors that come with HTTP 200.
- artist_descriptions table (migration 0014, SQLite and PostgreSQL).
- Spec, contract test, README and example config updated.

Closes #39
2026-11-11 21:36:27 +01:00
tgiachi
7bdbc9e160 fix(images): limit parallel builds, no stale saves, safer files
- At most two covers are built at the same time: a page of albums asked for at once
  could decode dozens of large pictures together.
- A change to an album's files marks its record stale and moves a generation instead
  of deleting the row. A build that started before the change is not saved over it
  and starts again, so a "no cover" found too early cannot win for a day.
- A cover that was found is checked again after a week, so a picture replaced in a
  folder is noticed.
- For CD1/Disc 2 folders the picture in the folder above is used. Folder pictures
  are read one at a time, and the pixel count is computed in 64 bits.
- Stored files are synced before they get their name, an empty one counts as
  missing, and old temporary files from a crash are removed.
- Files without track or disc numbers sort the same on both databases.
- storage.data_dir defaults next to the SQLite database, so a service started from
  another folder does not need a writable working directory.
- Tests: a listener who leaves, a change during a build, the build limit, a named
  pipe, an embedded picture of a file outside the library that exists, builds that
  really overlap.
2026-11-11 21:03:26 +01:00
tgiachi
0e121ead8e feat(images): album covers from my own files
- GET and HEAD /albums/{id}/cover serve a JPEG made from the picture embedded in
  the album's files, or else a cover, folder, front, album or albumart image
  (jpg, jpeg, png) in the album's folder. ?size=small (300 px) or large (1000 px).
  The token can be in the query, so an <img> element can use it.
- Built the first time it is asked for, scaled, and kept in storage.data_dir
  (SONDA_DATA_DIR, default "data"); an album with no cover is remembered for a day.
  A new or changed file of the album, or a full rescan, clears the record.
- Nothing is sent anywhere. Pictures are untrusted: files are opened inside the
  library only (links are not followed), over 20 MB or 16 million pixels are
  ignored, and what is served is always a JPEG made here. Stored files are 0600.
- images table (migration 0013, SQLite and PostgreSQL).
- Spec, contract test, README and example config updated.

Closes #37
2026-11-11 20:52:36 +01:00
tgiachi
65e93ee84b fix(feedback): purge only what the provider named, no leak between users
- Purging a provider removes only the artists that provider's lists named. A
  purge of MusicBrainz, which names none, no longer deletes an artist only a
  wish kept alive, nor the wish.
- A mark no longer makes an artist visible to everybody: GET /artists/{id} and
  the similar lookups did, which showed what other users marked. Marking or
  unmarking needs an artist the user can see or has marked themselves, with the
  same answer for both.
- Deleting an account cleans up the discovered artists only its marks kept, in
  the same transaction and under the artist lock.
- Tests: a purge of another provider, deleting an account, the scanner adopting
  a marked artist, and what another user can see of a marked artist.
2026-11-11 20:18:04 +01:00
tgiachi
a6dbf60ac8 feat(feedback): a wishlist and "not interested"
- PUT/DELETE /wishlist/{artist} and GET /wishlist: the artists I want.
- POST/DELETE /discover/{artist}/dismiss and GET /discover/dismissed: the
  artists I am not interested in. An artist is wished or dismissed, never both,
  and both lists are mine alone.
- Discover never suggests a dismissed artist, does not use one as a seed taken
  from my listening, and marks the wished ones it shows (wishlisted).
- New artist_feedback table (migration 0012, SQLite and PostgreSQL), removed
  with the account.
- An artist I marked is not cleaned up when the list that named it is replaced,
  and goes when its last mark is taken off and nobody names it. Taking a
  provider's data back still removes what only it named, marks included.
- Spec, contract test and README updated.

Closes #35
2026-11-11 20:11:18 +01:00
tgiachi
f548423f73 fix(discover): ask permission first, stable order, honest docs
- Check the discover_from_listening setting before reading the listening
  history, so a refused request does no work and a database failure cannot turn
  it into a 500.
- Cosine adds up in tag order: the sum in map order changed in the last digit
  between runs, and equal artists could swap places between requests.
- A seed that could not be read is no longer listed as a seed.
- README and spec: Discover exists now; "disabled" means something had to be
  asked and Last.fm is off; the stored lookups are shared, so another local user
  can see from retrieved_at that an artist was looked up, but not who.
- Tests: the history is not read for a refused request, a stable cosine, tags
  fetched only for the pool and four at a time, a cancelled request stops,
  MusicBrainz is never asked, the setting is per user.
2026-11-11 19:48:51 +01:00
tgiachi
28c249c268 feat(discover): artists I may like, with a score I can explain
- GET /discover suggests artists, in my library or not, with a score from 0 to 1
  and its parts: affinity (similar to the artists I like), genre (tags close to
  mine), preference (what my listening says) and discovery (a bonus for what I
  have not played). Default weights 0.40, 0.25, 0.25, 0.10, set in [scoring].
- A part with no data (no tags) is left out and the others rescaled; the answer
  says which parts were there, and which seeds led to each suggestion.
- Seeds are the artists I name with ?seed=, or, only when I turned on
  discover_from_listening, the artists I play most. Without either the request is
  refused and nothing is sent to anyone.
- The tags of the best candidates are read from Last.fm only, only for those with
  none stored, a few at a time.
- taste.Service.Learn gives the whole picture (every preference, the liked
  artists, the tag profile); TagService.ProviderTags asks one provider.
- Spec, contract test, README and example config updated.

Closes #33
2026-11-11 19:42:09 +01:00
tgiachi
acede4bd91 fix(settings): strict body, deleted-account race, doc wording
- PATCH /me/settings accepts exactly one JSON object: text after it, null, a
  differently cased name or an unknown name are refused (400) and change nothing.
- A user deleted between the read and the write of the settings gives 401, not a
  500, on PostgreSQL too (foreign key violation mapped to user not found).
- The spec says a 401 can also mean the account no longer exists, and that the
  body is strict.
- README no longer says more than the setting does.
- Tests: strict body cases, tokens of a deleted account on GET and PATCH,
  recognising a foreign key violation on both databases.
2026-11-11 19:20:42 +01:00
tgiachi
e0592c0260 feat(settings): my own settings, starting with Discover from my listening
- GET and PATCH /me/settings: settings that belong to the signed-in user.
- First setting, discover_from_listening, is off by default. When on, Discover
  may start from the artists I listen to most, which sends their names to
  Last.fm.
- New user_settings table (migration 0011, SQLite and PostgreSQL), removed with
  the account. A user with no row has the private defaults.
- A misspelt setting is rejected instead of being ignored.
- Spec, contract test and README updated.

Refs #29
2026-11-11 19:16:26 +01:00
tgiachi
d251cc4f39 fix(taste): order by the score, clamp future events, keep tags short
- Order the liked artists by the weighted sum, not by tanh, which rounds to
  exactly 1 after about 58 listens and made heavy artists tie.
- An event dated after now counts as happening now, also for the last listen.
- Genres of files that are gone no longer shape the tag profile, as in
  /artists/{id}/tags.
- The tag list is capped at 50.
- A zero half-life falls back to 90 days instead of producing NaN.
- Document the 10 half-lives window and the new rules in the spec and README.
- Tests: heavy artists keep their order, tracks with two artists credit both,
  genres of a missing file are left out, the tag cap, a zero half-life.
2026-11-11 18:52:08 +01:00
tgiachi
544ec67dd1 feat(taste): learn what I like from what I listen to
- taste package: each listening event has a value (complete +1, a play that
  counts +0.5, a skip that does not count -1, a short play 0), older events
  weigh less (half-life 90 days, taste.half_life_days), and the values of an
  artist become a preference in (-1, 1) with tanh.
- Tag profile built from the artists I like: genres of my files plus the tags
  already stored from providers, each source scaled to its own best tag.
- GET /me/taste shows the liked artists and the tags. It reads local data only
  and never asks a provider.
- TasteRepo reads events, names and tags; tests on SQLite and PostgreSQL.
- OpenAPI spec, contract test, README and example config updated.

Closes #27
2026-11-11 18:46:58 +01:00
tgiachi
b0a7a562a6 fix(discovery): purge lock, cleanup chains and rescans that cannot read
- fix: on PostgreSQL a purge could delete a discovered artist while a scan was
  adopting it. The scan then failed on the missing artist for the whole file,
  and the two could also deadlock. Purge now takes the same artist lock as the
  scanner and discovery before it removes anything. Saving a list or tags does
  too, and an artist that is gone by then is reported as not found instead of a
  foreign key error, so a user who opened an artist that was removed meanwhile
  gets a 404
- fix: a discovered artist that was only the source of a list stayed forever and
  kept the artists of its own list alive, so chains built up. Cleanup now removes
  such an artist and then follows the chain until nothing more goes
- fix: in a full rescan a file that came back but could not be read stayed
  marked missing. It is restored first, as in a normal scan, and read as well
- fix: ?full given twice is refused, so a typo cannot start a scan of another
  kind
- fix: genre cleaning lives in one place, used by the reader and the store
- docs: the files genres count the tracks the artist is credited on, and the spec
  says every files tag is a genre
- test: a purge colliding with a scan on both databases (it fails without the
  lock), a chain of discovered artists, saving for an artist that is gone, a
  file that returns unreadable during a full scan
2026-11-11 17:36:14 +01:00
tgiachi
1857bb9c53 feat(discovery): remove provider data, genres from my files, full rescans
- feat: DELETE /api/v1/providers/{name}/data (admin) removes everything a
  provider gave: its lists of similar artists, its tags and the records of
  when it was asked, then the artists that only that data named and that
  nobody has files for. Last.fm's terms ask for this when an agreement ends.
  The user's own artists, music, listens and settings stay, the provider is not
  switched off, and a second call removes nothing
- feat: a discovered artist that no list names any more is removed when the
  list that named it is replaced, together with its tags, so they do not pile
  up. Real artists, and any artist that another list still names, are kept
- feat: the scan reads the GENRE tag of each file, offline (several genres
  separated by ";", lower case, at most five per file), and
  GET /artists/{id}/tags gets a third entry, files: the genres of the artist's
  own playable tracks, each weighted by how many tracks have it. It asks nobody
  and is always there
- feat: POST /library/scan and POST /libraries/{id}/scan take full=true to read
  every file again, not only the new or changed ones, so MusicBrainz ids and
  genres reach music that was indexed before. Files keep their identity, so
  listening history is kept. Anything but true or false is a 400
- test: the plan of a full scan, the scanner and the manager; the purge on both
  databases, checked by removing the rule that spares real artists; the
  cleanup of replaced lists; genres per file and per artist
- docs: README, OpenAPI and the todo list updated
2026-11-11 17:27:29 +01:00
tgiachi
175b87a4cc fix(discovery): ids from files, adoption and the scanner lock
- fix: a discovered artist adopted by id under another spelling kept its old
  match key, so the next file with the new spelling and no id created a second
  artist. The key now follows the name
- fix: when a real artist without an id and a discovered artist holding the id
  have the same name, the id now goes to the real artist and the discovered one
  lets go of it. Before, the scan created a second real artist and a second
  album, and could not repair it because the id was taken
- fix: when a file without an id adopts a discovered artist that had a provider
  id, the tags, the fetch records and the similar artists read under that id
  are dropped, since they are not known to be about the user's artist. Links
  from other artists to it stay. A file that confirms the very same id keeps
  everything
- fix: the album artist id is only read when the file has an album artist tag;
  with the tag missing the name is a fallback and the id would have landed on the
  wrong artist (a Various Artists id on the track's own artist)
- fix: one artist credit with one id ("X feat. Y" with the id of X, how beets
  writes it) is not paired: no id is safer than a wrong one. A name that is
  itself a single letter or contains a slash still gets its id
- fix: on PostgreSQL the scanner took the artist lock after it had already
  changed artist rows, which could deadlock with a concurrent similar-artists
  save. SaveFile now takes the lock first, once
- fix: Last.fm does not know every MusicBrainz id: when it does not know the id
  and there is a name, the name is tried, never autocorrected, as before ids
  were read from files
- fix: waiting for one provider's tags is bounded at 20 seconds, so a rate
  limited provider cannot hold a page for a minute
- docs: the tag range is 1 to 100 (a tag with no votes is dropped), the spec says
  where an artist's id can come from, and the README says when Last.fm gets an id
- test: adoption by spelling, the real artist with a discovered namesake,
  dropping and keeping what was read, album artist fallback, credits, an ID3
  frame, and the id-then-name fallback of Last.fm
2026-11-11 17:13:31 +01:00
tgiachi
07ea997cd0 feat(discovery): artist tags from Last.fm and MusicBrainz, and ids from my files
- feat: GET /api/v1/artists/{id}/tags lists, for each provider that is on, the
  tags it gives to an artist with its own weights, kept as they came: Last.fm's
  are relative to the artist, MusicBrainz's are counts of votes, and they are
  never mixed. MusicBrainz also marks the tags it lists as genres. The same
  rules as similar artists apply: asked only on demand, kept 7 days (1 for an
  unknown artist), old data served when a provider fails, and one call for
  simultaneous requests. A provider that is off, failing or lacking an id does
  not hide the other
- feat: a thin MusicBrainz client that reads an artist's tags and genres by its
  id. It never searches by name, because a search returns look-alikes and
  picking one would be a guess. The id is checked before it reaches the path,
  and errors never repeat the provider's text
- feat: the User-Agent can change while the server runs, so the contact an
  admin sets for MusicBrainz applies to the next request; if the settings
  cannot be read it falls back to the project address
- feat: Last.fm top tags, by id when known and by name otherwise, never
  autocorrected
- feat: the scan reads MusicBrainz artist ids from the file tags, offline, and
  keeps them on the artists. An id is only used when it can be paired with its
  artist for certain: the same number of ids as artists, all valid. The same id
  is the same artist whatever the spelling, an artist without an id takes the
  one its file gives, and another id under the same name is another artist. A
  file that confirms the id a provider gave to a discovered artist keeps it
- feat: POST /providers/musicbrainz/test checks that the service answers
- test: what leaves the server for MusicBrainz is checked from the other end:
  the id of the artist and the admin's contact, nothing from the library;
  removing the safeguards on ids and pairing makes tests fail
- docs: README, OpenAPI and the provider text updated
2026-11-11 17:01:43 +01:00
tgiachi
b769ad7ac5 fix(discovery): concurrent writes, adopted artists and a client that leaves
- fix: on SQLite a transaction that read and then wrote failed at once with
  "database is locked" when another writer committed in between, because the
  busy timeout does not apply there. Transactions now start with BEGIN
  IMMEDIATE. Before this change a scan running while someone opened similar
  artists made files fail, and parallel requests stored nothing
- fix: on PostgreSQL two requests naming the same new artist could fail on the
  unique MusicBrainz id or leave two rows with one name. Creating artists, in
  the discovery store and in the scanner, now takes turns through an advisory
  lock and looks again once it has the turn
- fix: music arriving for an artist that a provider only named used to keep the
  provider's spelling and its unchecked MusicBrainz id, which later lookups
  would then send instead of the name. Such artists are now marked
  (artists.discovered); the first scan that finds them renames them to the
  spelling of the file tags, drops the id and clears the mark
- fix: a panic in the shared provider call is turned into a failure; the
  singleflight group would have re-raised it where nothing can recover
- fix: a client that leaves while Last.fm is being asked no longer gets a 500
  and an error in the log
- fix: no page can ask for more than is stored (limit tops out at 50), and the
  docs no longer say the best score is always 1
- test: concurrent saves plus a scan on both databases, checked by removing each
  fix; adoption keeps neither the name nor the id; the panic; the client that
  leaves
2026-11-11 16:47:33 +01:00
tgiachi
aafb2dd906 feat(discovery): similar artists from Last.fm
- feat: GET /api/v1/artists/{id}/similar lists the artists Last.fm finds similar
  to one in the library, best first, each with the provider's own score and
  rank and a flag saying whether it is in the library. It answers 200 when the
  provider is off or failing, with provider_status, stale and retrieved_at
- feat: a thin Last.fm client on top of the outbound client. It always sends
  autocorrect=0 so a misspelled local name cannot turn into another artist,
  prefers the MusicBrainz id when known, always sets a limit, and reads the
  error field even when the status is 200. Errors never carry the URL or the
  provider's own message, because the key travels in the query string
- feat: results are stored in artist_similar with a freshness ledger in
  provider_fetches: 7 days for an answer, 1 day for "unknown artist". Old data
  is served when the provider fails, and concurrent requests for the same
  artist share one call that does not depend on the first caller staying
- feat: artists named by a provider but without files become artists without
  tracks. GET /artists/{id} can show them (track_count 0), the lists of the
  library never include them, and a later scan adopts them by name. A provider
  id is never written onto an existing artist; names match only when at least
  one side has no id, and different ids always mean different artists
- feat: POST /providers/{name}/test (admin) checks a stored key with one cheap
  request, whether the provider is on or off, and reports ok, no_api_key,
  key_refused, rate_limited, unreachable or error
- test: the whole request is checked from the receiving end, with a user, a
  listen, a title and a library path in the database: only the artist and the
  key leave, with a User-Agent that names the project
- docs: README and OpenAPI updated; the contract test calls the new operations
2026-11-11 16:42:52 +01:00
tgiachi
e231860119 fix(providers): keep the key out of errors and make the outbound client robust
- fix: errors from the outbound client no longer carry the query string. Go puts
  the whole URL into a transport error, and a Last.fm key travels in the query,
  so any log of such an error would have written the key. The host and path stay
  for debugging and the cause can still be matched with errors.Is
- fix: a request that gives up while waiting for its turn gives the turn back,
  and a turn is not taken at all when the wait would pass the caller's deadline.
  Before, a burst of impatient callers pushed the queue further away until no
  request ever reached the provider
- fix: failures of requests that were already in flight when the provider died
  no longer double the breaker window each; one outage opens it once
- fix: redirects and oversized answers count as failures, so a provider that
  keeps answering that way stops being asked
- fix: sending an empty api_key to a provider that needs none (MusicBrainz) no
  longer turns it off
- test: the query string in transport errors, refused connections and timeouts;
  cancelling during the wait; the deadline shorter than the wait; twelve
  concurrent failures; redirects and big answers; the empty key. Checked by
  removing each fix on purpose
2026-11-11 16:11:53 +01:00
tgiachi
9f4da2e77e feat(providers): provider settings in a table and a careful outbound HTTP client
- feat(storage): provider_settings table (provider, enabled, api_key, contact);
  migration 0007 for both drivers. A provider with no row, or turned off, is
  never contacted
- feat(providers): a service that validates and applies settings: a Last.fm key
  is 32 hexadecimal characters, enabling a provider that needs a key without
  one is refused, clearing the key turns the provider off, a contact cannot
  contain parentheses or control characters. Each provider states what it sends
  and under which terms, and what it never sends
- feat(api): admin-only GET /providers and PUT /providers/{name}. The API key is
  write-only: responses carry only has_api_key, errors never repeat it and the
  request log never contains it (tested)
- feat(providers/outbound): the only way Sonda talks to the outside: plain GET
  with an identifiable User-Agent, no cookies, no Referer, no Authorization, no
  redirects, bounded answers, a timeout per attempt, a minimum interval between
  requests, retries with exponential backoff that honour Retry-After without
  waiting past the caller's deadline or for an absurd time, and a circuit
  breaker that makes a failing provider fail fast
- feat(providers): UserAgent builds "Sonda/version ( contact )" as MusicBrainz
  asks, defaulting to the project address so no personal address is sent
- breaking(config): providers.lastfm and SONDA_LASTFM_API_KEY are gone; an old
  config, or the variable, fails with a hint instead of being ignored
- docs: OpenAPI operations and schemas, README section on the providers and on
  what leaves the server
- test: fake servers and a fake clock only; no network in the suite
2026-11-11 16:07:12 +01:00
tgiachi
32068f7cf6 fix(listening): report a deleted account first and document one event per play
- fix: a listen from a deleted account is answered 401 before the track or the
  duration is looked at, so a client that signs out on 401 does it whatever
  else is wrong with the request (UserExists on the store)
- docs: one event per play, sent when the play ends or is abandoned, with one
  idempotency key per play. An event cannot be upgraded afterwards: a key that
  was already used is ignored even if the type or duration differ, and a new
  key would count the same play twice. The README no longer says to report at
  20 seconds, which led straight into that trap, and no longer hard-codes the
  minimum
- test: the SQL filter at exactly the threshold and just under it, the order of
  events within the same second, the order of checks for a deleted account
2026-11-11 15:02:28 +01:00
tgiachi
7047e07906 feat(listening): count a listen after a minimum play time and expose the history
- feat: an event counts as a listen when it is `complete`, or when it was
  played for at least listening.min_listen_seconds (default 20, 1 to 3600).
  The rule is applied when the history is read, not when an event is stored,
  so changing the setting re-reads the past; streaming never counts
- feat(api): POST /listens answers with `counted`, also for a duplicate
- feat(api): GET /listens returns the signed-in user's own history, newest
  first, with `counted` per event, paging and ?counted=true; nobody sees
  anybody else's events
- feat: a reported play time more than twice the track length plus ten seconds
  is rejected as implausible; looping and seeking back stay allowed, and a
  track of unknown length is not checked
- feat(storage): TrackDurationMs and ListEvents on SQLite and PostgreSQL
- docs: OpenAPI operations and schemas, README rule, setting, API table and a
  demo that reports a 25 s and a 3 s play and reads the history; the demo tones
  now last 30 s so a 25 s play is plausible
- test: the rule at its boundaries, the plausibility bound, history order,
  paging and isolation on both databases, and the contract test for the new
  operation

Closes #17
2026-11-11 14:58:47 +01:00
tgiachi
2ae4aedac0 fix(api): make the spec say what the code does, and make the tests prove it
- fix(spec): album.artist and track.album are real nullable objects (OpenAPI
  3.0 only honours nullable next to a type); the stream documents 304 on HEAD,
  412, If-Unmodified-Since and multipart/byteranges answers
- fix(spec): passwords and idempotency keys are measured in bytes, an overlap
  between libraries is a 400, a library PATCH needs a name or a path, limit 0
  means the default, login has no format rules of its own, and the wording about
  signing out says that issued access tokens live until they expire
- fix(auth): the Bearer scheme is matched ignoring case (RFC 7235)
- fix(listening): a listen with the access token of a deleted account is a 401
  instead of a database error
- fix(docs): the docs pages answer HEAD and carry X-Frame-Options, a CSP
  frame-ancestors, nosniff and no-referrer, since people paste their token there
- test: error codes are asserted in every error case; every accepted request is
  validated against the spec too; HEAD and 3xx answers are checked by hand
  because the validator skips them; the stream Content-Type must be one the
  spec lists; a scan held mid-way proves the scan_running conflicts; null album
  and null album artist, a vanished file, multi-range, 412 and HEAD 304 are
  exercised. Verified by breaking the code and the spec on purpose
2026-11-11 14:46:28 +01:00
tgiachi
9d28a8a99c feat(api): OpenAPI spec and an offline Swagger UI
- feat: internal/api/openapi/openapi.yaml describes every operation (OpenAPI
  3.0.3), written by hand and embedded in the binary; GET /api/v1/openapi.yaml
  serves it
- feat: GET /api/docs/ serves Swagger UI from assets embedded in the binary
  (github.com/swaggest/swgui, v5emb), so opening it never contacts another
  server; both are public because they contain no data
- feat: response objects in the spec are closed (additionalProperties: false)
- test: the spec is valid OpenAPI; the router and the spec describe the same
  operations in both directions; every operation has an id, a summary, a tag,
  a documented 401 when it needs a token and a 403 when it is admin only
- test: a contract test drives every operation through the real services,
  including a real scan and real streaming, and validates each response
  (status, headers, JSON body) against the spec with kin-openapi; it fails if
  an operation was never exercised. Checked by breaking the code and the spec
  on purpose
- test: the docs page loads without any external address and every asset it
  references is served
- docs: README section on the interactive documentation and on keeping the
  spec in step with the code

Closes #15
2026-11-11 14:35:16 +01:00