Skip to content

Add middleware for validating responses against OpenAPI schema - #311

Open
Carifio24 wants to merge 11 commits into
cosmicds:mainfrom
Carifio24:openapi-validator
Open

Add middleware for validating responses against OpenAPI schema#311
Carifio24 wants to merge 11 commits into
cosmicds:mainfrom
Carifio24:openapi-validator

Conversation

@Carifio24

@Carifio24 Carifio24 commented Aug 11, 2026

Copy link
Copy Markdown
Member

This PR adds something that I've wanted to do since I added in the OpenAPI documentation in #265, which is to add a way to validate the format of each response against what the docstring spec declares for that endpoint. This is done in the form of a middleware using express-openapi-validator.

Because our spec file is generated dynamically from the docstring comments, this required a bit of finagling so that we can get the order of generate the spec -> create the middleware -> create the endpoints to happen correctly. It also necessitates building the app before running the test suite. Adding this in also exposed several places where the OpenAPI docstring comments were incorrect. This PR makes some fixes to the comments, as well as cleans up the actual responses for both consistency and to more easily satisfy the spec.

The OpenAPI validator here is quite strict, so I don't think we want this in production - we don't have to return a 500 because of some minor spec mismatch. But it's very nice for testing purposes, so this PR sets this middleware to only be attached if NODE_ENV is set to "test". Overall this should help ensure that our actual API functionality and our OpenAPI spec are in agreement.

@Carifio24 Carifio24 linked an issue Aug 15, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add testing of OpenAPI spec

1 participant