Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into args
Browse files Browse the repository at this point in the history
  • Loading branch information
WoH committed Dec 8, 2024
2 parents 67f85ee + 666fec3 commit daa1dec
Show file tree
Hide file tree
Showing 19 changed files with 1,336 additions and 1,343 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/closeStaleIssuesAndPRs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
days-before-stale: 30
days-before-close: 5
days-before-stale: 150
days-before-close: 30
exempt-issue-labels: 'help wanted,Pending feedback'
exempt-pr-labels: 'help wanted,breaking change'
4 changes: 2 additions & 2 deletions .github/workflows/runTestsOnPush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
matrix:
node-version: [18, 20, 21]
os: [macos-latest, ubuntu-latest, windows-latest]
typescript-version: ['^4.9.5', '^5.2.2']
typescript-version: ['^5.0.0']

steps:
- uses: actions/checkout@master

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: yarn
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"fs-extra": "^11.2.0",
"glob": "^10.3.10",
"handlebars": "^4.7.8",
"merge-anything": "^5.1.4",
"merge-anything": "^5.1.7",
"minimatch": "^9.0.1",
"ts-deepmerge": "^7.0.1",
"typescript": "^5.6.2",
"ts-deepmerge": "^7.0.2",
"typescript": "^5.7.2",
"validator": "^13.12.0",
"yaml": "^2.5.1",
"yaml": "^2.6.1",
"yargs": "^17.7.1"
},
"devDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/metadataGeneration/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ export class GenerateMetadataError extends Error {
}

export class GenerateMetaDataWarning {
constructor(private message: string, private node: Node | TypeNode, private onlyCurrent = false) { }
constructor(
private message: string,
private node: Node | TypeNode,
private onlyCurrent = false,
) {}

toString() {
return `Warning: ${this.message}\n${prettyLocationOfNode(this.node)}\n${prettyTroubleCause(this.node, this.onlyCurrent)}`;
Expand All @@ -34,9 +38,9 @@ export function prettyLocationOfNode(node: Node | TypeNode) {
export function prettyTroubleCause(node: Node | TypeNode, onlyCurrent = false) {
let name: string;
if (onlyCurrent || !node.parent) {
name = node.pos !== -1 ? node.getText() : ((node as any).name?.text || '<unknown name>');
name = node.pos !== -1 && node.parent ? node.getText() : (node as any).name?.text || '<unknown name>';
} else {
name = node.parent.pos !== -1 ? node.parent.getText() : ((node as any).parent.name?.text || '<unknown name>');
name = node.parent.pos !== -1 ? node.parent.getText() : (node as any).parent.name?.text || '<unknown name>';
}
return `This was caused by '${name}'`;
}
2 changes: 1 addition & 1 deletion packages/cli/src/routeGeneration/routeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export abstract class AbstractRouteGenerator<Config extends ExtendedRoutesConfig
fileSize: 8388608, // 8mb
},
...this.options.multerOpts,
},
} as Config['multerOpts'],
useSecurity: this.metadata.controllers.some(controller => controller.methods.some(method => !!method.security.length)),
esm: this.options.esm,
};
Expand Down
263 changes: 144 additions & 119 deletions packages/cli/src/utils/validatorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,71 +32,74 @@ export function getParameterValidators(parameter: ts.ParameterDeclaration, param
}
}

return tags.reduce((validateObj, tag) => {
if (!tag.comment) {
return validateObj;
}
return tags.reduce(
(validateObj, tag) => {
if (!tag.comment) {
return validateObj;
}

const name = tag.tagName.text;
const comment = commentToString(tag.comment)
?.substr((commentToString(tag.comment)?.indexOf(' ') || -1) + 1)
.trim();
const value = getCommentValue(comment);
const name = tag.tagName.text;
const comment = commentToString(tag.comment)
?.substring((commentToString(tag.comment)?.indexOf(' ') || -1) + 1)
.trim();
const value = getCommentValue(comment);

switch (name) {
case 'uniqueItems':
validateObj[name] = {
errorMsg: getErrorMsg(comment, false),
value: undefined,
};
break;
case 'minimum':
case 'maximum':
case 'minItems':
case 'maxItems':
case 'minLength':
case 'maxLength':
if (isNaN(value as any)) {
throw new GenerateMetadataError(`${name} parameter use number.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value: Number(value),
};
break;
case 'minDate':
case 'maxDate':
if (!validator.isISO8601(String(value), { strict: true })) {
throw new GenerateMetadataError(`${name} parameter use date format ISO 8601 ex. 2017-05-14, 2017-05-14T05:18Z`);
}
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value,
};
break;
case 'pattern':
if (typeof value !== 'string') {
throw new GenerateMetadataError(`${name} parameter use string.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value: removeSurroundingQuotes(value),
};
break;
default:
if (name.startsWith('is')) {
const errorMsg = getErrorMsg(comment, false);
if (errorMsg) {
validateObj[name] = {
errorMsg,
value: undefined,
};
switch (name) {
case 'uniqueItems':
validateObj[name] = {
errorMsg: getErrorMsg(comment, false),
value: undefined,
};
break;
case 'minimum':
case 'maximum':
case 'minItems':
case 'maxItems':
case 'minLength':
case 'maxLength':
if (isNaN(value as any)) {
throw new GenerateMetadataError(`${name} parameter use number.`);
}
}
break;
}
return validateObj;
}, {} as Tsoa.Validators & { [unknown: string]: { errorMsg: string; value: undefined } });
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value: Number(value),
};
break;
case 'minDate':
case 'maxDate':
if (!validator.isISO8601(String(value), { strict: true })) {
throw new GenerateMetadataError(`${name} parameter use date format ISO 8601 ex. 2017-05-14, 2017-05-14T05:18Z`);
}
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value,
};
break;
case 'pattern':
if (typeof value !== 'string') {
throw new GenerateMetadataError(`${name} parameter use string.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(comment),
value: removeSurroundingQuotes(value),
};
break;
default:
if (name.startsWith('is')) {
const errorMsg = getErrorMsg(comment, false);
if (errorMsg) {
validateObj[name] = {
errorMsg,
value: undefined,
};
}
}
break;
}
return validateObj;
},
{} as Tsoa.Validators & { [unknown: string]: { errorMsg: string; value: undefined } },
);
}

export function getPropertyValidators(property: ts.Node): Tsoa.Validators | undefined {
Expand All @@ -109,6 +112,15 @@ export function getPropertyValidators(property: ts.Node): Tsoa.Validators | unde
}
return comment.split(' ')[0];
}
function getFullValue(comment?: string) {
if (!comment) {
return;
}
if (comment.includes('\n')) {
return comment.split('\n')[0];
}
return comment;
}
function getErrorMsg(comment?: string, isValue = true) {
if (!comment) {
return;
Expand All @@ -125,65 +137,77 @@ export function getPropertyValidators(property: ts.Node): Tsoa.Validators | unde
}
}

return tags.reduce((validateObj, tag) => {
const name = tag.tagName.text;
const comment = tag.comment;
const value = getValue(commentToString(comment));
return tags.reduce(
(validateObj, tag) => {
const name = tag.tagName.text;
const comment = tag.comment;
const value = getValue(commentToString(comment));

switch (name) {
case 'uniqueItems':
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment), false),
value: undefined,
};
break;
case 'minimum':
case 'maximum':
case 'minItems':
case 'maxItems':
case 'minLength':
case 'maxLength':
if (isNaN(value as any)) {
throw new GenerateMetadataError(`${name} parameter use number.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value: Number(value),
};
break;
case 'minDate':
case 'maxDate':
if (!validator.isISO8601(String(value), { strict: true })) {
throw new GenerateMetadataError(`${name} parameter use date format ISO 8601 ex. 2017-05-14, 2017-05-14T05:18Z`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value,
};
break;
case 'pattern':
if (typeof value !== 'string') {
throw new GenerateMetadataError(`${name} parameter use string.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value: removeSurroundingQuotes(value),
};
break;
default:
if (name.startsWith('is')) {
const errorMsg = getErrorMsg(commentToString(comment), false);
if (errorMsg) {
validateObj[name] = {
errorMsg,
value: undefined,
};
switch (name) {
case 'uniqueItems':
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment), false),
value: undefined,
};
break;
case 'minimum':
case 'maximum':
case 'minItems':
case 'maxItems':
case 'minLength':
case 'maxLength':
if (isNaN(value as any)) {
throw new GenerateMetadataError(`${name} parameter use number.`);
}
}
break;
}
return validateObj;
}, {} as Tsoa.Validators & { [unknown: string]: { errorMsg: string; value: undefined } });
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value: Number(value),
};
break;
case 'minDate':
case 'maxDate':
if (!validator.isISO8601(String(value), { strict: true })) {
throw new GenerateMetadataError(`${name} parameter use date format ISO 8601 ex. 2017-05-14, 2017-05-14T05:18Z`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value,
};
break;
case 'pattern':
if (typeof value !== 'string') {
throw new GenerateMetadataError(`${name} parameter use string.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value: removeSurroundingQuotes(value),
};
break;
case 'title':
if (typeof value !== 'string') {
throw new GenerateMetadataError(`${name} parameter use string.`);
}
validateObj[name] = {
errorMsg: getErrorMsg(commentToString(comment)),
value: getFullValue(commentToString(comment)),
};
break;
default:
if (name.startsWith('is')) {
const errorMsg = getErrorMsg(commentToString(comment), false);
if (errorMsg) {
validateObj[name] = {
errorMsg,
value: undefined,
};
}
}
break;
}
return validateObj;
},
{} as Tsoa.Validators & { [unknown: string]: { errorMsg: string; value: undefined } },
);
}

function getParameterTagSupport() {
Expand All @@ -206,6 +230,7 @@ function getParameterTagSupport() {
'maximum',
'minDate',
'maxDate',
'title',
];
}

Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
"license": "MIT",
"dependencies": {
"@hapi/boom": "^10.0.1",
"@hapi/hapi": "^21.3.10",
"@hapi/hapi": "^21.3.12",
"@types/koa": "^2.15.0",
"@types/multer": "^1.4.12",
"express": "^4.21.0",
"express": "^4.21.2",
"reflect-metadata": "^0.2.2",
"validator": "^13.12.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"@types/validator": "^13.12.2",
"typescript": "^5.6.2"
"typescript": "^5.7.2"
},
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit daa1dec

Please sign in to comment.