-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry-me.ts
49 lines (39 loc) · 2.11 KB
/
try-me.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import SwaggerParser from "@apidevtools/swagger-parser"
import models from './test/models'
import schemaWrapper from './test/openapi-validation-wrapper'
import { SchemaManager, OpenApiStrategy } from './src'
const schemaManager = new SchemaManager
const openapiStrategy = new OpenApiStrategy
const userSchema = schemaManager.generate(models.User, openapiStrategy)
schemaWrapper.components.schemas.user = userSchema
schemaWrapper.components.schemas.profile = schemaManager.generate(models.Profile, openapiStrategy)
schemaWrapper.components.schemas.document = schemaManager.generate(models.Document, openapiStrategy)
schemaWrapper.components.schemas.company = schemaManager.generate(models.Company, openapiStrategy)
schemaWrapper.components.schemas.friendship = schemaManager.generate(models.Friendship, openapiStrategy)
schemaWrapper.components.schemas.group = schemaManager.generate(models.Group, openapiStrategy)
schemaWrapper.components.schemas.usergroup = schemaManager.generate(models.UserGroup, openapiStrategy)
console.log('OpenAPI Schema', JSON.stringify(schemaWrapper, null, 4))
;(async function() {
try {
console.log('Validating generated full schema against swagger-parser...');
const wrapper = structuredClone(schemaWrapper)
const user = wrapper.components.schemas.user
/*
* These have non-standard validation properties specific to AJV
*/
delete user.properties.STRING_IS
delete user.properties.STRING_IS_STRING
delete user.properties.STRING_IS_ARGED_STRING
delete user.properties.STRING_IS_ARGED_REGEXP
delete user.properties.STRING_IS_ARRAY
delete user.properties.STRING_NOT
delete user.properties.STRING_NOT_STRING
delete user.properties.STRING_NOT_ARGED_STRING
delete user.properties.STRING_NOT_ARGED_REGEXP
delete user.properties.STRING_NOT_ARRAY
const api = await SwaggerParser.validate(Object.assign({}, wrapper))
console.log('Wrapper passed OpenAPI validation: API name: %s, Version: %s', api.info.title, api.info.version)
} catch(err) {
console.log(err)
}
})()