# How a Specification Becomes Code

What an import makes of an OpenAPI, Swagger or Postman specification: the groups and their names, each operation and its parameters, the schemas and what they allow, and the folder of code it writes.

What Studio makes of a specification it imports, part by part. Importing one is on [Import an API](/docs/studio/import-api), and what the import writes beyond the API's own folder on [Files Studio Writes](/docs/studio/import-files).

## Groups and their names

- Endpoints are grouped by the specification's tags, by path, or not at all, with **Single file**. By path, an endpoint goes in the group its resource names: the first segment of its path after the ones every path shares above every operation — Stripe's `/v1`, an API served under `/api` — that names neither a version, such as `v2`, `v1beta1` or `2010-04-01`, nor a parameter. So Stripe's endpoints go in `customers`, `charges` and the rest of its 78 resources, while an API whose every path starts with `/settings`, one of them `/settings` itself, keeps them all in `settings`.
- A group takes its name from its tag, its Postman folder or, grouped by path, its segment, made an identifier: `pet store` is `petStore`, and `raw`, a name the client keeps for itself, is `rawGroup`. A tag or folder with no letter or digit Studio spells in Latin letters names its group after the last segment every path of the group shares, `users` for `/api/users` and `/api/users/{id}`, and a group named by neither is `group`. A name another group took gets a number, `pets2`, and a name is cut to 128 characters, its number included, the longest a folder's name is made from.
- An endpoint in no group sits in the API itself: an operation with no tag, a path no segment groups — the API's root `/`, or `/v1` alone — a request at a Postman collection's root, and with **Single file** every endpoint. `source.ts` holds it beside the groups, and the client calls it on itself: `client.health()`, beside `client.pets.list()`. The wizard and **Manage** list these endpoints at the top level; adding the first of them to an import gives its `source.ts` an `endpoints` object beside `groups`, and removing the last takes the object away again with what only it needed. A specification that tags none of its operations — Stripe's, say — is grouped by path unless your settings choose a single file: by tag, none of its endpoints would be in a group, which the wizard says when tag is chosen anyway.
- A tag that names a `parent`, as OpenAPI 3.2 allows, is imported as a group inside its parent tag's group: its own folder, listed under `groups` in the parent's file, its prefix after the parent's, so `client.billing.invoices.list()` reaches the path the specification gives. A tag only other tags sit under becomes a group of its own, and a parent the specification does not declare, or one that would put a tag under itself, is left out. **Manage** adds a new inner group to its parent's file and takes a removed one out of it; a group whose endpoints all go stays while groups sit inside it, and goes once they do.

## Operations

- Every operation whose verb the builder has is imported: GET, HEAD, OPTIONS, POST, PUT, PATCH, DELETE, and QUERY — OpenAPI 3.2's `query` operation, or a QUERY a specification lists under `additionalOperations`. An operation that reads is generated as a read, one addressed by a closure included. One the builder has no verb for — TRACE, or another verb under `additionalOperations` — is listed among the operations left out, with the reason, rather than dropped.
- Each endpoint keeps what its operation says it does — the summary, or the first paragraph of the description — as `.meta({ description: "…" })`, whether or not it becomes a doc comment too: a tool the project's [`agents` policy](/docs/agents/overview#what-agents-may-call) offers without `.agent()` describes itself to the model by it, and the OpenAPI written from the definition keeps it.
- An operation is called with its path and query parameters and its header parameters, beside its body: a header parameter is a variable under its own name, validated with the rest and sent as a request header by `headerVariablesMiddleware`. `Accept`, `Content-Type` and `Authorization` are not taken as parameters, as OpenAPI says — the client sets them — and neither is a header named like a path or query parameter of the same operation, nor one beside a multipart form taken as a `FormData`, which is the whole of what such a call is made with.
- A multipart operation whose schema names its fields is called with a record of them, beside its parameters, as a JSON body's fields are: a field that holds a file's bytes — `format: binary`, or OpenAPI 3.1's `contentMediaType` without a `contentEncoding` — is a `Blob`, and a list of them a `Blob[]`. Its closure sends the fields with [`multipartBody`](/docs/advanced/upload#an-api-that-takes-only-a-form), so the call is a form whether a file is among them or not, directly and through the proxy. One whose schema names no fields is called with a `FormData`, and so is one a field of which is named as a parameter: a file travels through the proxy in a field of the variables, so the fields cannot go under a key of their own.
- A colon a specification's path writes as text, as Google's do — `/v1/urlInspection/index:inspect`, `/v1/{name}:cancel` — is doubled in the endpoint the import writes, `index::inspect` and `:name::cancel`, so that the client sends it as written; a segment a Postman request starts with a colon is its path variable. Google's `{+name}`, whose value keeps its slashes, stays `{+name}` — `/v1/{+name}:cancel` is written `{+name}::cancel` — and a parameter that text follows at once, as `/items/{id}5`, is written in braces, `{id}5`, which end its name. Such a colon never makes an operation without an `operationId` a read of one record: `GET /v1/projects:search` is named `getAllProjectsSearch`, not `getById`.

## Schemas

- A schema with `readOnly` or `writeOnly` fields, itself or through a schema it refers to, is two types: the answer, `User`, without the fields only the client sends and with the ones the server sends as required as declared, and the input a request sends, `UserInput`, the other way round — named `UserInput2` when the specification has a schema called `UserInput`. A schema that is only ever answered has no input type.
- What a schema allows beyond its type — a string's `minLength`, `maxLength` and `pattern`; a number's `minimum`, `maximum`, exclusive bounds and whole `multipleOf`, and that an `integer` is whole; a list's `minItems` and `maxItems` — is checked on what a request sends, and never on what an answer carries: a validator that refuses what the API really sends is worse than none. A schema both sent and answered with such a constraint, itself or through a schema it refers to, is then two schemas in the same way: `Product` reads the answer and `ProductInput` checks the request. An operation without a body has its parameters validated when one of them carries such a constraint, and only typed otherwise. Left unchecked: `uniqueItems`, a `multipleOf` that is not a whole number, which floating point cannot check exactly, and a `pattern` JavaScript cannot compile.
- A field named like a member every object has — `constructor`, `toString`, `valueOf`, `__proto__` — is a field like any other. Every validation library read a `constructor`, `toString` or `valueOf` a value left out as `Object`'s own member and refused the value, and none checked a field `__proto__` — zod left it unchecked, and Valibot threw — so an object with such a field is checked through `_ownFields`, a function the module declares after its declaration: on a copy of the value's own fields, with no prototype, a field `__proto__` checked and kept as a field of its own. It is described as its fields are, a field `__proto__` among them, inside another schema too, where zod leaves one with a field `__proto__` unspecified; a Valibot one is described as far as the converter you pass `toOpenAPI` for Valibot can. An update and **Manage** carry the function with the code that calls it and take it out with the last call, and Contract Drift's fix and the Playground read an object through it, wherever it sits — the Playground starts a call with a field `__proto__` as a field of its own. An optional such field is typed with the member beside its own type, `string | Object["constructor"]`, as TypeScript reads `Object`'s members on every object.
- A schema composed with `allOf` is merged into one, the properties of every schema it names copied in. A composition that takes in the schema it sits in — a category's `parent` composed of the category and a `depth` — is declared as a schema of its own, named after where the specification writes it: the component and the path inside it, `CategoryParent`, `NodeChildrenItem` for the items of a node's `children`. It refers to itself, so each level of it is typed and checked alike.
- A schema only one group's endpoints use is declared in that group's folder. One that several groups use, or the API's own endpoints, is declared once, in the import's own `schemas.ts`, and each group imports it from there: declared in every group that used it, Stripe's schemas — nearly all of which refer to each other — came to 59 MB over its 78 resources; declared once, they are 4.7 MB, 1.5 MB of it the import's own `schemas.ts`, which Biome checks only with `files.maxSize` raised past its default of 1 MiB. Where each schema goes is decided over the whole specification, whatever you select, so endpoints added later find their schemas where the first write put them; a schema leaves the import's `schemas.ts` only once nothing left in the import uses it.

## The folder an import writes

- An import writes its folder under `outputDir`: `source.ts`, the API as the specification describes it — its own endpoints and its groups; `schemas.ts`, the schemas its own endpoints and several groups use; `index.ts`, the direct caller with the schemas and types, re-exported by name; `proxy.ts`, the proxy caller alone; and a folder for each group, with its endpoints and the schemas only it uses. Import the proxy caller in browser code from `proxy.ts`: it takes the source's routes from `@noverax/courier/routes`, which Courier's plugin for your build gives the page, and registers the config there — or, where the config keeps a [routes module](/docs/proxy-mode/expose#the-routes-as-a-file), from that module, which Courier writes from the endpoints marked `.expose()` — so the browser bundle holds no part of the source — not its upstream address, its middleware nor a schema — which importing it from `index.ts` would bring along with the direct caller and the schemas. `proxy.ts` takes the proxy caller from `@noverax/courier/client`, the page's entry, and `index.ts` the direct caller, the server's, from `@noverax/courier/server`: the same callers the root gives. Where a page alone loads the files — the package they go in is React or Vue that Vite builds, beside no server framework it runs with — `index.ts` takes a page's direct caller from `@noverax/courier/client` instead, so the page's bundle holds none of the server's part. Studio tells a server framework — NestJS, Fastify, Hono, Express, Koa, hapi, Elysia, h3 or Nitro — by the packages it lists, and one the package lists among its dev dependencies alone, an Express or a Koa for a mock, is none: the app it builds runs without it, and its page loads the files alone. An import with a proxy caller marks its API `expose: true` in `source.ts`, so a page may call each endpoint it generates; mark one `.expose(false)` to keep it to the server, and the routes module follows as the config loads, as it does when **Manage** adds or removes endpoints. Types are imported from `index.ts` with `import type`, which a bundle drops, and a page that takes a schema from it takes no caller with it: each caller Studio writes is marked pure, so a bundle leaves it out where nothing calls it, and the server's part with it.
- The generated code passes Biome's recommended rules, stricter ones and its import organizer as it is written, before any formatter runs: an import's `index.ts` re-exports each schema and type by name rather than with `export *`, a pattern is a regular expression literal, a file that imports only types imports them with `import type`, and imports, re-exports and the names in each come in the order the organizer keeps them. It compiles with `noUnusedLocals`, `verbatimModuleSyntax` and `exactOptionalPropertyTypes` on.
- The generated files are application code. A project that emits declarations compiles them, since every type their exports carry is one the packages export, but not one under `isolatedDeclarations`, which asks for a written type on every export: the type of a group or a source is the whole chain of its endpoints.
