Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
The generated client
Read this when a test needs an endpoint the client does not have.
Every call goes through clients/api. A route the client cannot reach is missing an
operationId; fix the router, not the test.
clients/api is a Go module of its own, required from tests/go.mod through a replace
to the folder. That keeps the generated code out of ./..., so lint, vet and test do not
analyse it; the suites still compile against it. A new import in the generated code goes in
clients/api/go.mod (go mod tidy there), at the version tests/go.mod already uses.
Adding an endpoint
- Add the
operationIdtoinclude-operation-idsinclients/api/oapi-codegen.yaml. - Regenerate against a non-production instance:
INFISICAL_OPENAPI_URL=http://localhost:8080 make generate-client
The full spec is served only when NODE_ENV is not production and
OPENAPI_FULL_SPEC=true. The harness container runs in production mode, so generating
against it silently drops operations. Use the dev stack, or a throwaway container from
the harness image with NODE_ENV=development.
Unions
- Union request bodies. oapi-codegen declares the body as a defined type, which does
not inherit
MarshalJSON, so it serialises as{}. Build the union,json.Marshalit, and post with...WithBodyWithResponse. A union field inside an ordinary struct is fine. - Union responses. A response that can take more than one shape is generated as a
union with one
As…N()method per branch. Those methods onlyjson.Unmarshal, so every one of them succeeds whichever branch the server sent, and the wrong one hands back zero values instead of an error. After unwrapping, require a field that only the expected branch carries before trusting the result.
When the generated code does not compile
Some valid specs trip oapi-codegen bugs. The project permission schema is one: each rule's
action is "one action or a list of actions", and v2.8.0 names the list type and its item
type the same, so createProjectRole generates duplicate declarations.
Patch the spec before generation in clients/api/overlay.yaml
(OpenAPI Overlay), not the backend:
the spec is correct, and every Node API consumer reads it.
- Narrow the action to the schema that fails. The existing one replaces only the
createProjectRolebody's permission items with a plain object, and the suite sends rules as JSON (fixture.Permissioninfixture/role.go). - Overlays are strict: an action whose target matches nothing fails generation, so a renamed route shows up instead of silently undoing the patch.
- Remove the action once an oapi-codegen release fixes the bug.
Redirects and unauthenticated routes
Clients follow redirects by default. When the redirect is the outcome, such as an SSO start or a SAML ACS answer, opt in to receiving it:
browser := tn.Anonymous(t, infisical.NoRedirects()) // no token, tenant's rate-limit bucket
res, _ := browser.RedirectSamlByOrgSlugWithResponse(ctx, tn.OrgSlug, nil)
res.HTTPResponse.Header.Get("Location")
res.HTTPResponse.Cookies()
tn.Client(t, token, infisical.NoRedirects()) does the same for a principal. Send a
cookie back with a per-call request editor rather than a cookie jar.