Skip to content

Commit 16a89e4

Browse files
authored
Merge pull request #167 from alphagov/add-adr-for-api-tooling
Add ADR for Serialization and Schema Validation in GOV.UK Chat API
2 parents 3e56314 + ed6bc18 commit 16a89e4

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# 7. Serialisation and Schema Validation for GOV.UK Chat API
2+
3+
**Date:** 2025-04-15
4+
5+
## Context
6+
7+
We are building an API for GOV.UK Chat, and as part of that we need to choose tools for two concerns:
8+
9+
1. Serialising Ruby objects into JSON responses
10+
2. Validating API requests and responses against our OpenAPI specification
11+
12+
These tools should be simple, reliable, and maintainable, with minimal dependencies and good community support.
13+
14+
## Decision
15+
16+
### Serialisation
17+
18+
We have chosen to use [Blueprinter](https://github.com/procore/blueprinter) for serializing objects into JSON. It provides a clean and lightweight way to define how data is exposed through the API.
19+
20+
We decided against
21+
22+
- **active_model_serializers**, as there are issues with maintenance and it has a history of stability issues. See:
23+
- https://github.com/rails-api/active_model_serializers/issues
24+
- https://github.com/rails-api/active_model_serializers/issues/2396
25+
- **jsonapi-serializer**, We felt that our returned data models would be harder to work with were they to follow the requirements of the JSON API specification and thus provide a reduced user experience.
26+
27+
Blueprinter is preferred because:
28+
29+
- It’s simple to configure and easy to read
30+
- It keeps response logic isolated and maintainable
31+
- It is actively maintained and stable
32+
33+
### OpenAPI Request and Response Validation
34+
35+
We are using [Committee](https://github.com/interagent/committee) middleware to validate that API request and response payloads match the OpenAPI 3 specification at runtime. This gives us immediate feedback if responses drift from the specification.
36+
37+
In addition to runtime validation, we’re also using Committee in our request specs to ensure we're checking responses conform to the schema during automated testing.
38+
39+
We considered [rswag](https://github.com/rswag/rswag), but opted not to use it due to:
40+
41+
- Its focus on documentation and Swagger UI, which isn’t a priority right now
42+
- Its more complex setup and less intuitive behaviour for schema validation
43+
- Committee providing simpler, targeted validation of actual responses
44+
45+
## Status
46+
47+
**accepted**
48+
49+
## Consequences
50+
51+
- Developers will use Blueprinter to define API response formats
52+
- Request and response validation against the OpenAPI spec will happen at runtime via middleware, and in automated tests

0 commit comments

Comments
 (0)