Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

openapi.test.ts

27 lines1.0 KB

1import { describe, expect, it } from 'vitest'
2import { Validator } from '@cfworker/json-schema'
3​
4import type { Schema } from '@cfworker/json-schema'
5import metaSchema from './fixtures/oas-3.1-meta-schema.json'
6import { openApiDocument } from './openapi.ts'
7​
8describe('openApiDocument', () => {
9 it('validates against the OpenAPI 3.1 meta-schema', () => {
10 const validator = new Validator(metaSchema as Schema, '2020-12', false)
11 const result = validator.validate(openApiDocument)
12 expect(result.errors).toEqual([])
13 expect(result.valid).toBe(true)
14 })
15​
16 it('gives every operation a unique operationId', () => {
17 const ids: Array<string> = []
18 for (const pathItem of Object.values(openApiDocument.paths)) {
19 for (const operation of Object.values(pathItem)) {
20 ids.push((operation as { operationId: string }).operationId)
21 }
22 }
23 expect(ids.length).toBeGreaterThanOrEqual(12)
24 expect(new Set(ids).size).toBe(ids.length)
25 for (const id of ids) expect(id).toMatch(/^[a-zA-Z][a-zA-Z0-9]*$/)
26 })
27})