Generated files
Know which generated paths and names you can import, and which files to ignore.
Public paths
| Path | What it holds | Stable |
|---|---|---|
sdk/index.js | The client, its types and the data types | Yes |
sdk/operations/<name>.js | One operation factory per endpoint | Yes |
The SDK folder is the sdk output that you configure. Import only from the paths above. Your application code never imports generated model files: model classes extend model<T>() from @exprtlabs/golem/model, and build tools wire the generated codecs inside model.output (default .golem/models/).
- An SDK has no model classes in either mode. Its data types are types.
- A
standaloneSDK also holds a copy of the golem runtime that it uses, its conversions, and split tree-shakable validators (validators/_shared.generated.tsplus onevalidators/<operation>.generated.tsper operation). Do not import them directly. - A
golemmode SDK holds no checks or conversions. The models job writes them to a file belowmodel.output, named after the SDK folder with.sdk.generated.tsat the end. Do not import it. - All generated model artifacts (local models, controller DTOs, shared models, golem-mode SDK codecs and
models.validators.generated.ts) live insidemodel.output(default.golem/models/) and are internal to Golem. Zero*.generated.tsfiles are written beside source files insrc/.
Ignore or commit generated files
Golem needs no generated file in git. golem build generates first, so a fresh clone builds with one command, and clean clones type-check without generating first because model classes extend model<T>(). You choose whether to commit SDK or OpenAPI outputs:
- Ignore them. Put
.golem/and any configured SDK or OpenAPI paths in.gitignore. Rungolem generateorgolem buildin CI. - Commit them. A review then shows the SDK or OpenAPI changes. Run
golem checkin CI, so that a stale generated file fails the run.
Put .golem/ in .gitignore in both cases. Because all model artifacts live under .golem/models/ by default, no *.generated.ts glob in src/ is needed:
.golem/
sdk/.golem/ holds Golem's state and default generated model files on your machine. Any run of golem generate, golem build or golem watch writes it again.
Add every other generated path by name: the OpenAPI document that a docs job writes, and the files of a job from another package. A tool that imports such a file needs it generated first, so run golem generate before it.
The OpenAPI document of a docs job is a generated file. When you ignore it, it reaches the projects that read it through a run of the project that owns it:
golem generateorgolem buildin the owning project writes the document again.- A project that reads the document sets it as the
inputof an SDK job. Rungolem generatein the owning project first (SDK types in your models). In onegolem.yaml, an SDK job that reads the document of a docs job needs no first run. - In CI, run
golem generateorgolem buildin the owning project before the steps of a project that reads the document. golem checkfails when the document is missing or differs from the document that the docs job writes. It writes nothing (check).
Default locations
| Output | Location |
|---|---|
| Model files | .golem/models/, below the folder of golem.yaml |
| OpenAPI document and SDK | The paths you configure |
model.output overrides the model location.
Generated names
No generated base class is emitted. Your class links to its IModel declaration through extends model<T>() from @exprtlabs/golem/model and can have any name. For IModel types, use WireFormat<T> from @exprtlabs/golem/serde and ModelInit<T> from @exprtlabs/golem/model.
Inside model.output (default .golem/models/), Golem writes internal codec files for each model source and controller DTO. For IObject declarations, the generated file still emits <Alias>Fields, <Alias>Init and <Alias>JSON, along with internal codec functions. Exports that start with __golem are not part of the public API.
The models job skips a discovered model file that has no IModel or IObject alias. A file that model.sources names is never skipped (rules).
The first line of a generated model file names the version of golem that wrote it, for example /* Generated by @exprtlabs/golem-model <version>. Do not edit. */.
Generated SDK names
An SDK job writes these names for each schema in components.schemas. The table uses the schema Money and the operation createCharge. Another schema or operation gives the same names with its own name.
| What | Name | Notes |
|---|---|---|
| Data type | Money | A plain type. A date or date-time field has the type Date or a Temporal type, as dates sets. Responses carry these converted values. |
| Request type and response type | InputSchemas.Money, OutputSchemas.Money | The type as a request takes it and as a response returns it. They differ when readOnly or writeOnly fields exist. |
| Operation input | CreateChargeOperationInput | The argument of execute: path, query, header, cookie and body. |
| Operation result | CreateChargeOperationHttpResponse | The union of the declared responses. |
| Operation bodies | CreateChargeOperationSuccessBody, CreateChargeOperationErrorBody | The bodies of the success and the error responses. |
| Client | ProviderClient, ProviderClientOptions | The prefix is the name of the job. |
| Undeclared response | isProviderUndeclaredResponseError(error) | A type guard for an undeclared status or media type. |
The rules for the names:
- The name is the schema key, in PascalCase. Each word starts with a capital letter. A character that is not a letter, a digit,
_or$starts a new word, and so does a capital after a lowercase letter or a digit.chargegivesCharge,Foo-BargivesFooBar, andpaymentMethodgivesPaymentMethod.TMoneystaysTMoney. - A docs job names a schema after its model (component names).
type TMoney = IModel<…>with no class gives the schemaTMoney. - An SDK writes no model class, no
FieldsorInittype and noparse,stringify,validate,assert,toWireFormatorfromWireFormatfunction for a schema. The client converts and checks by itself. A class is your own model over the type (SDK types in your models).
Two schemas that give one name stop generation with a generated name collision error. The schemas Foo-Bar and Foo.Bar both give FooBar. The error names both schemas with the place of each in the document. Rename one schema in the document.
The diagnostics for these names:
- OPENAPI_DISCRIMINATOR_IMPLICIT_VALUE: a variant with no
mappingentry is selected by its schema name, not by its generated name.
Call operations with these names in Call operations. Use the data types as the field types of your own models in SDK types in your models.
Derived type names
A type built from a model, such as Omit<TMerchant, 'id'>, gets a schema name from its shape. Names are stable across runs.
| Type | Name |
|---|---|
Omit<TMerchant, 'id'> | TMerchantOmitId |
Pick<TMerchant, 'name' | 'id'> | TMerchantPickIdName |
Partial<Omit<TMerchant, 'id'>> | TMerchantOmitIdPartial |
TMerchant & TMoney | TMerchantAndTMoney |
The billing property of TPayment | TPaymentBilling |
The first matching rule gives the name:
- An intersection of named models. The sorted names join with
And. - A type alias that names the type, such as
type TBilling = Omit<TMerchant, 'id'>, which givesTBilling. The alias name is used as written. The alias needs no type parameters, must be declared in your own source rather than a.d.tsfile, and must have an ASCII identifier name. - A type that holds itself, such as
interface Tree { kids: Tree[] }or a class that lists its own kind. It takes the name of its interface, class or type alias, and its inner uses are references to that schema. A name that is not an ASCII identifier gives the type the name that rule 5 gives at its first use. - A named model wrapped in up to three levels of
Pick,Omit,Partial,RequiredandReadonly, each key list with at most three string-literal keys. Keys are sorted and written in PascalCase, innermost wrapper first. - Anything else: the owner plus the property, such as
TPayment.billinggivingTPaymentBilling. The owner of a model field is the model. The owner of a controller parameter is the controller class name without a trailingController, the method name, andBodyorQuery, such asPaymentsCreateBodyforPaymentsController.create. Other parameters use the parameter name instead. The owner of a controller response ends inResponse. Underscores and other characters outside letters and digits are dropped and the next letter is capitalized, soOrder_V2becomesOrderV2. A property name that contains a non-ASCII character gives the partField, such asOrderField. An owner name that contains a non-ASCII character, or does not start with a letter after cleanup, becomesModel, such asModelShape.
When the members of a union fall back to the owner plus the property, each member adds a part:
| Member | Name part |
|---|---|
| Every member has a string-literal property, and the values stay different | The PascalCase value of that property, such as TOrderEitherCard. If several properties qualify, the first in code-unit order wins. |
| No such property | The position of the member in the union as written, such as TOrderEither1. |
| A member that rules 1 to 3 name | It keeps that name. |
A union written through a type alias counts the alias's members in place.
Non-default settings, from the model option or from golem.yaml, add suffixes in this order:
| Suffix | Setting |
|---|---|
Loose | exact: false |
Any | allowAny: true |
Wire | The JSON form |
A docs job always reads the types that a signature spells out, such as an inline body, with exact: false, whatever exact says in golem.yaml. Their derived names end in Loose, such as PaymentsCreateBodyMerchantLoose for the merchant field of an inline body. A model that a signature names keeps its own exact and its own name.
Equal shapes from different expressions merge into one schema. The alphabetically first name stays.
Two different shapes that get the same name fail generation with RUNM1059, as does a derived name that equals a model name. The message names both source locations. Declare a named type alias to choose the name.
Runtime version
- Rule: Install
@exprtlabs/golemat the exact version of each built-in generator package that the configuration uses. Generated files import runtime entries that change with the version. A package from another author keeps its own version and is not compared. A standalone SDK runs with the runtime it carries, so its run time needs no version match. - Check:
generate,check,exec,watchandbuildcompare the installed@exprtlabs/golemwith@exprtlabs/golem-model,@exprtlabs/golem-openapi-tsand@exprtlabs/golem-ts-openapi. They fail before they write when a version differs. The message names both packages and versions and gives thenpm install -Dcommand that aligns the generator.
