Skip to content

Instantly share code, notes, and snippets.

@Eomm
Created April 14, 2019 09:21
Show Gist options
  • Save Eomm/9f7e2dcdc8c7e14a8f101ecb32540f3d to your computer and use it in GitHub Desktop.
Save Eomm/9f7e2dcdc8c7e14a8f101ecb32540f3d to your computer and use it in GitHub Desktop.
'use strict'
const fastify = require('./fastify')({ logger: true })
// Requests
fastify.addSchema({
$id: 'Request/Auth/Login',
type: 'object',
required: ['email', 'password'],
properties: {
email: { type: 'string', minLength: 6 },
password: { type: 'string', minLength: 8 }
},
tags: ['admin', 'user'],
additionalProperties: false
})
// Responses
fastify.addSchema({
$id: 'Response/Auth/R2XX',
type: 'object',
required: ['status', 'email'],
properties: {
status: { type: 'string' },
email: { type: 'string' },
slug: { type: 'string' },
role: {
type: 'array',
items: {
type: 'string'
}
}
},
tags: ['admin', 'user']
})
// ....
fastify.addSchema({
$id: 'Response/Success/200R',
$ref: 'Response/Success/200S#',
required: ['status']
})
fastify.addSchema({
$id: 'Response/Success/200IR',
$ref: 'Response/Success/200S#',
required: ['id', 'status'],
properties: {
id: { type: 'string' }
}
})
/* End Response schema */
/* Universal ID Delete El */
fastify.addSchema({
$id: 'Request/Any/DeleteByID',
type: 'object',
required: ['id'],
properties: {
id: { type: 'string' }
},
additionalProperties: false
})
/* Universal Schema for some routes */
fastify.addSchema({
$id: 'Response/DB/AnyStatType',
type: 'object',
required: ['status', 'type'],
properties: {
status: { type: 'string' },
type: { type: 'string' }
}
})
fastify.listen(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment