@atlassian/atlassian-openapi 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/swagger.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { Swagger } from './swagger';
2
+ export declare function pathsToOAS(paths: Swagger.Paths, tags?: Swagger.Tag[]): Swagger.SwaggerV3;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pathsToOAS = void 0;
4
+ function pathsToOAS(paths, tags) {
5
+ return {
6
+ openapi: '3.0.0',
7
+ info: {
8
+ title: 'Test Swagger File',
9
+ version: '1'
10
+ },
11
+ paths,
12
+ tags
13
+ };
14
+ }
15
+ exports.pathsToOAS = pathsToOAS;
@@ -0,0 +1,33 @@
1
+ import { Swagger as S, Swagger } from './swagger';
2
+ export declare namespace SwaggerTypeChecks {
3
+ function isPrimitiveType(t: S.SchemaType): boolean;
4
+ function isMediaTypeWithExamples(t: S.MediaType): t is S.MediaTypeWithExamples;
5
+ function isParameter(p: any): p is S.Parameter;
6
+ function isParameterWithSchema(p: any): p is S.ParameterWithSchema;
7
+ function isParameterWithContent(p: any): p is S.ParameterWithContent;
8
+ function isReference(s: any): s is S.Reference;
9
+ function isSchema(s: any): s is S.Schema;
10
+ function isRequestBody(b: any): b is S.RequestBody;
11
+ function isExample(e: any): e is S.Example;
12
+ function isPathItem(o: any): o is S.PathItem;
13
+ function isCallback(o: any): o is S.Callback;
14
+ function isHeaderWithSchema(o: any): o is S.HeaderWithSchema;
15
+ function isHeaderWithContent(o: any): o is S.HeaderWithContent;
16
+ function isHeader(o: any): o is S.Header;
17
+ function isLinkWithOperationRef(o: any): o is S.LinkWithOperationRef;
18
+ function isLinkWithOperationId(o: any): o is S.LinkWithOperationId;
19
+ function isLink(o: any): o is S.Link;
20
+ function isResponse(o: any): o is S.Response;
21
+ function isApiKeySecurityScheme(o: any): o is S.ApiKeySecurityScheme;
22
+ function isNonBearerHTTPSecurityScheme(o: any): o is S.NonBearerHttpSecurityScheme;
23
+ function isBearerHttpSecurityScheme(o: any): o is S.BearerHttpSecurityScheme;
24
+ function isOAuth2SecurityScheme(o: any): o is S.OAuth2SecurityScheme;
25
+ function isOpenIdConnectSecurityScheme(o: any): o is S.OpenIdConnectSecurityScheme;
26
+ function isHttpSecurityScheme(o: any): o is S.HttpSecurityScheme;
27
+ function isSecurityScheme(o: any): o is S.SecurityScheme;
28
+ function isPathParam(p: Swagger.Parameter): p is (Swagger.ParameterWithSchemaWithExampleInPath | Swagger.ParameterWithSchemaWithExamplesInPath | Swagger.ParameterWithContentInPath);
29
+ function isOAuth2ScopesArray(o: NonNullable<Swagger.Operation['x-atlassian-oauth2-scopes']>): o is Array<Swagger.OAuth2Scopes>;
30
+ function isOAuth2ScopesWithStateArray(o: NonNullable<Swagger.Operation['x-atlassian-oauth2-scopes']>): o is Array<Swagger.OAuth2ScopesWithState>;
31
+ function isOAuth2Scopes(o: Swagger.OAuth2Scopes | Swagger.OAuth2ScopesWithState): o is Swagger.OAuth2Scopes;
32
+ function isOAuth2ScopesWithState(o: Swagger.OAuth2Scopes | Swagger.OAuth2ScopesWithState): o is Swagger.OAuth2ScopesWithState;
33
+ }
@@ -0,0 +1,380 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SwaggerTypeChecks = void 0;
4
+ var SwaggerTypeChecks;
5
+ (function (SwaggerTypeChecks) {
6
+ function isPrimitiveType(t) {
7
+ return t === 'boolean' || t === 'integer' || t === 'number' || t === 'string';
8
+ }
9
+ SwaggerTypeChecks.isPrimitiveType = isPrimitiveType;
10
+ function isMediaTypeWithExamples(t) {
11
+ return 'examples' in t;
12
+ }
13
+ SwaggerTypeChecks.isMediaTypeWithExamples = isMediaTypeWithExamples;
14
+ // tslint:disable-next-line:no-any
15
+ function matchesObjectShape(o, allKeys, requiredKeys) {
16
+ if (typeof o !== 'object') {
17
+ return false;
18
+ }
19
+ const nonExtensionKeys = removeExtensions(Object.keys(o));
20
+ const keysMatch = nonExtensionKeys.every(key => allKeys.has(key));
21
+ const hasRequiredKeys = typeof requiredKeys === 'undefined' ||
22
+ requiredKeys.every(rk => !!nonExtensionKeys.find(k => k === rk));
23
+ return keysMatch && hasRequiredKeys;
24
+ }
25
+ const parameterWithSchemaRequiredKeys = [
26
+ 'name',
27
+ 'in',
28
+ 'schema'
29
+ ];
30
+ const parameterWithSchemaOptionalKeys = [
31
+ 'description',
32
+ 'deprecated',
33
+ 'allowEmptyValue',
34
+ 'required',
35
+ 'style',
36
+ 'explode',
37
+ 'allowReserved',
38
+ 'example',
39
+ 'examples'
40
+ ];
41
+ const parameterWithContentRequiredKeys = [
42
+ 'name',
43
+ 'in',
44
+ 'content'
45
+ ];
46
+ const parameterWithContentOptionalKeys = [
47
+ 'description',
48
+ 'required',
49
+ 'deprecated',
50
+ 'allowEmptyValue'
51
+ ];
52
+ // tslint:disable-next-line:no-any
53
+ function isParameter(p) {
54
+ return isParameterWithSchema(p) || isParameterWithContent(p);
55
+ }
56
+ SwaggerTypeChecks.isParameter = isParameter;
57
+ // tslint:disable-next-line:no-any
58
+ function isParameterWithSchema(p) {
59
+ if (typeof p !== 'object') {
60
+ return false;
61
+ }
62
+ const nonExtensionKeys = removeExtensions(Object.keys(p));
63
+ const isParameterWithSchemaKey = (key) => !!parameterWithSchemaRequiredKeys.find(k => k === key) ||
64
+ !!parameterWithSchemaOptionalKeys.find(k => k === key);
65
+ const keysMatch = nonExtensionKeys.every(isParameterWithSchemaKey);
66
+ const requiredKeysPresent = parameterWithSchemaRequiredKeys.every(key => !!nonExtensionKeys.find(k => k === key));
67
+ return keysMatch && requiredKeysPresent;
68
+ }
69
+ SwaggerTypeChecks.isParameterWithSchema = isParameterWithSchema;
70
+ // tslint:disable-next-line:no-any
71
+ function isParameterWithContent(p) {
72
+ if (typeof p !== 'object') {
73
+ return false;
74
+ }
75
+ const nonExtensionKeys = removeExtensions(Object.keys(p));
76
+ const isParameterWithSchemaKey = (key) => !!parameterWithContentRequiredKeys.find(k => k === key) ||
77
+ !!parameterWithContentOptionalKeys.find(k => k === key);
78
+ const keysMatch = nonExtensionKeys.every(isParameterWithSchemaKey);
79
+ const requiredKeysPresent = parameterWithContentRequiredKeys.every(key => !!nonExtensionKeys.find(k => k === key));
80
+ return keysMatch && requiredKeysPresent;
81
+ }
82
+ SwaggerTypeChecks.isParameterWithContent = isParameterWithContent;
83
+ // tslint:disable-next-line:no-any
84
+ function isReference(s) {
85
+ return typeof s === 'object' && '$ref' in s;
86
+ }
87
+ SwaggerTypeChecks.isReference = isReference;
88
+ const schemaStandardKeys = new Set([
89
+ 'title',
90
+ 'multipleOf',
91
+ 'maximum',
92
+ 'exclusiveMaximum',
93
+ 'minimum',
94
+ 'exclusiveMinimum',
95
+ 'maxLength',
96
+ 'minLength',
97
+ 'pattern',
98
+ 'maxItems',
99
+ 'minItems',
100
+ 'uniqueItems',
101
+ 'maxProperties',
102
+ 'minProperties',
103
+ 'required',
104
+ 'enum',
105
+ 'type',
106
+ 'not',
107
+ 'allOf',
108
+ 'oneOf',
109
+ 'anyOf',
110
+ 'items',
111
+ 'properties',
112
+ 'additionalProperties',
113
+ 'description',
114
+ 'format',
115
+ 'default',
116
+ 'nullable',
117
+ 'discriminator',
118
+ 'readOnly',
119
+ 'writeOnly',
120
+ 'example',
121
+ 'externalDocs',
122
+ 'deprecated',
123
+ 'xml'
124
+ ]);
125
+ function removeExtensions(keys) {
126
+ return keys.filter(k => !k.startsWith('x-'));
127
+ }
128
+ // tslint:disable-next-line:no-any
129
+ function isSchema(s) {
130
+ return matchesObjectShape(s, schemaStandardKeys);
131
+ }
132
+ SwaggerTypeChecks.isSchema = isSchema;
133
+ const requestBodyKeys = new Set([
134
+ 'description',
135
+ 'content',
136
+ 'required'
137
+ ]);
138
+ const requiredRequestBodyKeys = [
139
+ 'content'
140
+ ];
141
+ // tslint:disable-next-line:no-any
142
+ function isRequestBody(b) {
143
+ return matchesObjectShape(b, requestBodyKeys, requiredRequestBodyKeys);
144
+ }
145
+ SwaggerTypeChecks.isRequestBody = isRequestBody;
146
+ const optionalExampleKeys = new Set([
147
+ 'summary',
148
+ 'description',
149
+ 'value',
150
+ 'externalValue'
151
+ ]);
152
+ // tslint:disable-next-line:no-any
153
+ function isExample(e) {
154
+ return matchesObjectShape(e, optionalExampleKeys);
155
+ }
156
+ SwaggerTypeChecks.isExample = isExample;
157
+ const optionalPathItemKeys = new Set([
158
+ '$ref',
159
+ 'summary',
160
+ 'description',
161
+ 'get',
162
+ 'put',
163
+ 'post',
164
+ 'delete',
165
+ 'options',
166
+ 'head',
167
+ 'patch',
168
+ 'trace',
169
+ 'servers',
170
+ 'parameters'
171
+ ]);
172
+ // tslint:disable-next-line:no-any
173
+ function isPathItem(o) {
174
+ return matchesObjectShape(o, optionalPathItemKeys);
175
+ }
176
+ SwaggerTypeChecks.isPathItem = isPathItem;
177
+ // tslint:disable-next-line:no-any
178
+ function isCallback(o) {
179
+ if (typeof o !== 'object') {
180
+ return false;
181
+ }
182
+ // Every key in the object must point to a path-item
183
+ const nonExtensionKeys = removeExtensions(Object.keys(o));
184
+ return nonExtensionKeys.every(key => isPathItem(o[key]));
185
+ }
186
+ SwaggerTypeChecks.isCallback = isCallback;
187
+ const headerWithSchemaKeys = new Set([
188
+ 'description',
189
+ 'required',
190
+ 'deprecated',
191
+ 'allowEmptyValue',
192
+ 'style',
193
+ 'explode',
194
+ 'allowReserved',
195
+ 'schema',
196
+ 'example',
197
+ 'examples'
198
+ ]);
199
+ const headerWithSchemaRequiredKeys = [
200
+ 'schema'
201
+ ];
202
+ // tslint:disable-next-line:no-any
203
+ function isHeaderWithSchema(o) {
204
+ return matchesObjectShape(o, headerWithSchemaKeys, headerWithSchemaRequiredKeys);
205
+ }
206
+ SwaggerTypeChecks.isHeaderWithSchema = isHeaderWithSchema;
207
+ const headerWithContentKeys = new Set([
208
+ 'description',
209
+ 'required',
210
+ 'deprecated',
211
+ 'allowEmptyValue',
212
+ 'content'
213
+ ]);
214
+ const headerWithContentRequiredKeys = [
215
+ 'content'
216
+ ];
217
+ // tslint:disable-next-line:no-any
218
+ function isHeaderWithContent(o) {
219
+ return matchesObjectShape(o, headerWithContentKeys, headerWithContentRequiredKeys);
220
+ }
221
+ SwaggerTypeChecks.isHeaderWithContent = isHeaderWithContent;
222
+ // tslint:disable-next-line:no-any
223
+ function isHeader(o) {
224
+ return isHeaderWithSchema(o) || isHeaderWithContent(o);
225
+ }
226
+ SwaggerTypeChecks.isHeader = isHeader;
227
+ const optionalLinkWithOperationRefKeys = new Set([
228
+ 'operationRef',
229
+ 'parameters',
230
+ 'requestBody',
231
+ 'description',
232
+ 'server'
233
+ ]);
234
+ // tslint:disable-next-line:no-any
235
+ function isLinkWithOperationRef(o) {
236
+ return matchesObjectShape(o, optionalLinkWithOperationRefKeys);
237
+ }
238
+ SwaggerTypeChecks.isLinkWithOperationRef = isLinkWithOperationRef;
239
+ const optionalLinkWithOperationIdKeys = new Set([
240
+ 'operationId',
241
+ 'parameters',
242
+ 'requestBody',
243
+ 'description',
244
+ 'server'
245
+ ]);
246
+ // tslint:disable-next-line:no-any
247
+ function isLinkWithOperationId(o) {
248
+ return matchesObjectShape(o, optionalLinkWithOperationIdKeys);
249
+ }
250
+ SwaggerTypeChecks.isLinkWithOperationId = isLinkWithOperationId;
251
+ // tslint:disable-next-line:no-any
252
+ function isLink(o) {
253
+ return isLinkWithOperationId(o) || isLinkWithOperationRef(o);
254
+ }
255
+ SwaggerTypeChecks.isLink = isLink;
256
+ const responseKeys = new Set([
257
+ 'description',
258
+ 'headers',
259
+ 'content',
260
+ 'links'
261
+ ]);
262
+ const requiredResponseKeys = [
263
+ 'description'
264
+ ];
265
+ // tslint:disable-next-line:no-any
266
+ function isResponse(o) {
267
+ return matchesObjectShape(o, responseKeys, requiredResponseKeys);
268
+ }
269
+ SwaggerTypeChecks.isResponse = isResponse;
270
+ const apiKeySecuritySchemeKeys = new Set([
271
+ 'type',
272
+ 'name',
273
+ 'in',
274
+ 'description'
275
+ ]);
276
+ const apiKeySecuritySchemeRequiredKeys = [
277
+ 'type',
278
+ 'name',
279
+ 'in'
280
+ ];
281
+ // tslint:disable-next-line:no-any
282
+ function isApiKeySecurityScheme(o) {
283
+ return matchesObjectShape(o, apiKeySecuritySchemeKeys, apiKeySecuritySchemeRequiredKeys);
284
+ }
285
+ SwaggerTypeChecks.isApiKeySecurityScheme = isApiKeySecurityScheme;
286
+ const nonBearerHttpSecuritySchemeKeys = new Set([
287
+ 'scheme',
288
+ 'description',
289
+ 'type'
290
+ ]);
291
+ const nonBearerHttpSecuritySchemeRequiredKeys = [
292
+ 'scheme',
293
+ 'type'
294
+ ];
295
+ // tslint:disable-next-line:no-any
296
+ function isNonBearerHTTPSecurityScheme(o) {
297
+ return matchesObjectShape(o, nonBearerHttpSecuritySchemeKeys, nonBearerHttpSecuritySchemeRequiredKeys) && o.scheme !== 'bearer';
298
+ }
299
+ SwaggerTypeChecks.isNonBearerHTTPSecurityScheme = isNonBearerHTTPSecurityScheme;
300
+ const bearerHttpSecuritySchemeKeys = new Set([
301
+ 'scheme',
302
+ 'bearerFormat',
303
+ 'type',
304
+ 'description'
305
+ ]);
306
+ const bearerHttpSecuritySchemeRequiredKeys = [
307
+ 'type',
308
+ 'scheme'
309
+ ];
310
+ // tslint:disable-next-line:no-any
311
+ function isBearerHttpSecurityScheme(o) {
312
+ return matchesObjectShape(o, bearerHttpSecuritySchemeKeys, bearerHttpSecuritySchemeRequiredKeys) && o.scheme === 'bearer';
313
+ }
314
+ SwaggerTypeChecks.isBearerHttpSecurityScheme = isBearerHttpSecurityScheme;
315
+ const oauth2SecuritySchemeKeys = new Set([
316
+ 'type',
317
+ 'flows',
318
+ 'description'
319
+ ]);
320
+ const oauth2SecuritySchemeRequiredKeys = [
321
+ 'type',
322
+ 'flows'
323
+ ];
324
+ // tslint:disable-next-line:no-any
325
+ function isOAuth2SecurityScheme(o) {
326
+ return matchesObjectShape(o, oauth2SecuritySchemeKeys, oauth2SecuritySchemeRequiredKeys);
327
+ }
328
+ SwaggerTypeChecks.isOAuth2SecurityScheme = isOAuth2SecurityScheme;
329
+ const openIdConnectSecuritySchemeKeys = new Set([
330
+ 'type',
331
+ 'openIdConnectUrl',
332
+ 'description'
333
+ ]);
334
+ const openIdConnectSecuritySchemeRequiredKeys = [
335
+ 'type',
336
+ 'openIdConnectUrl'
337
+ ];
338
+ // tslint:disable-next-line:no-any
339
+ function isOpenIdConnectSecurityScheme(o) {
340
+ return matchesObjectShape(o, openIdConnectSecuritySchemeKeys, openIdConnectSecuritySchemeRequiredKeys);
341
+ }
342
+ SwaggerTypeChecks.isOpenIdConnectSecurityScheme = isOpenIdConnectSecurityScheme;
343
+ // tslint:disable-next-line:no-any
344
+ function isHttpSecurityScheme(o) {
345
+ return isBearerHttpSecurityScheme(o) || isNonBearerHTTPSecurityScheme(o);
346
+ }
347
+ SwaggerTypeChecks.isHttpSecurityScheme = isHttpSecurityScheme;
348
+ // tslint:disable-next-line:no-any
349
+ function isSecurityScheme(o) {
350
+ return isApiKeySecurityScheme(o)
351
+ || isBearerHttpSecurityScheme(o)
352
+ || isNonBearerHTTPSecurityScheme(o)
353
+ || isOAuth2SecurityScheme(o)
354
+ || isOpenIdConnectSecurityScheme(o);
355
+ }
356
+ SwaggerTypeChecks.isSecurityScheme = isSecurityScheme;
357
+ function isPathParam(p) {
358
+ return p.in === 'path';
359
+ }
360
+ SwaggerTypeChecks.isPathParam = isPathParam;
361
+ // tslint:disable-next-line:max-line-length
362
+ function isOAuth2ScopesArray(o) {
363
+ return o.every(isOAuth2Scopes);
364
+ }
365
+ SwaggerTypeChecks.isOAuth2ScopesArray = isOAuth2ScopesArray;
366
+ // tslint:disable-next-line:max-line-length
367
+ function isOAuth2ScopesWithStateArray(o) {
368
+ return o.every(isOAuth2ScopesWithState);
369
+ }
370
+ SwaggerTypeChecks.isOAuth2ScopesWithStateArray = isOAuth2ScopesWithStateArray;
371
+ function isOAuth2Scopes(o) {
372
+ return 'deprecated' in o;
373
+ }
374
+ SwaggerTypeChecks.isOAuth2Scopes = isOAuth2Scopes;
375
+ // tslint:disable-next-line:max-line-length
376
+ function isOAuth2ScopesWithState(o) {
377
+ return 'state' in o;
378
+ }
379
+ SwaggerTypeChecks.isOAuth2ScopesWithState = isOAuth2ScopesWithState;
380
+ })(SwaggerTypeChecks = exports.SwaggerTypeChecks || (exports.SwaggerTypeChecks = {}));
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@atlassian/atlassian-openapi",
3
+ "version": "1.0.3",
4
+ "description": "This is a package that lets you deal with the Atlassian flavour of the OpenAPI 3.0 specification.",
5
+ "repository": "github:robertmassaioli/atlassian-openapi",
6
+ "publishConfig": {
7
+ "registry": "https://packages.atlassian.com/api/npm/npm-public/"
8
+ },
9
+ "keywords": [
10
+ "atlassian",
11
+ "openapi",
12
+ "swagger"
13
+ ],
14
+ "author": "Robert Massaioli",
15
+ "license": "MIT",
16
+ "main": "lib/index",
17
+ "typings": "lib/index",
18
+ "files": [
19
+ "lib/**",
20
+ "swagger.v3.json"
21
+ ],
22
+ "scripts": {
23
+ "test": "jest",
24
+ "test-watch": "jest --watch",
25
+ "lint": "tslint 'src/**/*.ts*'",
26
+ "build": "tsc --project .",
27
+ "prepare": "npm run build"
28
+ },
29
+ "dependencies": {
30
+ "jsonpointer": "^5.0.0",
31
+ "urijs": "^1.19.10"
32
+ },
33
+ "devDependencies": {
34
+ "@types/jest": "^23.3.14",
35
+ "@types/urijs": "^1.15.33",
36
+ "husky": "^3.0.5",
37
+ "jest": "^23.6.0",
38
+ "ts-jest": "^24.1.0",
39
+ "ts-node": "^8.4.1",
40
+ "tslint": "^5.10.0",
41
+ "typescript": "^3.7"
42
+ },
43
+ "husky": {
44
+ "hooks": {
45
+ "pre-commit": "npm run lint"
46
+ }
47
+ }
48
+ }