-
-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(schema): fix typing for operation decorators #2973
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -79,6 +79,7 @@ describe("Consumes", () => { | |||||
|
||||||
let actualError: any; | ||||||
try { | ||||||
// @ts-ignore | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider adding type annotation for better clarity. The test case effectively validates the error handling. Consider adding a type annotation to make the intention clearer: -// @ts-ignore
+// @ts-ignore - Testing invalid decorator usage on parameter 📝 Committable suggestion
Suggested change
|
||||||
Consumes("text/json")(Test.prototype, "test", 0); | ||||||
} catch (er) { | ||||||
actualError = er; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,7 +50,7 @@ import {Returns} from "./returns.js"; | |||||
* @operation | ||||||
* @response | ||||||
*/ | ||||||
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): Function { | ||||||
export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add explicit decorator return type. While removing the generic -export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader) {
+export function Header(headers: string | number | JsonHeaders, value?: string | number | JsonHeader): MethodDecorator { The 📝 Committable suggestion
Suggested change
|
||||||
if (value !== undefined) { | ||||||
headers = {[headers as string]: value}; | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,9 +53,9 @@ import {Returns} from "./returns.js"; | |
* @response | ||
* @headers | ||
*/ | ||
export function Redirect(url: string, meta?: JsonHeader): Function; | ||
export function Redirect(status: number, url: string, meta?: JsonHeader): Function; | ||
export function Redirect(...args: any[]): Function { | ||
export function Redirect(url: string, meta?: JsonHeader): MethodDecorator; | ||
export function Redirect(status: number, url: string, meta?: JsonHeader): MethodDecorator; | ||
export function Redirect(...args: any[]): MethodDecorator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider adding type safety for the spread arguments. The spread operator with -export function Redirect(...args: any[]): MethodDecorator {
+export function Redirect(...args: Array<string | number | JsonHeader>): MethodDecorator {
|
||
const {status, url, meta} = args.reduce( | ||
(options: any, value: any) => { | ||
if (isNumber(value)) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ import {JsonEntityFn} from "../common/jsonEntityFn.js"; | |
* @classDecorator | ||
* @operation | ||
*/ | ||
export function Security(name: string, ...scopes: string[]): Function; | ||
export function Security(name: string, ...scopes: string[]): ClassDecorator & MethodDecorator; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Type declarations accurately reflect decorator usage. The return type Also applies to: 60-61 |
||
/** | ||
* Add security metadata on the decorated method. | ||
* | ||
|
@@ -57,8 +57,8 @@ export function Security(name: string, ...scopes: string[]): Function; | |
* @classDecorator | ||
* @operation | ||
*/ | ||
export function Security(security: OpenSpecSecurity): Function; | ||
export function Security(nameOrSecurity: string | OpenSpecSecurity, ...scopes: string[]): Function { | ||
export function Security(security: OpenSpecSecurity): ClassDecorator & MethodDecorator; | ||
export function Security(nameOrSecurity: string | OpenSpecSecurity, ...scopes: string[]): ClassDecorator & MethodDecorator { | ||
return JsonEntityFn((store, args) => { | ||
switch (store.decoratorType) { | ||
case DecoratorTypes.METHOD: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
LGTM! Consider adding @methodDecorator to JSDoc.
The return type correctly allows both class and method usage. Consider adding
@methodDecorator
to the JSDoc tags to match the implementation.* @decorator * @operation * @response + * @methodDecorator */