Skip to content

fix(apiv2): list null in the enum of nullable request members - #3534

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/openapi-nullable-enum
Nov 9, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
blurbery:fix/openapi-nullable-enum

Conversation

@blurbery

@blurbery blurbery commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2980
Related issue: N/A
Validation tasks: none (only the generated /api/v2 document changes; the server handles requests exactly as before)

Two nullable request members in the /api/v2 OpenAPI document have an enum that leaves out null, so a client that validates requests against the document, or generates strict types from it, refuses a null the server accepts. This change adds null to those enums and adds a spec lint rule so it can't come back.

The members are ProfileUpdate.max_playback_quality (null removes the playback ceiling) and AdminItemMetadataUpdate.status (null leaves the match status unchanged). Huma writes "type": ["string", "null"] for a nullable schema but leaves its enum alone, and JSON Schema 2020-12 applies type and enum separately. The bundled web types weren't affected, because openapi-typescript adds | null from type.

Approach

GenerateOpenAPI now adds null to the enum of every nullable component schema after registration. That replaces the TransformSchema on AdminPlaybackHistoryEntry, which did the same for three response fields; their output is byte-identical.

I went with one pass over the document rather than copying that transformer onto two more types. It covers the next nullable enum without anyone having to remember, and it keeps the runtime schemas as they are. A transformer on a request type would also feed null into Huma's precomputed 422 message (expected value to be one of "1080p, 2160p, <nil>"). Request validation doesn't need the change: Huma accepts null on a nullable schema before it checks the enum.

The spec lint in internal/contractspec now fails a nullable schema whose enum leaves out null, in the same places the generator walks: members, array items, typed map values and oneOf/anyOf/allOf branches. I added the rule to the enum conventions in docs/architecture/api-contract.md as well.

DownloadSubscriptionPatchBody.quality is held out on purpose, through apiv2.NullEnumWithheld. It's the opposite case: Patch[T].Schema documents every member as nullable, but updateDownloadSubscription answers 400 for null on all six monitor fields. For quality, the enum without null is the only part of its schema that matches the server, so adding null would document something the server rejects. The real fix is to stop documenting those six fields as nullable. That narrows the request contract and needs a breaking-change approval, so I've left it for a follow-up. The lint fails the withheld entry once the member no longer needs it.

Validation

The contract checks below ran on 674cd7087. The internal/apiv2 runs were on cbbf4de24; the later commits only touch internal/contractspec and a doc sentence.

  • make apiv2-openapi and make verify-apiv2-openapi: regenerated and current; only the two enums change.
  • make apiv2-web-types and make verify-apiv2-web-types: current, no change to the web types.
  • make verify-apiv2-contract against main: the lint passes, and the diff reports three request-property-enum-value-added changes (updateProfile, updateAdminUserProfile, updateAdminItemMetadata), none breaking.
  • The new rule run against the previous document fails on exactly the two members. Seeded lint cases cover the rule and a stale withheld entry.
  • make verify-apiv2-fixtures, TestCommittedArtifactMatchesRouter, the internal/contractspec tests and focused internal/apiv2 tests: pass.
  • go vet on both packages, and golangci-lint --new-from-merge-base on internal/contractspec: clean.
  • The rest of the full gate, including make lint-changed for internal/apiv2, make test-go and the web checks, runs on CI.
  • Benchmarks: not applicable, only the generated document changes.

Evidence

No screen changes. What clients see is the GET /api/v2/openapi.json response, which serves the committed contracts/api/v2/openapi.json bytes. The three nullable enum members in it, trimmed to type and enum:

Before and after

Before (main at 2d5f22e7d):

ProfileUpdate.max_playback_quality:     {"type": ["string", "null"], "enum": ["1080p", "2160p"]}
AdminItemMetadataUpdate.status:         {"type": ["string", "null"], "enum": ["pending", "matched", "unmatched"]}
DownloadSubscriptionPatchBody.quality:  {"type": ["string", "null"], "enum": ["original", "20mbps", "10mbps", "5mbps", "2mbps", "1mbps"]}

After (this branch at 674cd7087):

ProfileUpdate.max_playback_quality:     {"type": ["string", "null"], "enum": ["1080p", "2160p", null]}
AdminItemMetadataUpdate.status:         {"type": ["string", "null"], "enum": ["pending", "matched", "unmatched", null]}
DownloadSubscriptionPatchBody.quality:  {"type": ["string", "null"], "enum": ["original", "20mbps", "10mbps", "5mbps", "2mbps", "1mbps"]}

Risks

The request contract only widens, for two fields, to match what the server already accepts. Clients generated from the old document keep working. There's no runtime change. DownloadSubscriptionPatchBody still documents six nullable fields the server refuses as null, as it did before.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (desktop app)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5
  • Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
  • Adversarial review: a separate Claude Code subagent (claude-opus-5-5) reviewed the diff without my conclusions. It checked that the generator reaches every nullable enum, runtime validation and 422 messages, mutation of shared schemas, the lint decoding and exemption, and that removing the transformer leaves the document byte-identical. It found nothing blocking. I narrowed the doc sentence to the locations the lint actually checks (members and array items).

Note

Include null in enums of nullable request members in apiv2 OpenAPI document

  • Adds a document-generation pass in document.go that appends null to nullable enums across component schemas (properties, items, typed maps, oneOf/anyOf/allOf branches). The registered request schemas themselves stay unchanged.
  • Replaces the entry-specific schema hook in admin_playback_history.go with this central pass.
  • Adds a nullable-enum lint rule in lint.go that reports nullable enums missing null, with an exception table (NullEnumWithheld) whose entries must keep a nullable enum without null. DownloadSubscriptionPatchBody.quality is the first withheld member.
  • Documents the convention in api-contract.md and regenerates contracts/api/v2/openapi.json.
  • Risk: behavioral change only in the generated OpenAPI artifact — nullable enums now list null except for entries in NullEnumWithheld in document.go; consumers of the committed contract should re-diff it.

Macroscope summarized 674cd70.

JSON Schema 2020-12 applies type and enum separately, so a member typed
["string", "null"] whose enum lists only strings still refuses null.
ProfileUpdate.max_playback_quality (null removes the ceiling) and
AdminItemMetadataUpdate.status (null leaves it unchanged) were documented
that way, so a client that validates against /api/v2 refused a null the
server accepts.

GenerateOpenAPI now adds null to the enum of every nullable component
schema after registration, which replaces the per-type transformer on
AdminPlaybackHistoryEntry. The pass runs on the document only: Huma's
validator accepts null on a nullable schema before it checks the enum,
and the registered enum stays as it was, so the 422 message for a bad
value doesn't gain a null.

DownloadSubscriptionPatchBody.quality is held out through
apiv2.NullEnumWithheld: Patch documents it as nullable, but the handler
answers 400 for null on every monitor field.

The spec lint now fails a nullable enum without null, and fails a
NullEnumWithheld entry once its member no longer needs it.

Closes Silo-Server#2980
goconst flags a string literal used three times, and the nullable enum
rule added the third use of "components.schemas.". The contract doc
now says which locations the lint checks: members and array items.
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 5, 2026
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

OpenAPI generation now adds null to nullable enums, with one named exception, and contract lint checks this representation. The committed v2 document includes null in two nullable enums. The playback-history-specific schema transform was removed.

Changes: Nullable enum contract

Layer / File(s) Summary
Nullable-enum OpenAPI generation
internal/apiv2/document.go, internal/apiv2/admin_playback_history.go, contracts/api/v2/openapi.json
OpenAPI generation recursively adds null to nonempty enums on nullable schemas, except for named withheld members. The committed document adds null to two enums. The playback-history-specific schema transform was removed.
Nullable-enum lint and documentation
internal/contractspec/lint.go, internal/contractspec/lint_test.go, docs/architecture/api-contract.md
Contract lint checks nullable enum values against the withheld-member registry and reports stale exceptions. Tests cover missing and incorrectly included null values, and the API contract guide documents the rule.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

Suggested labels: bug, go, api-v2, impact: usability, size/M

Suggested reviewers: quick104

Merge Risk: Low · up to 32161

Invalid nullable enums in composed schemas or map values can pass lint. Merge with this limitation acknowledged.

Security architecture risk: Minimal · up to 32161

The published contract is corrected without expanding server-side permissions or accepted request behavior. The field that rejects null retains its explicit exception and handler-side rejection. No material security risk was identified in this change.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The effective change reaches consumers that validate against the public document or generate strict request types. It does not create a new server route or grant additional authority: the changed enum lists describe null values already accepted by the existing nullable request paths.

Trust Boundaries and Controls

  • observed — DownloadSubscriptionPatchBody.quality remains excluded from null admission. Its existing handler resolves viewer identity and rejects any null monitor field before constructing a patch or invoking the mutation service. The PR does not remove or weaken that guard.

Resilience and Maintainability Implications

  • inferred — The normalization transition is confined to a fresh generation-owned schema graph. Checking for an existing null makes repeated traversal idempotent, clipping the enum before append avoids overwriting a shared backing array, and serialization errors return no document. Consequently, partial normalization does not publish a live request-validation configuration requiring recovery.
Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Linked Issues check Inconclusive Issue #2980 names three nullable enum members. Evidence from the whole-PR diff (merge base 2d5f22e to head 321615b):

- ProfileUpdate.max_playback_quality: met. contracts/api/v2/openapi.json adds …
Missing evidence: the behavior of updateDownloadSubscription for a null value in the six monitor fields, including quality. The handler is in internal/apiv2 (for example download_subscription_mutations.go or download_subscriptions.go). The …
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title "fix(apiv2): list null in the enum of nullable request members" matches the main change. The diff adds null to the enums of nullable request members (ProfileUpdate.max_playback_quality and A…
Out of Scope Changes check Passed Changed files and their connection to #2980:

- contracts/api/v2/openapi.json: two enum lines changed. These implement the requested fix.
- internal/apiv2/document.go: adds admitNullInNullableEnums, w…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Description check Passed The pull request description directly explains the nullable enum changes, generated OpenAPI updates, lint rule, intentional exclusion, validation, and risks covered by the changeset.
Full details: Title check

Explanation

The title "fix(apiv2): list null in the enum of nullable request members" matches the main change. The diff adds null to the enums of nullable request members (ProfileUpdate.max_playback_quality and AdminItemMetadataUpdate.status) in the generated /api/v2 OpenAPI document, and adds a lint rule to enforce it. The title is specific and concise, and it leads with the primary change.

Full details: Out of Scope Changes check

Explanation

Changed files and their connection to #2980:

  • contracts/api/v2/openapi.json: two enum lines changed. These implement the requested fix.
  • internal/apiv2/document.go: adds admitNullInNullableEnums, which runs after registration, and the NullEnumWithheld table. This generic pass is the mechanism that adds null to the two enums. The pass also covers other nullable enums, but the openapi.json diff shows no other enum change. The withheld table records the deliberate exclusion of quality.
  • internal/apiv2/admin_playback_history.go: removes TransformSchema, which applied the same null addition to three response fields. The generic pass replaces it. The PR states that the generated output is byte-identical. The openapi.json diff does not contradict this.
  • internal/contractspec/lint.go and lint_test.go: add a rule that fails a nullable enum without null, and a stale-withheld check. These prevent recurrence of the bug class in #2980. Their scope is wider than the two named members, but they do not change runtime behavior.
  • docs/architecture/api-contract.md: documents the nullable enum convention that the lint enforces.

No change is unrelated to #2980. I did not run the tests. My conclusions rely on the diff and the PR description for the byte-identical output and the lint behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files. (2 skipped: 2 unsupported.)

Full details: Linked Issues check

Explanation

Issue #2980 names three nullable enum members. Evidence from the whole-PR diff (merge base 2d5f22e to head 321615b):

  • ProfileUpdate.max_playback_quality: met. contracts/api/v2/openapi.json adds null to the enum ("1080p", "2160p", null). The type list already contains "null".
  • AdminItemMetadataUpdate.status: met. The same file adds null to the enum ("pending", "matched", "unmatched", null).
  • DownloadSubscriptionPatchBody.quality: not met as written in the issue. The enum still omits null while type includes "null". The PR excludes this member through apiv2.NullEnumWithheld in internal/apiv2/document.go. The PR states that updateDownloadSubscription returns 400 for null on the monitor fields. I did not read that handler, so this claim is unverified.

If the handler accepts null for quality, #2980 requires null in this enum, and this PR does not meet that requirement. If the handler rejects null, the issue expected behavior for quality conflicts with server behavior. The correct fix then changes the request contract, which the PR describes as a breaking change to be handled separately.

The generic pass in internal/apiv2/document.go covers the same mechanism that the issue proposes, so no other nullable enum needs a separate change.

Resolution

Missing evidence: the behavior of updateDownloadSubscription for a null value in the six monitor fields, including quality. The handler is in internal/apiv2 (for example download_subscription_mutations.go or download_subscriptions.go). The file listing for internal/apiv2 was truncated before these files appeared, and I did not read them. With that evidence, a reviewer can decide whether quality requires null in its enum (#2980 unmet for this member) or whether the withheld member and the follow-up contract change satisfy the issue (#2980 met with a documented deviation). A maintainer should confirm which outcome applies and record it on #2980.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish triaged High-confidence review completed; does not mean fixed, validated, or accepted for release. labels Nov 5, 2026
Comment thread internal/contractspec/lint.go Resolved
@coderabbitai coderabbitai Bot added the impact: usability Core flow broken or severely blocked label Nov 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fc4c37f8-80e0-4333-830d-e968414464d1
Commits

Reviewing files that changed from the base of the PR and between 2d5f22e and 321615b.

Files selected for processing: 6

  • contracts/api/v2/openapi.json
  • docs/architecture/api-contract.md
  • internal/apiv2/admin_playback_history.go
  • internal/apiv2/document.go
  • internal/contractspec/lint.go
  • internal/contractspec/lint_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Comment thread internal/contractspec/lint.go Resolved
The nullable enum rule walked only members and array items, so a nullable
enum in a oneOf, anyOf or allOf branch or a typed map value passed the lint
although the generator covers those places. The rule now has its own walk
over all of them.
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104

Quick104 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 674cd7087. I found nothing to fix, so I pushed nothing to the branch.

Findings: none. The two earlier lint threads (composed schemas and map values) are fixed in 674cd7087. I confirmed the walk and its seeded cases against the source.

What I checked

  • The served document is the committed bytes (contracts.OpenAPI). GenerateOpenAPI builds a fresh registry on every call, and only the generator command and tests call it. The pass therefore can't change the router's runtime schemas, and slices.Clip makes the append copy rather than write into a shared backing array.
  • Huma v2.38.0 returns early on null for a nullable schema (validate.go:424), before the enum check (validate.go:583). Request handling and 422 messages stay the same.
  • Both widened members accept null at runtime. updateProfile clears the ceiling, and a nil status leaves the match status unchanged. updateDownloadSubscription answers 400 for null on all six monitor fields, so withholding quality is right. fix(apiv2): stop documenting the monitor patch fields as nullable #3535, stacked on this PR, documents those fields as not nullable and removes the table.
  • With this branch merged into current main, make verify-apiv2-openapi and make verify-apiv2-web-types report the committed artifacts as current. Main has added no new nullable enum since the branch point, so the branch didn't need an update. The internal/contractspec tests and the artifact tests in internal/apiv2 pass, and make verify-apiv2-contract finds no unapproved breaking change.
  • Fails on base: TestCommittedArtifactPassesLint run against main's openapi.json fails on exactly AdminItemMetadataUpdate.status and ProfileUpdate.max_playback_quality, and passes on this head. A scan of the whole document, including path-level schemas, finds only the withheld DownloadSubscriptionPatchBody.quality left. The issue's Draft 2020-12 validator check now accepts null on both fixed members.

Validated features: the board lookup was unavailable here. Judged from the source, no passed case is reachable: only the committed document changes, and request handling is the same.

User manual: unaffected. The developer API page tells readers to download /api/v2/openapi.json and doesn't describe enum shapes.

Apple/Android: no follow-up needed. The request contract only widens to accept what the server already accepted, and no first-party client depends on the old enum.

Merge order: this PR goes first, then #3535, which deletes NullEnumWithheld.

Fit: 9/10 · Readiness: 9/10 — ready

  • Fit: it fixes a real /api/v2 contract defect before the 1.0 lock, at the generator rather than per type, and adds a lint rule so the mismatch can't come back. It adds no new API surface.
  • Readiness: the approach holds up against Huma's validator and the handlers, the lint gate fails on the old document and passes on this one, and CI is green.

🤖 Claude Code (claude-opus-5-5)

@Quick104
Quick104 merged commit 6685aab into Silo-Server:main Nov 9, 2026
28 checks passed
Quick104 added a commit to blurbery/silo-server that referenced this pull request Nov 13, 2026
…patch-nullability

Silo-Server#3534 merged with its own NullEnumWithheld table, its lint branch, and a
check that each entry names a member. This branch removes the table, so
the conflicts resolve to this branch's side and the entry check goes too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority. triaged High-confidence review completed; does not mean fixed, validated, or accepted for release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] v2 OpenAPI rejects null on nullable enum request fields

2 participants