Skip to content

fix(storage): document 200 responses for vector bucket CRUD endpoints - #1270

Open
grdsdev wants to merge 3 commits into
masterfrom
feat/vector-bucket-openapi
Open

fix(storage): document 200 responses for vector bucket CRUD endpoints#1270
grdsdev wants to merge 3 commits into
masterfrom
feat/vector-bucket-openapi

Conversation

@grdsdev

@grdsdev grdsdev commented Jul 28, 2026

Copy link
Copy Markdown

Context

The SDK team is starting to use the generated OpenAPI spec to generate idiomatic API clients for the Supabase SDKs. We're starting with vector buckets for testing. This PR is the first of several that will make the fastify-generated OpenAPI spec ready for client generation, split by route family to keep each one reviewable.

Summary

First slice of #1215 (too large to review as one PR), split by route family. This PR covers only the vector bucket routes.

  • Adds vectorBucketSchema, getVectorBucketResponseSchema, listVectorBucketsResponseSchema (mirroring bucketSchema/objectSchema), and wires them into create-bucket/delete-bucket/get-bucket/list-buckets so the exported spec has success schemas for the vector CRUD endpoints, not just error responses.
  • Adds src/http/routes/openapi-transform.ts: derives stable operationIds from each route's existing config.operation, names swagger components by $id instead of def-N, folds duplicate trailing-slash paths, and documents a generic 4xx (doc-only, covering 403 etc.) for any route without one. Prerequisite infra for generating a usable client from any route family, starting here with vector.

Deferred to follow-up PRs: bucket/object/iceberg/render/tus/cdn/health route documentation, error-handler.ts formatter support, apikey.ts, typespec tooling additions.

Test plan

  • tsc -noEmit — no errors
  • biome check on touched files — clean
  • vitest run on openapi-transform.test.ts — 5/5 passing

The vector bucket routes (create/get/list/delete) only ever documented
error responses, so the exported OpenAPI spec had no success schema at
all for them - unusable for SDK generation. Adds a vectorBucketSchema
component (mirroring bucketSchema/objectSchema) plus response wrappers
for get/list, and explicit `type: 'null'` 200s for the void
create/delete responses so generators don't try to decode an empty
body as JSON.

Also wires createOpenApiTransform/dedupeTrailingSlashPaths/
nameSchemaByDollarId into the swagger build (assigns stable
operationIds from each route's config.operation, names swagger
components by $id, and folds duplicate trailing-slash paths), and
documents the 403 response every JWT-guarded route (including vector)
can return.

First slice of a larger OpenAPI/SDK-generation PR, split up by route
family to keep review scoped.
@grdsdev
grdsdev requested a review from a team as a code owner July 28, 2026 09:13
@coveralls

coveralls commented Jul 28, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 30361736315

Coverage decreased (-21.1%) to 59.184%

Details

  • Coverage decreased (-21.1%) from the base build.
  • Patch coverage: 64 uncovered changes across 2 files (10 of 74 lines covered, 13.51%).
  • 2446 coverage regressions across 105 files.

Uncovered Changes

File Changed Covered %
src/http/routes/openapi-transform.ts 66 4 6.06%
src/app.ts 5 3 60.0%
Total (3 files) 74 10 13.51%

Coverage Regressions

2446 previously-covered lines in 105 files lost coverage.

Top 10 Files by Coverage Loss Lines Losing Coverage Coverage
src/http/routes/admin/pprof.ts 156 3.7%
src/storage/renderer/image.ts 156 31.2%
src/internal/monitoring/pprof/runtime.ts 130 0.98%
src/storage/protocols/iceberg/catalog/rest-catalog-client.ts 128 2.41%
src/internal/streams/hash-stream.ts 108 0.0%
src/internal/database/migrations/migrate.ts 104 38.39%
src/storage/backend/file.ts 95 16.04%
src/internal/monitoring/pprof/profile.ts 82 0.0%
src/internal/concurrency/async-abort-controller.ts 73 1.64%
src/internal/queue/queue.ts 71 1.33%

Coverage Stats

Coverage Status
Relevant Lines: 12049
Covered Lines: 7648
Line Coverage: 63.47%
Relevant Branches: 7083
Covered Branches: 3675
Branch Coverage: 51.88%
Branches in Coverage %: Yes
Coverage Strength: 363.6 hits per line

💛 - Coveralls

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Beyond the inline finding, I also checked vectorBucketSchema's use of the OpenAPI-style nullable: true keyword on creationTime (rather than the type: ['integer', 'null'] / anyOf pattern used everywhere else in src/storage/schemas) — it's a docs-only response schema and AJV ignores the unrecognized nullable keyword rather than erroring, so it doesn't break validation, just an inconsistency worth normalizing at some point.

Extended reasoning...

Confirmed via grep that every other nullable field in src/storage/schemas (bucket.ts, object.ts, upload.ts, multipart.ts) uses type: [x, 'null'] or anyOf, never the OpenAPI 3.0 'nullable' keyword. Since this schema is only used for response documentation/serialization (not request validation) and AJV in this codebase's default config doesn't run in strict mode that would throw on unknown keywords, this doesn't cause a functional bug — just a style inconsistency, not delaying approval on its own.

Comment thread src/http/plugins/jwt.ts Outdated
The onRoute hook was mutating routeOptions.schema.response directly,
which Fastify compiles into a real fast-json-stringify serializer
independent of docs generation. Iceberg's routes use a custom error
formatter ({ error: { message, type, code } }, no top-level
statusCode/message/code), so any 403 there (wrong-role JWT) would fail
serialization against errorSchema's required fields and come back as
a 500 instead. openapi-transform.ts's defaultErrorResponse already
documents a generic 4xx (covering 403) doc-only for every route, so no
replacement is needed.
* leak collisions into each other when generated in the same process (see export-docs.ts).
*/
export function createOpenApiTransform() {
const seenIds = new Set<string>()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes ordering important so maintenance problem. If we change route ordering in a file, it will break SDKs. I would suggest adding explicit config directly to routes for documentation and validate for uniqueness. Auto generated head routes could receive Head suffix

config: {
  operation: ROUTE_OPERATIONS.GET_AUTH_OBJECT,
	openapiOperation: "yourid"
}

Comment thread src/http/routes/openapi-transform.ts Outdated
metadata: { type: 'string' },
file: { type: 'string', contentEncoding: 'binary' },
},
required: ['cacheControl', 'file'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cacheControl isn't required, defaults to no-cache

type: 'object',
properties: {
cacheControl: { type: 'string' },
metadata: { type: 'string' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it also accepts userMetadata and contentType

… fields

- operationId generation no longer silently resolves collisions by
  registration order. Routes can now set config.operationId to pin an
  explicit id; exposeHeadRoutes-derived HEAD routes get a deterministic
  Head suffix; any other collision throws instead of picking a winner
  based on file order, since that would make generated SDK method names
  depend on ordering that has nothing to do with the API contract.
- documentMultipartUploadBody no longer marks cacheControl as required -
  the uploader defaults it to 'no-cache' when omitted.
* regression, not a docs improvement. Document the multipart shape here instead, transform-only,
* where - like `defaultErrorResponse` above - it can never reach live request validation.
*/
function documentMultipartUploadBody(schema: FastifySchema, route: RouteOptions): FastifySchema {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we also support raw uploads so we need to document it as well?

I would suggest dropping multipart from this PR and could be added separately in a follow up

properties: {
cacheControl: { type: 'string' },
metadata: { type: 'string' },
file: { type: 'string', contentEncoding: 'binary' },

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
file: { type: 'string', contentEncoding: 'binary' },
file: { type: 'string', format: 'binary' },

https://spec.openapis.org/oas/v3.0.3#data-types

* those ad-hoc replies (fast-json-stringify errors on a missing required property rather
* than dropping it). A transform can't affect request handling, so it can't cause that.
*/
function defaultErrorResponse(schema: FastifySchema | undefined): FastifySchema {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is not aligned with iceberg

setErrorHandler(fastify, {

} as RouteOptions
}

describe('documentMultipartUploadBody (via transformOpenApiSchema)', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would be nice to see a few tests vector response and error envelope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants