Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/melroy89/fastify-shared-definition-issue
Reproduction code for shared definitions for response object issue
https://github.com/melroy89/fastify-shared-definition-issue
fastify fastify-swagger swagger
Last synced: 2 months ago
JSON representation
Reproduction code for shared definitions for response object issue
- Host: GitHub
- URL: https://github.com/melroy89/fastify-shared-definition-issue
- Owner: melroy89
- Created: 2024-03-21T21:10:20.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-09-18T16:20:01.000Z (4 months ago)
- Last Synced: 2024-10-04T13:36:00.374Z (3 months ago)
- Topics: fastify, fastify-swagger, swagger
- Language: JavaScript
- Homepage:
- Size: 44.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reproducible repo for Fastify Shared Response schema
See code: `app.js` & `routes/root.js`
1. `npm install`
2. `npm run dev`
3. Go to: http://127.0.0.1:3000/docs
4. See error message appear in Swagger:```sh
Resolver error at paths./.get.responses.500.content.application/json.schema.$ref
Could not resolve reference: Could not resolve pointer: /components/schemas/def-0/definitions/internalServerErrorResponse does not exist in document
```(No errors appear in the console log)
Because Swagger is **NOT** built to use `definitions` via `addSchema` for response objects, instead Swagger is built to use `components` -> `responses` schemas for shared responses objects instead.
---
Swagger support `components` with `responses` this during OpenAPI spec definition (Fastify Swagger doesn't support this). Example ofa such an OpenAPI document:
```js
{
openapi: '3.0.0',
info: {
title: 'Example...'
},
components: {
responses: {
internalServerErrorResponse: {
description: "500 Internal Server Error",
content: {
"application/json": {
"schema": {
"type": "object",
}
}
}
}
}
}
}
```Such a component response object above could be used for reusability, if that was supported by Fastify Swagger.