• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Fdawgs / ydh-myydh-crud-api / 4417510579

pending completion
4417510579

push

github

GitHub
chore(main): release 11.0.7 (#1221)

259 of 259 branches covered (100.0%)

Branch coverage included in aggregate %.

527 of 527 relevant lines covered (100.0%)

14.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/plugins/shared-schemas/index.js
1
const fp = require("fastify-plugin");
9✔
2
const S = require("fluent-json-schema");
9✔
3

4
/**
5
 * @author Frazer Smith
6
 * @description Plugin that adds a collection of shared schemas for re-use throughout the server.
7
 * @param {object} server - Fastify instance.
8
 */
9
async function plugin(server) {
10
        /**
11
         * NOTE: `.definition()` definitions have been replaced with `.prop()` properties, and
12
         * `.id()` ids removed due to definitions breaking in v4.12.1 of fastify-swagger.
13
         * See https://github.com/fastify/fastify-swagger/issues/524
14
         */
15

16
        // Response schemas
17
        server.addSchema(
38✔
18
                S.object()
19
                        .id("responses")
20
                        .title("Responses")
21
                        .description("Common response schemas")
22
                        .prop(
23
                                "badRequest",
24
                                S.object()
25
                                        .title("400 Bad Request")
26
                                        .prop("statusCode", S.number().const(400))
27
                                        .prop("error", S.string().const("Bad Request"))
28
                                        .prop(
29
                                                "message",
30
                                                S.string().examples([
31
                                                        "No valid query string parameters provided",
32
                                                ])
33
                                        )
34
                        )
35
                        .prop(
36
                                "unauthorized",
37
                                S.object()
38
                                        .title("401 Unauthorized")
39
                                        .prop("statusCode", S.number().const(401))
40
                                        .prop("error", S.string().const("Unauthorized"))
41
                                        .prop(
42
                                                "message",
43
                                                S.string().examples(["missing authorization header"])
44
                                        )
45
                        )
46
                        .prop(
47
                                "notFoundDbResults",
48
                                S.object()
49
                                        .title("404 Not Found Response")
50
                                        .prop("statusCode", S.number().const(404))
51
                                        .prop("error", S.string().const("Not Found"))
52
                                        .prop(
53
                                                "message",
54
                                                S.string().examples([
55
                                                        "Invalid or expired search results",
56
                                                        "Record does not exist or has already been deleted",
57
                                                        "User not found",
58
                                                ])
59
                                        )
60
                        )
61
                        .prop(
62
                                "notAcceptable",
63
                                S.object()
64
                                        .title("406 Not Acceptable Response")
65
                                        .prop("statusCode", S.number().const(406))
66
                                        .prop("error", S.string().const("Not Acceptable"))
67
                                        .prop("message", S.string().const("Not Acceptable"))
68
                        )
69
                        .prop(
70
                                "unsupportedMediaType",
71
                                S.object()
72
                                        .title("415 Unsupported Media Type")
73
                                        .prop("statusCode", S.number().const(415))
74
                                        .prop("error", S.string().const("Unsupported Media Type"))
75
                                        .prop(
76
                                                "message",
77
                                                S.string().examples([
78
                                                        "Unsupported Media Type: application/xml",
79
                                                ])
80
                                        )
81
                        )
82
                        .prop(
83
                                "tooManyRequests",
84
                                S.object()
85
                                        .title("429 Too Many Requests Response")
86
                                        .prop("statusCode", S.number().const(429))
87
                                        .prop("error", S.string().const("Too Many Requests"))
88
                                        .prop(
89
                                                "message",
90
                                                S.string().examples([
91
                                                        "Rate limit exceeded, retry in 1 minute",
92
                                                ])
93
                                        )
94
                        )
95
                        .prop(
96
                                "internalServerError",
97
                                S.object()
98
                                        .title("500 Internal Server Error Response")
99
                                        .prop("statusCode", S.number().const(500))
100
                                        .prop("error", S.string().const("Internal Server Error"))
101
                                        .prop(
102
                                                "message",
103
                                                // JSON Schema does not support Regex flags, added for posterity
104
                                                S.string().pattern(
105
                                                        /^(?:Internal Server Error|Error.*)$/m
106
                                                )
107
                                        )
108
                        )
109
                        .prop(
110
                                "serviceUnavailable",
111
                                S.object()
112
                                        .title("503 Service Unavailable")
113
                                        .prop("statusCode", S.number().const(503))
114
                                        .prop("code", S.string().const("FST_UNDER_PRESSURE"))
115
                                        .prop("error", S.string().const("Service Unavailable"))
116
                                        .prop("message", S.string().const("Service Unavailable"))
117
                        )
118
        );
119
}
120

121
module.exports = fp(plugin, {
9✔
122
        fastify: "4.x",
123
        name: "shared-schemas",
124
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc