这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/chilled-wolves-pump.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@hey-api/openapi-ts": patch
---

parser: merge `default` keyword with `$ref` in OpenAPI 3.1
**parser**: merge `default` keyword with `$ref` in OpenAPI 3.1
12 changes: 6 additions & 6 deletions packages/openapi-ts/src/plugins/@hey-api/sdk/shared/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,13 @@ export const generateClassSdk = ({
g
.$if(!plugin.config.instance, (g) => g.public().static())
.do(
plugin.config.instance
? $.return(
$.new(refChildClass.placeholder).args(
$.return(
plugin.config.instance
? $.new(refChildClass.placeholder).args(
$.object().prop('client', $('this').attr('client')),
),
)
: $.return(refChildClass.placeholder),
)
: refChildClass.placeholder,
),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const createQueryOptions = ({
.param(optionsParamName, (p) =>
p.optional(!isRequiredOptions).type(typeData),
)
.do($.return($(symbolQueryOptions.placeholder).call(queryOptionsObj))),
.do($(symbolQueryOptions.placeholder).call(queryOptionsObj).return()),
);
plugin.setSymbolValue(symbolQueryOptionsFn, statement);
};
22 changes: 10 additions & 12 deletions packages/openapi-ts/src/plugins/arktype/v2/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ export const createRequestValidatorV2 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr('parseAsync')
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr('parseAsync')
.call(dataParameterName)
.await()
.return(),
);
};

Expand All @@ -62,11 +61,10 @@ export const createResponseValidatorV2 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr('parseAsync')
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr('parseAsync')
.call(dataParameterName)
.await()
.return(),
);
};
8 changes: 4 additions & 4 deletions packages/openapi-ts/src/plugins/swr/v2/useSwr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export const createUseSwr = ({
)
.assign(
$.func().do(
$.return(
$(symbolUseSwr.placeholder).call(
$(symbolUseSwr.placeholder)
.call(
$.literal(operation.path),
$.func()
.async()
.do(...statements),
),
),
)
.return(),
),
);
plugin.setSymbolValue(symbolUseQueryFn, statement);
Expand Down
22 changes: 10 additions & 12 deletions packages/openapi-ts/src/plugins/valibot/v1/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ export const createRequestValidatorV1 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(v.placeholder)
.attr(identifiers.async.parseAsync)
.call($(symbol.placeholder), $(dataParameterName))
.await(),
),
$(v.placeholder)
.attr(identifiers.async.parseAsync)
.call(symbol.placeholder, dataParameterName)
.await()
.return(),
);
};

Expand All @@ -56,11 +55,10 @@ export const createResponseValidatorV1 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(v.placeholder)
.attr(identifiers.async.parseAsync)
.call($(symbol.placeholder), $(dataParameterName))
.await(),
),
$(v.placeholder)
.attr(identifiers.async.parseAsync)
.call(symbol.placeholder, dataParameterName)
.await()
.return(),
);
};
22 changes: 10 additions & 12 deletions packages/openapi-ts/src/plugins/zod/mini/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const createRequestValidatorMini = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};

Expand All @@ -49,11 +48,10 @@ export const createResponseValidatorMini = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};
22 changes: 10 additions & 12 deletions packages/openapi-ts/src/plugins/zod/v3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const createRequestValidatorV3 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};

Expand All @@ -49,11 +48,10 @@ export const createResponseValidatorV3 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call($(dataParameterName))
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};
22 changes: 10 additions & 12 deletions packages/openapi-ts/src/plugins/zod/v4/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ export const createRequestValidatorV4 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};

Expand All @@ -49,11 +48,10 @@ export const createResponseValidatorV4 = ({
.async()
.param(dataParameterName)
.do(
$.return(
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await(),
),
$(symbol.placeholder)
.attr(identifiers.parseAsync)
.call(dataParameterName)
.await()
.return(),
);
};
4 changes: 3 additions & 1 deletion packages/openapi-ts/src/ts-dsl/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ts from 'typescript';

import type { MaybeTsDsl, WithString } from './base';
import { TsDsl } from './base';
import { AccessMixin } from './mixins/access';
import { AccessMixin, registerLazyAccessAttrFactory } from './mixins/access';
import { mixin } from './mixins/apply';
import { AssignmentMixin } from './mixins/assignment';
import { OperatorMixin } from './mixins/operator';
Expand Down Expand Up @@ -59,3 +59,5 @@ export interface AttrTsDsl
OperatorMixin,
OptionalMixin {}
mixin(AttrTsDsl, AccessMixin, AssignmentMixin, OperatorMixin, OptionalMixin);

registerLazyAccessAttrFactory((expr, name) => new AttrTsDsl(expr, name));
15 changes: 11 additions & 4 deletions packages/openapi-ts/src/ts-dsl/await.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
/* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */
import ts from 'typescript';

import type { MaybeTsDsl, WithString } from './base';
import { TsDsl } from './base';
import { AccessMixin, registerLazyAccessAwaitFactory } from './mixins/access';
import { mixin } from './mixins/apply';

export class AwaitTsDsl extends TsDsl<ts.AwaitExpression> {
private exprNode: MaybeTsDsl<WithString>;
private _awaitExpr: MaybeTsDsl<WithString>;

constructor(expr: MaybeTsDsl<WithString>) {
super();
this.exprNode = expr;
this._awaitExpr = expr;
}

$render(): ts.AwaitExpression {
const expr = this.$node(this.exprNode);
return ts.factory.createAwaitExpression(expr);
return ts.factory.createAwaitExpression(this.$node(this._awaitExpr));
}
}

export interface AwaitTsDsl extends AccessMixin {}
mixin(AwaitTsDsl, AccessMixin);

registerLazyAccessAwaitFactory((expr) => new AwaitTsDsl(expr));
21 changes: 9 additions & 12 deletions packages/openapi-ts/src/ts-dsl/call.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
/* eslint-disable @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unsafe-declaration-merging */
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import ts from 'typescript';

import { AwaitTsDsl } from './await';
import type { MaybeTsDsl, WithString } from './base';
import { TsDsl } from './base';
import { AccessMixin, registerLazyAccessCallFactory } from './mixins/access';
import { mixin } from './mixins/apply';
import { ArgsMixin } from './mixins/args';

export class CallTsDsl extends TsDsl<ts.CallExpression> {
private callee: MaybeTsDsl<WithString>;
private _callee: MaybeTsDsl<WithString>;

constructor(
callee: MaybeTsDsl<WithString>,
...args: ReadonlyArray<MaybeTsDsl<WithString>>
) {
super();
this.callee = callee;
this._callee = callee;
this.args(...args);
}

/** Await the result of the call expression. */
await(): AwaitTsDsl {
return new AwaitTsDsl(this);
}

$render(): ts.CallExpression {
return ts.factory.createCallExpression(
this.$node(this.callee),
this.$node(this._callee),
undefined,
this.$args(),
);
}
}

export interface CallTsDsl extends ArgsMixin {}
mixin(CallTsDsl, ArgsMixin);
export interface CallTsDsl extends AccessMixin, ArgsMixin {}
mixin(CallTsDsl, AccessMixin, ArgsMixin);

registerLazyAccessCallFactory((expr, args) => new CallTsDsl(expr, ...args));
6 changes: 3 additions & 3 deletions packages/openapi-ts/src/ts-dsl/expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { mixin } from './mixins/apply';
import { OperatorMixin } from './mixins/operator';

export class ExprTsDsl extends TsDsl<ts.Expression> {
private input: MaybeTsDsl<WithString>;
private _exprInput: MaybeTsDsl<WithString>;

constructor(id: MaybeTsDsl<WithString>) {
super();
this.input = id;
this._exprInput = id;
}

$render(): ts.Expression {
return this.$node(this.input);
return this.$node(this._exprInput);
}
}

Expand Down
Loading
Loading