Adding simple working validating test

This commit is contained in:
sinasab
2023-09-18 14:54:55 -07:00
parent 8eb03f05cf
commit d85581e3ab
3 changed files with 10 additions and 0 deletions
BIN
View File
Binary file not shown.
+1
View File
@@ -38,6 +38,7 @@
"elysia": ">= 0.7.0"
},
"devDependencies": {
"@apidevtools/swagger-parser": "^10.1.0",
"@types/node": "^20.1.4",
"bun-types": "^0.7.0",
"elysia": "0.7.10",
+9
View File
@@ -1,7 +1,9 @@
import { Elysia, t } from 'elysia'
import SwaggerParser from '@apidevtools/swagger-parser';
import { swagger } from '../src'
import { describe, expect, it } from 'bun:test'
import { fail } from 'assert';
const req = (path: string) => new Request(`http://localhost${path}`)
@@ -13,6 +15,13 @@ describe('Swagger', () => {
expect(res.status).toBe(200)
})
it('returns a valid Swagger/OpenAPI json config', async () => {
const app = new Elysia().use(swagger())
const res = await app.handle(req('/swagger/json')).then((x) => x.json());
expect(res.openapi).toBe("3.0.3");
await SwaggerParser.validate(res).catch((err) => fail(err));
});
it('use custom Swagger version', async () => {
const app = new Elysia().use(
swagger({