Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bahmutov/todo-api-with-json-schema
Example todo API with json schema validation
https://github.com/bahmutov/todo-api-with-json-schema
cypress demo example json-schema
Last synced: 3 months ago
JSON representation
Example todo API with json schema validation
- Host: GitHub
- URL: https://github.com/bahmutov/todo-api-with-json-schema
- Owner: bahmutov
- Created: 2018-04-29T13:52:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-16T06:56:35.000Z (3 months ago)
- Last Synced: 2024-09-16T08:22:06.736Z (3 months ago)
- Topics: cypress, demo, example, json-schema
- Language: JavaScript
- Size: 889 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# todo-api-with-json-schema
[![CircleCI](https://circleci.com/gh/bahmutov/todo-api-with-json-schema.svg?style=svg)](https://circleci.com/gh/bahmutov/todo-api-with-json-schema) [![renovate-app badge][renovate-badge]][renovate-app]
This is a demo application showing how to use JSON schemas to validate data flowing in the system.
## Run locally
After cloning the repo, execute from the terminal
```bash
npm install
npm run dev
```Application should be running at `localhost:3000` and Cypress should open.
## Information
- See slides for presentation [JSON Schemas](https://slides.com/bahmutov/json-schemas-confoo)
- Read [JSON Schemas are your True Testing Friend](https://www.cypress.io/blog/2018/07/10/json-schemas-are-your-true-testing-friend/)## Tests
This project declares the following [schemas](schemas.md). Then the schemas are used from the end-to-end tests. Look at the following tests to see how you can use JSON schemas from your tests
- [cypress/integration/fixture-spec.js](cypress/integration/fixture-spec.js) to validate fixture files against a schema
- [cypress/integration/api-spec.js](cypress/integration/api-spec.js) validates REST api calls against response schema
- [cypress/integration/ui-spec.js](cypress/integration/ui-spec.js) drives the web application via DOM UI and validates the Ajax calls from the application to the server using data schemaExample error message when a fixture object does not match the schema
![Fixture schema error](images/fixture-does-not-match-schema.png)
## Ramda
If you use [Ramda](https://ramdajs.com/docs/) or [lodash/fp](https://github.com/lodash/lodash/wiki/FP-Guide) you can use curried schema tools functions to create terse functions to validate and sanitize lists of objects. See [cypress/integration/ui-spec.js](cypress/integration/ui-spec.js) for examples.
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
[renovate-app]: https://renovateapp.com/