···22"@hey-api/openapi-ts": patch
33---
4455-valibot: use `.strictObject()` instead of `.objectWithRest()` when additional properties are not allowed
55+**valibot**: use `.strictObject()` instead of `.objectWithRest()` when additional properties are not allowed
···11+import type ts from 'typescript';
22+13import { AttrTsDsl } from '../attr';
24import type { MaybeTsDsl, WithString } from '../base';
35import { CallTsDsl } from '../call';
4657export class AccessMixin {
68 /** Accesses a property on the current expression (e.g. `this.foo`). */
77- attr(this: MaybeTsDsl<WithString>, name: string | number): AttrTsDsl {
99+ attr(
1010+ this: MaybeTsDsl<WithString>,
1111+ name: WithString<ts.MemberName> | number,
1212+ ): AttrTsDsl {
813 return new AttrTsDsl(this, name);
914 }
1015 /** Calls the current expression as a function (e.g. `fn(arg1, arg2)`). */
···2233import type { TsDsl } from '../base';
4455+/**
66+ * Creates an accessor for adding TypeScript modifiers to a parent DSL node.
77+ *
88+ * @param parent - The parent DSL node to which modifiers will be added.
99+ * @returns An object with a `list` method that returns the collected modifiers.
1010+ */
511export function createModifierAccessor<Parent extends TsDsl>(parent: Parent) {
612 const modifiers: Array<ts.Modifier> = [];
7131414+ /**
1515+ * Adds a modifier of the specified kind to the modifiers list if the condition is true.
1616+ *
1717+ * @param kind - The syntax kind of the modifier to add.
1818+ * @param condition - Whether to add the modifier (default: true).
1919+ * @returns The parent DSL node for chaining.
2020+ */
821 function _m(kind: ts.ModifierSyntaxKind, condition = true): Parent {
922 if (condition) {
1023 modifiers.push(ts.factory.createModifier(kind));
···14271528 Object.assign(parent, { _m }); // attaches to parent
16293030+ /**
3131+ * Returns the list of collected modifiers.
3232+ *
3333+ * @returns Array of TypeScript modifiers.
3434+ */
1735 function list() {
1836 return modifiers;
1937 }
···2442type Target = object & {
2543 _m?(kind: ts.ModifierSyntaxKind, condition?: boolean): unknown;
2644};
4545+4646+/**
4747+ * Mixin that adds an `abstract` modifier to a node.
4848+ */
2749export class AbstractMixin {
5050+ /**
5151+ * Adds the `abstract` keyword modifier if the condition is true.
5252+ *
5353+ * @param condition - Whether to add the modifier (default: true).
5454+ * @returns The target object for chaining.
5555+ */
2856 abstract<T extends Target>(this: T, condition: boolean = true): T {
2957 return this._m!(ts.SyntaxKind.AbstractKeyword, condition) as T;
3058 }
3159}
6060+6161+/**
6262+ * Mixin that adds an `async` modifier to a node.
6363+ */
3264export class AsyncMixin {
6565+ /**
6666+ * Adds the `async` keyword modifier if the condition is true.
6767+ *
6868+ * @param condition - Whether to add the modifier (default: true).
6969+ * @returns The target object for chaining.
7070+ */
3371 async<T extends Target>(this: T, condition: boolean = true): T {
3472 return this._m!(ts.SyntaxKind.AsyncKeyword, condition) as T;
3573 }
3674}
7575+7676+/**
7777+ * Mixin that adds a `default` modifier to a node.
7878+ */
3779export class DefaultMixin {
8080+ /**
8181+ * Adds the `default` keyword modifier if the condition is true.
8282+ *
8383+ * @param condition - Whether to add the modifier (default: true).
8484+ * @returns The target object for chaining.
8585+ */
3886 default<T extends Target>(this: T, condition: boolean = true): T {
3987 return this._m!(ts.SyntaxKind.DefaultKeyword, condition) as T;
4088 }
4189}
9090+9191+/**
9292+ * Mixin that adds an `export` modifier to a node.
9393+ */
4294export class ExportMixin {
9595+ /**
9696+ * Adds the `export` keyword modifier if the condition is true.
9797+ *
9898+ * @param condition - Whether to add the modifier (default: true).
9999+ * @returns The target object for chaining.
100100+ */
43101 export<T extends Target>(this: T, condition: boolean = true): T {
44102 return this._m!(ts.SyntaxKind.ExportKeyword, condition) as T;
45103 }
46104}
105105+106106+/**
107107+ * Mixin that adds a `private` modifier to a node.
108108+ */
47109export class PrivateMixin {
110110+ /**
111111+ * Adds the `private` keyword modifier if the condition is true.
112112+ *
113113+ * @param condition - Whether to add the modifier (default: true).
114114+ * @returns The target object for chaining.
115115+ */
48116 private<T extends Target>(this: T, condition: boolean = true): T {
49117 return this._m!(ts.SyntaxKind.PrivateKeyword, condition) as T;
50118 }
51119}
120120+121121+/**
122122+ * Mixin that adds a `protected` modifier to a node.
123123+ */
52124export class ProtectedMixin {
125125+ /**
126126+ * Adds the `protected` keyword modifier if the condition is true.
127127+ *
128128+ * @param condition - Whether to add the modifier (default: true).
129129+ * @returns The target object for chaining.
130130+ */
53131 protected<T extends Target>(this: T, condition: boolean = true): T {
54132 return this._m!(ts.SyntaxKind.ProtectedKeyword, condition) as T;
55133 }
56134}
135135+136136+/**
137137+ * Mixin that adds a `public` modifier to a node.
138138+ */
57139export class PublicMixin {
140140+ /**
141141+ * Adds the `public` keyword modifier if the condition is true.
142142+ *
143143+ * @param condition - Whether to add the modifier (default: true).
144144+ * @returns The target object for chaining.
145145+ */
58146 public<T extends Target>(this: T, condition: boolean = true): T {
59147 return this._m!(ts.SyntaxKind.PublicKeyword, condition) as T;
60148 }
61149}
150150+151151+/**
152152+ * Mixin that adds a `readonly` modifier to a node.
153153+ */
62154export class ReadonlyMixin {
155155+ /**
156156+ * Adds the `readonly` keyword modifier if the condition is true.
157157+ *
158158+ * @param condition - Whether to add the modifier (default: true).
159159+ * @returns The target object for chaining.
160160+ */
63161 readonly<T extends Target>(this: T, condition: boolean = true): T {
64162 return this._m!(ts.SyntaxKind.ReadonlyKeyword, condition) as T;
65163 }
66164}
165165+166166+/**
167167+ * Mixin that adds a `static` modifier to a node.
168168+ */
67169export class StaticMixin {
170170+ /**
171171+ * Adds the `static` keyword modifier if the condition is true.
172172+ *
173173+ * @param condition - Whether to add the modifier (default: true).
174174+ * @returns The target object for chaining.
175175+ */
68176 static<T extends Target>(this: T, condition: boolean = true): T {
69177 return this._m!(ts.SyntaxKind.StaticKeyword, condition) as T;
70178 }
+9-1
packages/openapi-ts/src/ts-dsl/mixins/type.ts
···44import type { TypeInput } from '../type';
55import { TypeTsDsl } from '../type';
6677+export interface TypeAccessor<Parent extends TsDsl> {
88+ $render(): ts.TypeNode | undefined;
99+ fn(): ReturnType<typeof TypeTsDsl>;
1010+ fn(type: TypeInput): Parent;
1111+}
1212+713/** Provides `.type()`-like access with internal state management. */
88-export function createTypeAccessor<Parent extends TsDsl>(parent: Parent) {
1414+export function createTypeAccessor<Parent extends TsDsl>(
1515+ parent: Parent,
1616+): TypeAccessor<Parent> {
917 const $type = parent['$type'].bind(parent);
10181119 let _type: ReturnType<typeof TypeTsDsl> | undefined;
+5-5
packages/openapi-ts/src/ts-dsl/param.ts
···66import { DecoratorMixin } from './mixins/decorator';
77import { OptionalMixin } from './mixins/optional';
88import { PatternMixin } from './mixins/pattern';
99-import { createTypeAccessor } from './mixins/type';
99+import { createTypeAccessor, type TypeAccessor } from './mixins/type';
1010import { ValueMixin } from './mixins/value';
11111212export class ParamTsDsl extends TsDsl<ts.ParameterDeclaration> {
1313 private name?: string;
1414- private _type = createTypeAccessor(this);
1414+ private _type: TypeAccessor<ParamTsDsl> = createTypeAccessor(this);
1515+1616+ /** Sets the parameter's type. */
1717+ type: TypeAccessor<ParamTsDsl>['fn'] = this._type.fn;
15181619 constructor(
1720 name: string | ((p: ParamTsDsl) => void),
···2528 name(this);
2629 }
2730 }
2828-2929- /** Sets the parameter's type. */
3030- type = this._type.fn;
31313232 $render(): ts.ParameterDeclaration {
3333 const name = this.$pattern() ?? this.name;