Skip to content

Commit 8ad0787

Browse files
committed
greatly improved client code gen
1 parent 3e308b2 commit 8ad0787

File tree

3 files changed

+189
-160
lines changed

3 files changed

+189
-160
lines changed

src/Exceptionless.Web/ClientApp/api-templates/class-data-contract.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export class <%~ contract.name %> {
66
<% for (const field of contract.$content) { %>
77
<%~ includeFile('@base/object-field-jsdoc.ejs', { ...it, field }) %>
88
<%~ includeFile('./object-field-class-validator.ejs', { ...it, field }) %>
9-
<%~ field.name %><%~ field.isRequired || field.nullable !== true ? '!' : '' %>: <%~ field.value.replaceAll('any', 'unknown') %><%~ field.type === "object" && field.nullable === true ? ' | null' : '' %><%~ field.nullable === true ? ' = null' : '' %>;
9+
<%~ field.name %><%~ field.isRequired || !field.nullable ? '!' : '' %><%~ field.nullable ? '?' : '' %>: <%~ field.value.replaceAll('any', 'unknown') %>;
1010
<% } %>
1111
}
1212

src/Exceptionless.Web/ClientApp/api-templates/object-field-class-validator.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function getFormatValidation(field) {
2222
}
2323
2424
const validationDecorators = _.compact([
25-
!field.isRequired && "@IsOptional()",
25+
!field.isRequired && field.nullable && "@IsOptional()",
2626
(field.name === "id" || field.name.endsWith("_id")) && `@IsMongoId({ message: '${field.name} must be a valid ObjectId.' })`,
2727
field.name === "url" && `@IsUrl({}, { message: '${field.name} must be a valid URL.' })`,
2828
!_.isUndefined(field.format) && getFormatValidation(field),
@@ -32,7 +32,7 @@ const validationDecorators = _.compact([
3232
!_.isUndefined(field.type) && (field.type === "object" || (field.type === "array" && field.items.$ref)) && `@ValidateNested({ message: '${field.name} must be a valid nested object.' })`,
3333
]);
3434
35-
if (!validationDecorators.length && field.isRequired) {
35+
if (!validationDecorators.length && (field.isRequired || !field.nullable)) {
3636
validationDecorators.push(`@IsDefined({ message: '${field.name} is required.' })`);
3737
}
3838

0 commit comments

Comments
 (0)