What Studio writes into your project when it imports an API, updates one or removes one, and how it formats it. Importing itself is on Import an API.
Which files Studio changes
Studio changes an import's files — when it writes the import, updates it, adds or removes endpoints, or removes the import — only inside the import's folder, or, removing an import Studio 0.3.0 bound as eval, arguments, undefined or globalThis, inside the folder 0.3.0 wrote it into, and decides for each file by who it belongs to. It records every file it writes, with a hash of its content, in .courier/imports-state.json, and starts each with two lines that say so:
// @courier-generated {"import":"pets","sha256":"3f2a…"}
// Courier Studio wrote this file. It keeps your edits to endpoints when it updates the file.- A file Studio wrote and nobody changed is replaced or removed as the change needs. A file whose first line names the import, but which Studio has no record of — in a fresh clone, say, where
.courier/is not checked in — is treated the same way when it is replaced; removing one waits for you, offered ticked. - A file you changed keeps your edits to endpoints when Studio updates it. A file Studio would replace whole, or remove, waits for you instead — and so does a file whose endpoints Studio cannot read as code, one saved mid-edit say, since it cannot keep your edits in it.
- A file Studio did not write — one you added to the folder, or one its first line says Studio wrote for another import — is never removed, and replacing it waits for you.
- A symbolic link or a folder where a file should be is never written through, replaced or removed, and nothing is written through a folder link that leads out of the project. A change that would write one of them is refused until you move it out of the way.
- A group Studio names otherwise than the Studio that wrote it —
evalGroupwhere 0.3.0 named a groupeval, and so forarguments,undefinedandglobalThis, or after its path where its tag spells no name — takes its new name the next time the import is written, updated or managed. Manage keeps its endpoints, reading the group's old file as the group it is now. That file then belongs to a group the specification no longer has, and goes as such a file does: at once when Studio wrote it and nobody changed it, once you allow it when you did. What you changed in it is not carried into the group's new file; the copy in.courier/backups/keeps it.
When a change holds steps that wait for you, Studio shows them with the rest of the change, each with its own checkbox, and takes only the steps you tick; a file left unticked stays as it is, and so does every file it imports: Studio never removes a file that a file staying in the import's folder imports, and the message after the change counts it among the files left as they were. An update, a change to endpoints and a removal are applied only as you previewed them: if a file changed in the meantime, Studio shows the change as it now stands instead. A write needs no preview, and asks only when a step waits for you.
Every change is applied all at once. Studio keeps a copy of each file it replaces or removes in .courier/backups/<change>/, and keeps the copies of the last 20 changes that made any. A change that Studio is stopped in the middle of is undone the next time it starts, file by file, except for a file changed since, which is left as it is. A change another Studio on the same project is still making is left to that Studio. Studio tries such an undo once: its copy of each file it could not restore is kept, whatever the limit, and Studio names those files at every start until you delete their folder in .courier/backups/. Studio undoes only what its own records name: a .courier folder that came with the project cannot make it touch other files. Removing an import takes it out of courier.config.ts too. Under the box Also remove … from courier.config.ts, ticked, the dialog shows the lines Studio removes: the import's sources entry with the import only that entry used, and its imports entry — an imports left empty goes, a sources left empty reads {}. Where the config takes its sources from a module of the project, the box reads Also remove … from lib/sources.ts and courier.config.ts, and the dialog shows the lines each file loses: the sources entry and its import come out of that module, the imports entry out of the config, both files changed or neither. Studio makes that change before any file goes, while the files are still there: it loads the config without the import and checks that the config no longer declares it nor imports any of the files that go, and only then removes them. A config — or that module — saved after the dialog was shown, or a change Studio could not make — the config would still import one of the files, say — removes nothing, and the dialog shows the removal again with the reason, the box unticked when the change failed. Untick the box to leave the config as it is; then, and whenever Studio cannot change the config — it does not load, it builds sources in a way Studio cannot change, or the browser is not on the machine Studio runs on — the dialog warns when the config imports one of the files that go, since the config stops loading until you remove that import, and reminds you to remove the import's entry under imports too, since Studio goes on checking the import for updates while the config declares it.
A request Studio refuses changes nothing. It is answered with { error } — 404 for an import Studio does not know, 400 for a body it cannot read — and, for the refusals below, with a code and, where there is one, the plan as it stands. A change that needs courier.config to load is refused as How Studio loads the project describes.
| Code | Status | Meaning |
|---|---|---|
NEEDS_CONFIRMATION | 409 | Some steps wait for you; send the request again with the plan's planDigest and the paths you allow in confirm. |
PLAN_NOT_SEEN | 409 | An update, a change to endpoints or a removal quoted no plan; preview it first. |
PLAN_STALE | 409 | The plan is not the one you saw: a file it rests on changed, or the import's declaration, the change asked for or the project's formatter configuration did. |
CONFIG_STALE | 409 | A removal quoted, as configBaseHash, a change to courier.config.ts planned against the config as it was — and the module it takes its sources from, when the change writes that too: one of them was saved since the preview. Nothing was removed. |
CONFIG_NOT_CHANGED | 409 | Studio could not take the import out of courier.config.ts — the config did not load without it, still imported a file the removal takes, or could not be written — and left it as it was. Nothing was removed. |
TARGET_BLOCKED | 409 | A file the change writes is a symbolic link or not a file. |
CONFIRMATION_NOT_IN_PLAN | 400 | confirm names a path the plan does not ask about. |
DECLARATION_MISMATCH | 409 | imports declares the import in another folder, or with another type, validation, grouping, client or other generation option, than the wizard's options; the message names each one. An update and Manage generate as declared, so an import written otherwise would change layout at the next of them. |
DIR_OVERLAP | 409 | Another import owns the folder, or one inside or around it. |
NAME_TAKEN | 409 | sources declares another API under the import's name. |
IMPORT_RENAMED | 409 | The import's files are still where Studio 0.3.0 bound it as eval, arguments, undefined or globalThis, which this release binds as a reserved word's is, evalGroup in eval-group/. Studio does not move an import's files: remove the import, which takes them from that folder, then import it again; where both folders hold its files, delete the one you do not keep first. |
FILE_NOT_RECOGNIZED | 409 | A file Studio would add endpoints to no longer shows where its endpoints are. |
ENDPOINT_OUTSIDE_PREFIX | 409 | An endpoint you add would call a URL the prefix its group file declares cannot reach, or Studio cannot read that prefix; add it by hand, or import the API again under the same name. An endpoint the file's prefix can reach is written relative to it, whatever prefix the specification gives the group. |
IMPORTS_STATE_UNSAFE | 409 | Studio cannot read .courier/imports-state.json, or keep a copy of it, so saving it would lose the other imports' records. |
COURIER_DIR_UNSAFE | 409 | .courier, or a folder Studio keeps in it, is a symbolic link or not a folder; Studio keeps nothing there. |
INVALID_IMPORT | 400 | The output directory, the source name or a group's name is one Studio does not write to: outside the project, in .git, node_modules or .courier, or a name Windows treats differently. |
PATH_OUTSIDE_PROJECT | 400 | A path leads out of the project. |
SPEC_NOT_GENERATED | 400 | Studio could not generate code from the specification sent. |
INVALID_SPEC | 400 | The specification sent holds a value Studio cannot write into the code it generates: a name that is not an identifier or is one the generated code keeps for itself, an endpoint named so that its client could not call it, two groups of one name or written to one folder, a group whose parent names no group or whose chain of parents loops, a bound that is not a finite number, a pattern whose literal would not end where it does, or a node that is not an object or a list. The message names where it is. |
SPEC_TOO_LARGE | 413 | The specification is larger than 64 MB once parsed: Studio takes the parsed specification back when it generates, writes, updates or manages an import, and a request body may be at most 64 MB. |
SPEC_WORK_LIMIT | 413 | Reading the specification, generating its code or comparing it took longer, or more memory, than Studio gives such work; see Specifications on a private network. |
STUDIO_BUSY | 503 | Studio already fetches, reads, generates or compares as much for pages without the token as it takes at once; try again in a moment. |
STUDIO_TOKEN_REQUIRED | 401 | The page has no token: it may not change the project, read a file or the code of it, preview a change to an import or to courier.config.ts, or check imports for updates. A visitor of a public demo is told what the demo does not do. |
STUDIO_DEMO_REFUSED | 403 | A visitor of a public demo asked Studio to read a specification from a file of the project. |
SPEC_UNREADABLE | 502 | The import's from answered with something that is not a specification Studio reads, such as a page. |
SPEC_PIN_MISMATCH | 409 | The specification's hash is not the one the import's pinHash names. |
IMPORT_TRANSFORM_FAILED | 400 | The import's transform threw, or returned something that is not a specification or one holding a value INVALID_SPEC describes; the message names where it is. What it threw is quoted as a load error quotes it: the environment's values masked, every credential cut. |
How Studio formats the files
Studio writes the files the way your project formats its code, and shows them that way before you apply the change:
- Biome, when a
biome.jsonorbiome.jsoncstands in the project or a folder above it, or itspackage.jsonlists@biomejs/biome: Studio runs the project's own Biome on each file — its native program, without the Node launcher — with your configuration: the formatter and the import sorting. Lint rules do not change the code. - ESLint, when an ESLint configuration stands there — an
eslint.config.*file, or for ESLint 8 an.eslintrcfile or aneslintConfigkey inpackage.json: Studio applies the fixes your rules offer, aseslint --fixdoes. A file your configuration ignores stays as it is. - Prettier, when a Prettier configuration stands there, or
package.jsonlistsprettieror has aprettierkey: Studio runs it last, alone or after Biome when Biome's formatter is off, reading.editorconfig,.prettierignoreand.gitignoreas Prettier's command line does. - None of them: the files are written as Studio generates them.
Studio loads ESLint and Prettier once, from your project, in processes of their own — up to three — and keeps them between changes, so a file takes milliseconds: Petstore's eight files take about 20 ms once the tools are loaded, GitHub's 89 under a second. A configuration you change is read on the next change, and the processes go after five idle minutes. A file goes through the tools again until a pass changes nothing.
A file you edited is formatted whole when Studio merges a change into it, as your editor would format it when you save it; a courier.mocks.ts Studio creates is formatted the same way. The change says which tools ran, with their versions. When a tool fails on a file — an ESLint configuration with no TypeScript parser cannot read TypeScript, say — the other tools still run on it, and the change says why; a tool the project configures but did not install is named the same way. A file no tool formats is still correct code.