Skip to content

Commit dea147f

Browse files
committed
first commit
0 parents  commit dea147f

File tree

13 files changed

+5763
-0
lines changed

13 files changed

+5763
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "standard"
3+
}

.github/workflows/test.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-node@v3
14+
with:
15+
node-version: '18.x'
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Run tests
19+
run: npm test

.gitignore

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (https://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# TypeScript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# next.js build output
61+
.next

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]

CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing to fastify-response-validation
2+
3+
## Issue Contributions
4+
5+
When opening new issues or commenting on existing issues on this repository
6+
please make sure discussions are related to concrete technical issues.
7+
8+
Try to be *friendly* (we are not animals :monkey: or bad people :rage4:) and explain correctly how we can reproduce your issue.
9+
10+
## Code Contributions
11+
12+
This document will guide you through the contribution process.
13+
14+
### Step 1: Fork
15+
16+
Fork the project [on GitHub](https://github.com/geut/fastify-response-validation) and check out your copy locally.
17+
18+
```bash
19+
$ git clone [email protected]:username/fastify-response-validation.git
20+
$ cd fastify-response-validation
21+
$ npm install
22+
$ git remote add upstream git://github.com/geut/fastify-response-validation.git
23+
```
24+
25+
### Step 2: Branch
26+
27+
Create a feature branch and start hacking:
28+
29+
```bash
30+
$ git checkout -b my-feature-branch -t origin/main
31+
```
32+
33+
### Step 3: Test
34+
35+
Bug fixes and features **should come with tests**. We use [jest](https://jestjs.io/) to do that.
36+
37+
```bash
38+
$ npm test
39+
```
40+
41+
### Step 4: Lint
42+
43+
Make sure the linter is happy and that all tests pass. Please, do not submit
44+
patches that fail either check.
45+
46+
We use [standard](https://standardjs.com/)
47+
48+
### Step 5: Commit
49+
50+
Make sure git knows your name and email address:
51+
52+
```bash
53+
$ git config --global user.name "Bruce Wayne"
54+
$ git config --global user.email "[email protected]"
55+
```
56+
57+
Writing good commit logs is important. A commit log should describe what
58+
changed and why.
59+
60+
### Step 6: Changelog
61+
62+
If your changes are really important for the project probably the users want to know about it.
63+
64+
We use [chan](https://github.com/geut/chan/) to maintain a well readable changelog for our users.
65+
66+
### Step 7: Push
67+
68+
```bash
69+
$ git push origin my-feature-branch
70+
```
71+
72+
### Step 8: Make a pull request ;)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 GEUT
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# fastify-response-validation
2+
A simple plugin that enables response validation for Fastify.
3+
4+
![Tests](https://github.com/geut/fastify-response-validation/actions/workflows/test.yml/badge.svg)
5+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat)](https://standardjs.com)
6+
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat)](https://github.com/RichardLitt/standard-readme)
7+
8+
[![Made by GEUT][geut-badge]][geut-url]
9+
10+
## Install
11+
12+
```bash
13+
$ npm install --save-dev @geut/fastify-response-validation
14+
```
15+
16+
## Usage
17+
18+
```javascript
19+
import fastify from 'fastify'
20+
21+
const app = fastify()
22+
23+
await app.register(import('@geut/fastify-response-validation'))
24+
25+
app.route({
26+
method: 'GET',
27+
path: '/',
28+
schema: {
29+
response: {
30+
'2xx': {
31+
type: 'object',
32+
properties: {
33+
answer: { type: 'string', format: 'date' }
34+
}
35+
}
36+
}
37+
},
38+
handler: async (req, reply) => {
39+
return { answer: 'wrong date' }
40+
}
41+
})
42+
43+
app.inject({
44+
method: 'GET',
45+
path: '/'
46+
}, (err, res) => {
47+
if (err) throw err
48+
// {"statusCode":500,"error":"Internal Server Error","message":"response/answer must match format \"date\""}
49+
console.log(res.payload)
50+
})
51+
```
52+
53+
## Issues
54+
55+
:bug: If you found an issue we encourage you to report it on [github](https://github.com/geut/fastify-response-validation/issues). Please specify your OS and the actions to reproduce it.
56+
57+
## Contributing
58+
59+
:busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this [guideline](https://github.com/geut/fastify-response-validation/blob/main/CONTRIBUTING.md).
60+
61+
## License
62+
63+
MIT © A [**GEUT**](http://geutstudio.com/) project
64+
65+
[geut-url]: https://geutstudio.com
66+
[geut-badge]: https://img.shields.io/badge/Made%20By-GEUT-4f5186?style=for-the-badge&link=https://geutstudio.com&labelColor=white&logo=data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2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C66Xqtvbx+EjIp10jaOMLBaPasDwRTGc5PyNJ1rb9EN5/jP7U17KaaZJvbpV6icI88z3+VG0vH8ipJJ8Ga8tIr22eCYZVh5g94pC1TTJtPmMU67yH4XxwYV0So54IriIxzRrIh7QwzSIyOTbWzlElkCcxtjwNedHeKMCVseDmnq72UgkJa1maL9LDeH81XvspfA9WSBh/sR6U9XD+zDQp+yTSNmR/MnJomG3SLiBlu80zQ7JXTH31xEg/Tlj6Vb2OzljaEO6meQc5OweVc8koOmUGjaFLfuss4MdsOOewv8v5p0ijSGNY41CoowAOQrbsr2p7t0zSWj//Z

example.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import fastify from 'fastify'
2+
3+
const app = fastify()
4+
5+
await app.register(import('./src/index.js'))
6+
7+
app.route({
8+
method: 'GET',
9+
path: '/',
10+
schema: {
11+
response: {
12+
'2xx': {
13+
type: 'object',
14+
properties: {
15+
answer: { type: 'string', format: 'date' }
16+
}
17+
}
18+
}
19+
},
20+
handler: async (req, reply) => {
21+
return { answer: 'wrong date' }
22+
}
23+
})
24+
25+
app.inject({
26+
method: 'GET',
27+
path: '/'
28+
}, (err, res) => {
29+
if (err) throw err
30+
// {"statusCode":500,"error":"Internal Server Error","message":"response/answer must match format \"date\""}
31+
console.log(res.payload)
32+
})

0 commit comments

Comments
 (0)