Skip to content

Instantly share code, notes, and snippets.

@sudomaxime
Created December 9, 2023 17:47
Show Gist options
  • Save sudomaxime/55896eed00967377392155bab243d315 to your computer and use it in GitHub Desktop.
Save sudomaxime/55896eed00967377392155bab243d315 to your computer and use it in GitHub Desktop.
doc-example.json
{
"endpoint": "/user",
"handler": "UserCreateHandler",
"inputs": {
"body": {
"email": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if a value is a valid email address",
"code": "INVALID_EMAIL_FORMAT",
"params": {},
"validateNullish": false,
"message": "Email format is invalid",
"serverSideOnly": false,
"fromStdLib": false,
"validatorName": "validEmail",
"customized": false
},
{
"type": "cast",
"description": "Converts the string to its lowercase representation.",
"params": {},
"runOnNullish": false,
"transformerName": "toLowerCase",
"customized": false
},
{
"type": "check",
"description": "Validates if a value length is over the provided bounds.",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255.",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "maxLength",
"customized": false
}
]
},
"emailRepeat": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if an email matches with the email repeat",
"code": "EMAIL_REPEAT_MISMATCH",
"params": {},
"validateNullish": false,
"message": "Your email doesn't match",
"serverSideOnly": false,
"fromStdLib": false,
"validatorName": "emailRepeat",
"customized": false
}
]
},
"firstName": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if a value length is inside the provided bounds.",
"code": "VALUE_NOT_IN_LENGTH_BOUNDS",
"params": {
"min": 2,
"max": 255
},
"validateNullish": false,
"message": "Value must be longer or equal than 2 and smaller than 255",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "lengthRange",
"customized": false
},
{
"type": "cast",
"description": "Remove trailing spaces at beginning and end of strings.",
"params": {},
"runOnNullish": false,
"transformerName": "trim",
"customized": false
},
{
"type": "cast",
"description": "Capitalize a string",
"params": {},
"runOnNullish": false,
"transformerName": "capitalize",
"customized": false
}
]
},
"lastName": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if a value length is inside the provided bounds.",
"code": "VALUE_NOT_IN_LENGTH_BOUNDS",
"params": {
"min": 2,
"max": 255
},
"validateNullish": false,
"message": "Value must be longer or equal than 2 and smaller than 255",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "lengthRange",
"customized": false
},
{
"type": "cast",
"description": "Remove trailing spaces at beginning and end of strings.",
"params": {},
"runOnNullish": false,
"transformerName": "trim",
"customized": false
},
{
"type": "cast",
"description": "Capitalize a string",
"params": {},
"runOnNullish": false,
"transformerName": "capitalize",
"customized": false
}
]
},
"password": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if a password have at least 8 characters, one special, one upper, one lower",
"code": "PASSWORD_TOO_WEAK",
"params": {},
"validateNullish": false,
"message": "Password is too weak, use at least 8 characters, one special, one upper, one lower",
"serverSideOnly": false,
"fromStdLib": false,
"validatorName": "strongPassword",
"customized": false
},
{
"type": "check",
"description": "Validates if a value length is over the provided bounds.",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255.",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "maxLength",
"customized": false
}
]
},
"passwordRepeat": {
"type": "string",
"pipeline": [
{
"type": "check",
"description": "Validates if a value is provided and non nullish.",
"code": "REQUIRED_VALUE",
"params": {},
"validateNullish": true,
"message": "This value is required",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "required",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a string",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "string",
"customized": false
},
{
"type": "check",
"description": "Validates if a value length is over the provided bounds.",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255.",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "maxLength",
"customized": false
},
{
"type": "check",
"description": "Validates if a password match with the password repeat",
"code": "PASSWORD_REPEAT_MISMATCH",
"params": {},
"validateNullish": false,
"message": "Your password doesn't match",
"serverSideOnly": false,
"fromStdLib": false,
"validatorName": "passwordRepeat",
"customized": false
}
]
},
"agreedTerms": {
"type": "boolean",
"pipeline": [
{
"type": "cast",
"description": "Converts truthy and falsy values to their boolean equivalents.",
"params": {},
"runOnNullish": false,
"transformerName": "boolify",
"customized": false
},
{
"type": "check",
"description": "Validates that a value is a boolean",
"code": "INVALID_TYPE",
"params": {},
"validateNullish": false,
"message": "You must provide a boolean for this value",
"serverSideOnly": false,
"fromStdLib": true,
"validatorName": "boolean",
"customized": false
},
{
"type": "check",
"description": "Make sure that a value is equals to true",
"code": "TERMS_AGREEMENT_REQUIRED",
"params": {},
"validateNullish": false,
"message": "This value isn't true",
"serverSideOnly": false,
"fromStdLib": false,
"validatorName": "agreedTerms",
"customized": false
}
]
}
},
"params": false,
"query": false,
"headers": false
},
"outputs": {
"status": 201,
"type": "ApiSuccess",
"handleAsDevelopperError": false,
"data": {
"ok": true,
"kind": "UserEntityAttributes",
"code": "USER_CREATED",
"self": "/user/:id",
"status": 201,
"message": "User created successfully.",
"outputs": {
"id": "number",
"firstName": "string",
"lastName": "string",
"email": "string",
"role": "string",
"createdAt": "string",
"updatedAt": "string",
"emailValidated": "boolean"
}
}
},
"throws": [
{
"status": 500,
"type": "DomainError",
"handleAsDevelopperError": true,
"data": {
"ok": false,
"code": "SERVER_ERROR",
"status": 500,
"message": "An error occured while processing your request.",
"errors": [],
"errorKeys": {},
"errorCodes": []
}
},
{
"status": 400,
"type": "DomainError",
"handleAsDevelopperError": false,
"data": {
"ok": false,
"code": "USER_PENDING_VALIDATION",
"status": 400,
"message": "This user has a pending validation, he should validate his email.",
"errors": [],
"errorKeys": {}
}
},
{
"status": 400,
"type": "DomainError",
"handleAsDevelopperError": false,
"data": {
"ok": false,
"code": "USER_ALREADY_EXISTS_BY_EMAIL",
"status": 400,
"message": "A user already exists with this email",
"errors": [],
"errorKeys": {}
}
},
{
"status": 400,
"type": "CasterValidationError",
"handleAsDevelopperError": false,
"data": {
"ok": false,
"code": "VALIDATION_ERROR",
"status": 400,
"message": "This request is malformed",
"errors": [
{
"schemaError": false,
"key": "email",
"validatorKey": "email",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "email",
"validatorKey": "email",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "email",
"validatorKey": "email",
"validator": "validEmail",
"code": "INVALID_EMAIL_FORMAT",
"description": "Validates if a value is a valid email address",
"params": {},
"validateNullish": false,
"message": "Email format is invalid"
},
{
"schemaError": false,
"key": "email",
"validatorKey": "email",
"validator": "maxLength",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"description": "Validates if a value length is over the provided bounds.",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255."
},
{
"schemaError": false,
"key": "emailRepeat",
"validatorKey": "emailRepeat",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "emailRepeat",
"validatorKey": "emailRepeat",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "emailRepeat",
"validatorKey": "emailRepeat",
"validator": "emailRepeat",
"code": "EMAIL_REPEAT_MISMATCH",
"description": "Validates if an email matches with the email repeat",
"params": {},
"validateNullish": false,
"message": "Your email doesn't match"
},
{
"schemaError": false,
"key": "firstName",
"validatorKey": "firstName",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "firstName",
"validatorKey": "firstName",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "firstName",
"validatorKey": "firstName",
"validator": "lengthRange",
"code": "VALUE_NOT_IN_LENGTH_BOUNDS",
"description": "Validates if a value length is inside the provided bounds.",
"params": {
"min": 2,
"max": 255
},
"validateNullish": false,
"message": "Value must be longer or equal than 2 and smaller than 255"
},
{
"schemaError": false,
"key": "lastName",
"validatorKey": "lastName",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "lastName",
"validatorKey": "lastName",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "lastName",
"validatorKey": "lastName",
"validator": "lengthRange",
"code": "VALUE_NOT_IN_LENGTH_BOUNDS",
"description": "Validates if a value length is inside the provided bounds.",
"params": {
"min": 2,
"max": 255
},
"validateNullish": false,
"message": "Value must be longer or equal than 2 and smaller than 255"
},
{
"schemaError": false,
"key": "password",
"validatorKey": "password",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "password",
"validatorKey": "password",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "password",
"validatorKey": "password",
"validator": "strongPassword",
"code": "PASSWORD_TOO_WEAK",
"description": "Validates if a password have at least 8 characters, one special, one upper, one lower",
"params": {},
"validateNullish": false,
"message": "Password is too weak, use at least 8 characters, one special, one upper, one lower"
},
{
"schemaError": false,
"key": "password",
"validatorKey": "password",
"validator": "maxLength",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"description": "Validates if a value length is over the provided bounds.",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255."
},
{
"schemaError": false,
"key": "passwordRepeat",
"validatorKey": "passwordRepeat",
"validator": "required",
"code": "REQUIRED_VALUE",
"description": "Validates if a value is provided and non nullish.",
"params": {},
"validateNullish": true,
"message": "This value is required"
},
{
"schemaError": false,
"key": "passwordRepeat",
"validatorKey": "passwordRepeat",
"validator": "string",
"code": "INVALID_TYPE",
"description": "Validates that a value is a string",
"params": {},
"validateNullish": false,
"message": "You must provide a string for this value"
},
{
"schemaError": false,
"key": "passwordRepeat",
"validatorKey": "passwordRepeat",
"validator": "maxLength",
"code": "VALUE_OVER_LENGTH_BOUNDS",
"description": "Validates if a value length is over the provided bounds.",
"params": {
"length": 255
},
"validateNullish": false,
"message": "Value must be shorter than 255."
},
{
"schemaError": false,
"key": "passwordRepeat",
"validatorKey": "passwordRepeat",
"validator": "passwordRepeat",
"code": "PASSWORD_REPEAT_MISMATCH",
"description": "Validates if a password match with the password repeat",
"params": {},
"validateNullish": false,
"message": "Your password doesn't match"
},
{
"schemaError": false,
"key": "agreedTerms",
"validatorKey": "agreedTerms",
"validator": "boolean",
"code": "INVALID_TYPE",
"description": "Validates that a value is a boolean",
"params": {},
"validateNullish": false,
"message": "You must provide a boolean for this value"
},
{
"schemaError": false,
"key": "agreedTerms",
"validatorKey": "agreedTerms",
"validator": "agreedTerms",
"code": "TERMS_AGREEMENT_REQUIRED",
"description": "Make sure that a value is equals to true",
"params": {},
"validateNullish": false,
"message": "This value isn't true"
}
],
"errorKeys": {
"email": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"INVALID_EMAIL_FORMAT",
"VALUE_OVER_LENGTH_BOUNDS"
],
"emailRepeat": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"EMAIL_REPEAT_MISMATCH"
],
"firstName": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"VALUE_NOT_IN_LENGTH_BOUNDS"
],
"lastName": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"VALUE_NOT_IN_LENGTH_BOUNDS"
],
"password": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"PASSWORD_TOO_WEAK",
"VALUE_OVER_LENGTH_BOUNDS"
],
"passwordRepeat": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"VALUE_OVER_LENGTH_BOUNDS",
"PASSWORD_REPEAT_MISMATCH"
],
"agreedTerms": [
"INVALID_TYPE",
"TERMS_AGREEMENT_REQUIRED"
]
},
"errorCodes": [
"REQUIRED_VALUE",
"INVALID_TYPE",
"INVALID_EMAIL_FORMAT",
"VALUE_OVER_LENGTH_BOUNDS",
"EMAIL_REPEAT_MISMATCH",
"VALUE_NOT_IN_LENGTH_BOUNDS",
"PASSWORD_TOO_WEAK",
"PASSWORD_REPEAT_MISMATCH",
"TERMS_AGREEMENT_REQUIRED"
]
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment