GenerateContext
GenerateContext is an internal object controlling the generate phase. It provides access to schema data and settings inputs. It also receives generated code and writes to File objects.
Properties
| Property | Type | Description |
|---|---|---|
| oasDocument | OasDocument | Document representing the OpenAPI schema input |
| logger | Logger | Deno Logger for logging messages |
Methods
createAndRegisterDefinition
Generates a TypeSystemValue from schema using schemaToValueFn and creates a new Definition using the provided identifier. It then registers the new definition in File object at destinationPath.
If a definition with the name provided by identifier already exists at destinationPath, the existing definition will be retrieved and returned instead of creating a new one.
context.createAndRegisterDefinition({schema,identifier,destinationPath,schemaToValueFn})
Parameters
| Property | Type | Description |
|---|---|---|
| schema | SchemaType | Input schema which schemaToValueFn will convert to a TypeSystemValue |
| identifier | Identifier | Identifier representing a variable or type declaration |
| destinationPath | string | Path to the file where the generated code will be written. |
| schemaToValueFn | (schema: SchemaType) => TypeSystemValue | Function that takes a SchemaType object and returns a TypeSystemValue value. |
Return value
A Definition object with the output of schemaToValueFn function assigned to its value property.
defineAndRegister
Creates a new Definition using the provided identifier and registers it in File object at destinationPath.
If a definition with the name provided by identifier already exists at destinationPath, the existing definition will be retrieved and returned instead of creating a new one.
context.defineAndRegister({identifier,value,destinationPath,})
Parameters
| Property | Type | Description |
|---|---|---|
| identifier | Identifier | Identifier representing a variable or type declaration |
| value | Stringable | Stringable value |
| destinationPath | string | File path for the generated code |
Return value
A Definition object with the provided value assigned to its value property.
register
Insert supplied imports and definitions into File at destinationPath.
If an import from a specified module already exists in the file, the import names are appended to the existing module.
Any definitions with with a name that has already been registered at destinationPath will be not be added.
context.register({ imports, definitions })
Parameters
| Property | Type | Description |
|---|---|---|
| imports | Record<string, ImportName[]> | undefined | An optional object where each key is a module name and value is an array of ImportName objects. |
| definitions | Definition[] | undefined | An optional array of Definition objects |
Return value
Void
insertOperation
Transforms an operation into a Definition using insertable and registers it.
If a Definition with same name already exists at same path, it will be reused.
If Definition is declared outside of destinationPath, it will also get imported to destinationPath.
context.insertOperation({insertable,operation,generation,destinationPath,})
Parameters
| Property | Type | Description |
|---|---|---|
| insertable | OperationInsertable | OperationInsertable that converts an Operation to code. |
| operation | OasOperation | Object representing the OpenAPI operation |
| generation | 'regular' | 'force' | undefined | Optional flag to force generation even if it is not selected. This option is used internally to generate dependency code. |
| destinationPath | string | Path to the file where the generated code is used. |
Return value
A new Inserted object.
insertModel
Looks up model by refName, transforms it into a Definition using insertable and registers it.
If a Definition with same name already exists at same path, it will be reused.
If Definition is declared outside of destinationPath, it will also get imported to destinationPath.
context.insertModel({insertable,refName,generation,destinationPath})
Parameters
| Property | Type | Description |
|---|---|---|
| insertable | ModelInsertable | ModelInsertable that converts an Model to code. |
| refName | RefName | RefName of the model to transform and insert. |
| generation | 'regular' | 'force' | undefined | Optional flag to force generation even if it is not selected. This option is used internally to generate dependency code. |
| destinationPath | string | Path to the file where the generated code is used. |
Return value
A new Inserted object.
toOperationContentSettings
Creates a new ContentSettings object from settings loaded at runtime and static config methods on insertable object.
context.toOperationContentSettings({ operation, insertable })
Parameters
| Property | Type | Description |
|---|---|---|
| operation | OasOperation | Object representing the OpenAPI operation |
| insertable | OperationInsertable | OperationInsertable that converts an OasOperation to code. |
Return value
A new ContentSettings object.
toModelContentSettings
Creates a new ContentSettings object from settings loaded at runtime and static config methods on insertable object.
context.toModelContentSettings({ refName, insertable })
Parameters
| Property | Type | Description |
|---|---|---|
| refName | RefName | RefName of the model to transform and insert. |
| insertable | ModelInsertable | ModelInsertable that converts an Model to code. |
Return value
A new ContentSettings object.
toGatewayContentSettings
Creates a new ContentSettings object from settings loaded at runtime and static config methods on gateway object.
context.toGatewayContentSettings(gateway)
Parameters
| Property | Type | Description |
|---|---|---|
| gateway | `OperationGateway | ModelGateway` |
Return value
A new ContentSettings object.
resolveSchemaRefOnce
Look up an OasSchema reference by refName and return its value.
context.resolveSchemaRefOnce( refName )
Parameters
| Property | Type | Description |
|---|---|---|
| refName | RefName | RefName of the schema to resolve |
Throws if schema with refName is not found.
Return value
findDefinition
Look up a Definition by name at exportPath.
context.findDefinition({ name, exportPath })
Parameters
| Property | Type | Description |
|---|---|---|
| name | string | Name of the definition to find |
| exportPath | string | Path to the file where the definition is declared |
Return value
A Definition object or undefined if not found.