|
| 1 | +import { type OpenAPIV2, type OpenAPIV3 } from 'openapi-types' |
| 2 | +import { expect } from 'tstyche' |
| 3 | +import '..' |
| 4 | + |
| 5 | +expect<OpenAPIV3.Document>() |
| 6 | + .type.toBeAssignableFrom({ |
| 7 | + openapi: '3.0.0', |
| 8 | + info: { |
| 9 | + version: '1.0.0', |
| 10 | + title: 'Test OpenApiv3 specification' |
| 11 | + }, |
| 12 | + components: { |
| 13 | + securitySchemes: { |
| 14 | + myAuth: { |
| 15 | + type: 'oauth2' as const, |
| 16 | + 'x-tokenName': 'id_token', |
| 17 | + flows: { |
| 18 | + implicit: { |
| 19 | + authorizationUrl: 'http.../login/oauth/authorize', |
| 20 | + scopes: {} |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + }, |
| 26 | + paths: {} |
| 27 | + }) |
| 28 | + |
| 29 | +expect<OpenAPIV2.Document>().type.toBeAssignableFrom({ |
| 30 | + swagger: '2.0.0', |
| 31 | + info: { |
| 32 | + title: 'Test OpenApiv2 specification', |
| 33 | + version: '2.0.0' |
| 34 | + }, |
| 35 | + securityDefinitions: { |
| 36 | + OAuth2AccessCodeFlow: { |
| 37 | + type: 'oauth2' as const, |
| 38 | + flow: 'accessCode' as const, |
| 39 | + authorizationUrl: 'https://example.com/oauth/authorize', |
| 40 | + tokenUrl: 'https://example.com/oauth/token', |
| 41 | + 'x-tokenName': 'id_token', |
| 42 | + scopes: {} |
| 43 | + }, |
| 44 | + OAuth2ApplicationFlow: { |
| 45 | + type: 'oauth2' as const, |
| 46 | + flow: 'application' as const, |
| 47 | + tokenUrl: 'https://example.com/oauth/token', |
| 48 | + 'x-tokenName': 'id_token', |
| 49 | + scopes: {} |
| 50 | + }, |
| 51 | + OAuth2ImplicitFlow: { |
| 52 | + type: 'oauth2' as const, |
| 53 | + flow: 'implicit' as const, |
| 54 | + authorizationUrl: 'https://example.com/oauth/authorize', |
| 55 | + 'x-tokenName': 'id_token', |
| 56 | + scopes: {} |
| 57 | + }, |
| 58 | + OAuth2PasswordFlow: { |
| 59 | + type: 'oauth2' as const, |
| 60 | + flow: 'password' as const, |
| 61 | + tokenUrl: 'https://example.com/oauth/token', |
| 62 | + 'x-tokenName': 'id_token', |
| 63 | + scopes: {} |
| 64 | + } |
| 65 | + }, |
| 66 | + paths: {} |
| 67 | +}) |
| 68 | + |
| 69 | +expect<OpenAPIV2.Document>() |
| 70 | + .type.toBeAssignableFrom({ |
| 71 | + swagger: '2.0.0', |
| 72 | + info: { |
| 73 | + title: 'Test OpenApiv2 specification', |
| 74 | + version: '2.0.0' |
| 75 | + }, |
| 76 | + paths: { |
| 77 | + '/users/{userId}': { |
| 78 | + get: { |
| 79 | + summary: 'Gets a user by ID.', |
| 80 | + responses: {}, |
| 81 | + parameters: [ |
| 82 | + { |
| 83 | + in: 'path', |
| 84 | + name: 'userId', |
| 85 | + type: 'integer', |
| 86 | + required: true, |
| 87 | + description: 'Numeric ID of the user to get.', |
| 88 | + 'x-example': 'BADC0FFEE' |
| 89 | + }, |
| 90 | + { |
| 91 | + in: 'query', |
| 92 | + name: 'offset', |
| 93 | + type: 'integer', |
| 94 | + description: |
| 95 | + 'The number of items to skip before starting to collect the result set.', |
| 96 | + 'x-example': 1337 |
| 97 | + }, |
| 98 | + { |
| 99 | + in: 'header', |
| 100 | + name: 'X-Request-ID', |
| 101 | + type: 'string', |
| 102 | + required: true, |
| 103 | + 'x-example': 'wget' |
| 104 | + }, |
| 105 | + { |
| 106 | + in: 'formData', |
| 107 | + name: 'name', |
| 108 | + type: 'string', |
| 109 | + description: "A person's name.", |
| 110 | + 'x-example': 'John Doe' |
| 111 | + } |
| 112 | + ] |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + }) |
0 commit comments