@appland/appmap 3.19.0 → 3.20.0

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/built/appmap.html +1 -1
  3. package/built/main.js.map +1 -1
  4. package/built/package.json +2 -1
  5. package/built/src/openapi/command.js +33 -17
  6. package/built/src/openapi/command.js.map +1 -1
  7. package/built/src/openapi/index.js +28 -0
  8. package/built/src/openapi/index.js.map +1 -0
  9. package/built/src/openapi/method.js +54 -49
  10. package/built/src/openapi/method.js.map +1 -1
  11. package/built/src/openapi/model.js +19 -22
  12. package/built/src/openapi/model.js.map +1 -1
  13. package/built/src/openapi/objectSchema.js +47 -0
  14. package/built/src/openapi/objectSchema.js.map +1 -0
  15. package/built/src/openapi/parseHTTPServerRequests.js +11 -0
  16. package/built/src/openapi/parseHTTPServerRequests.js.map +1 -0
  17. package/built/src/openapi/path.js +13 -14
  18. package/built/src/openapi/path.js.map +1 -1
  19. package/built/src/openapi/provider.js +73 -0
  20. package/built/src/openapi/provider.js.map +1 -0
  21. package/built/src/openapi/response.js +37 -13
  22. package/built/src/openapi/response.js.map +1 -1
  23. package/built/src/openapi/rpcRequest.js +87 -0
  24. package/built/src/openapi/rpcRequest.js.map +1 -0
  25. package/built/src/openapi/schemaInferrer.js +59 -0
  26. package/built/src/openapi/schemaInferrer.js.map +1 -0
  27. package/built/src/openapi/securitySchemes.js +14 -39
  28. package/built/src/openapi/securitySchemes.js.map +1 -1
  29. package/built/src/openapi/statusCodes.js +68 -0
  30. package/built/src/openapi/statusCodes.js.map +1 -0
  31. package/built/src/openapi/util.js +67 -47
  32. package/built/src/openapi/util.js.map +1 -1
  33. package/package.json +2 -1
  34. package/built/src/openapi/schema.js +0 -34
  35. package/built/src/openapi/schema.js.map +0 -1
  36. package/built/src/openapi/settings.js +0 -10
  37. package/built/src/openapi/settings.js.map +0 -1
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const js_yaml_1 = require("js-yaml");
7
+ const url_1 = require("url");
8
+ const http_1 = __importDefault(require("http"));
9
+ const https_1 = __importDefault(require("https"));
10
+ const promises_1 = require("fs/promises");
11
+ const URLLoader = (protocol) => {
12
+ return (url) => {
13
+ return new Promise((resolve, reject) => {
14
+ protocol
15
+ .get(url)
16
+ .on('response', (response) => {
17
+ if (response.statusCode !== 200) {
18
+ return reject(`${response.statusCode} ${response.statusMessage}`);
19
+ }
20
+ const data = [];
21
+ response
22
+ .on('data', (chunk) => {
23
+ data.push(Buffer.from(chunk));
24
+ })
25
+ .on('end', () => {
26
+ resolve(Buffer.concat(data));
27
+ });
28
+ })
29
+ .on('error', reject);
30
+ });
31
+ };
32
+ };
33
+ const FileLoader = (url) => {
34
+ return (0, promises_1.readFile)(url.pathname);
35
+ };
36
+ const ProtocolLoader = {
37
+ 'http:': URLLoader(http_1.default),
38
+ 'https:': URLLoader(https_1.default),
39
+ 'file:': FileLoader,
40
+ };
41
+ const fetch = (urlStr) => {
42
+ const url = new url_1.URL(urlStr);
43
+ const loader = ProtocolLoader[url.protocol];
44
+ if (!loader) {
45
+ throw new Error(`No schema loader for protocol ${url.protocol}`);
46
+ }
47
+ return loader(url);
48
+ };
49
+ const SchemaCache = {};
50
+ const schemaCache = async (key, fn) => {
51
+ const cachedResult = SchemaCache[key];
52
+ if (cachedResult) {
53
+ return cachedResult;
54
+ }
55
+ const result = await fn(key);
56
+ SchemaCache[key] = result;
57
+ return result;
58
+ };
59
+ const fetchSchema = async (sourceURL) => {
60
+ return schemaCache(sourceURL, async (sourceURL) => {
61
+ const data = await fetch(sourceURL);
62
+ return (0, js_yaml_1.load)(data.toString());
63
+ });
64
+ };
65
+ const lookup = async (host, openapiSchemata) => {
66
+ const sourceURL = openapiSchemata[host];
67
+ if (!sourceURL) {
68
+ throw new Error(`No OpenAPI schema URL configured for host ${host}. Available hosts are: ${Object.keys(openapiSchemata).join(', ')}`);
69
+ }
70
+ return await fetchSchema(sourceURL);
71
+ };
72
+ exports.default = lookup;
73
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/openapi/provider.ts"],"names":[],"mappings":";;;;;AAAA,qCAA+B;AAC/B,6BAA0B;AAE1B,gDAA6C;AAC7C,kDAA0B;AAC1B,0CAAuC;AAIvC,MAAM,SAAS,GAAG,CAAC,QAAa,EAAE,EAAE;IAClC,OAAO,CAAC,GAAQ,EAAmB,EAAE;QACnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,QAAQ;iBACL,GAAG,CAAC,GAAG,CAAC;iBACR,EAAE,CAAC,UAAU,EAAE,CAAC,QAAyB,EAAE,EAAE;gBAC5C,IAAI,QAAQ,CAAC,UAAU,KAAK,GAAG,EAAE;oBAC/B,OAAO,MAAM,CAAC,GAAG,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;iBACnE;gBAED,MAAM,IAAI,GAAa,EAAE,CAAC;gBAC1B,QAAQ;qBACL,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;oBAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBAChC,CAAC,CAAC;qBACD,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;oBACd,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC/B,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;iBACD,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,UAAU,GAAG,CAA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AAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,KAAK,EAClB,IAAY,EACZ,eAAuC,EACV,EAAE;IAC/B,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACxC,IAAI,CAAC,SAAS,EAAE;QACd,MAAM,IAAI,KAAK,CACb,6CAA6C,IAAI,0BAA0B,MAAM,CAAC,IAAI,CACpF,eAAe,CAChB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACf,CAAC;KACH;IACD,OAAO,MAAM,WAAW,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
@@ -1,29 +1,53 @@
1
1
  "use strict";
2
- const { STATUS_CODES } = require('http');
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const statusCodes_1 = __importDefault(require("./statusCodes"));
7
+ const schemaInferrer_1 = __importDefault(require("./schemaInferrer"));
3
8
  class Response {
4
9
  constructor(statusCode) {
5
- this.statusCode = parseInt(`${statusCode}`, 10);
6
- this.events = [];
10
+ this.statusCode = statusCode;
11
+ this.rpcRequests = [];
7
12
  }
8
13
  openapi() {
9
14
  // eslint-disable-next-line arrow-body-style
10
- const mimeTypes = () => {
11
- return this.events
12
- .filter((event) => event.httpServerResponse && event.responseContentType)
13
- .map((event) => event.responseContentType.split(';')[0]);
15
+ const contentTypes = () => {
16
+ return this.rpcRequests
17
+ .map((rpcRequest) => rpcRequest.responseContentType)
18
+ .filter((ct) => ct)
19
+ .map((ct) => ct.split(';')[0]);
14
20
  };
15
- const content = [...new Set(mimeTypes())]
21
+ const schemata = {};
22
+ this.rpcRequests.forEach((rpcRequest) => {
23
+ const returnValue = rpcRequest.returnValue;
24
+ if (!returnValue)
25
+ return;
26
+ if (rpcRequest.responseContentType) {
27
+ const mimeType = rpcRequest.responseContentType.split(';')[0];
28
+ if (!schemata[mimeType]) {
29
+ schemata[mimeType] = new schemaInferrer_1.default();
30
+ }
31
+ schemata[mimeType].addExample(returnValue);
32
+ }
33
+ });
34
+ const content = [...new Set(contentTypes())]
16
35
  .sort()
17
36
  .reduce((memo, mimeType) => {
18
- // eslint-disable-next-line no-param-reassign
19
37
  memo[mimeType] = {};
38
+ if (!schemata[mimeType])
39
+ return memo;
40
+ // eslint-disable-next-line no-param-reassign
41
+ const schema = schemata[mimeType].openapi();
42
+ if (schema)
43
+ memo[mimeType].schema = schema;
20
44
  return memo;
21
45
  }, {});
22
- return { content, description: STATUS_CODES[this.statusCode] };
46
+ return { content, description: statusCodes_1.default[this.statusCode] };
23
47
  }
24
- addRequest(event) {
25
- this.events.push(event);
48
+ addRpcRequest(rpcRequest) {
49
+ this.rpcRequests.push(rpcRequest);
26
50
  }
27
51
  }
28
- module.exports = Response;
52
+ exports.default = Response;
29
53
  //# sourceMappingURL=response.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"response.js","sourceRoot":"","sources":["../../../src/openapi/response.js"],"names":[],"mappings":";AAAA,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEzC,MAAM,QAAQ;IACZ,YAAY,UAAU;QACpB,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,GAAG,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,OAAO;QACL,4CAA4C;QAC5C,MAAM,SAAS,GAAG,GAAG,EAAE;YACrB,OAAO,IAAI,CAAC,MAAM;iBACf,MAAM,CACL,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,mBAAmB,CACjE;iBACA,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CA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perty(exports, "__esModule", { value: true });
3
+ exports.rpcRequestForEvent = void 0;
4
+ const url_1 = require("url");
5
+ const util_1 = require("./util");
6
+ class ServerRPCRequest {
7
+ constructor(event) {
8
+ this.event = event;
9
+ }
10
+ get status() {
11
+ return this.event.httpServerResponse.status;
12
+ }
13
+ get parameters() {
14
+ return this.event.message || [];
15
+ }
16
+ get returnValue() {
17
+ return this.event.returnValue;
18
+ }
19
+ get requestHeaders() {
20
+ var _a;
21
+ return ((_a = this.event.httpServerRequest) === null || _a === void 0 ? void 0 : _a.headers) || {};
22
+ }
23
+ get responseHeaders() {
24
+ var _a;
25
+ return ((_a = this.event.httpServerResponse) === null || _a === void 0 ? void 0 : _a.headers) || {};
26
+ }
27
+ get requestContentType() {
28
+ return this.event.requestContentType;
29
+ }
30
+ get responseContentType() {
31
+ return this.event.responseContentType;
32
+ }
33
+ get requestMethod() {
34
+ var _a;
35
+ return (_a = this.event.requestMethod) === null || _a === void 0 ? void 0 : _a.toLowerCase();
36
+ }
37
+ get requestPath() {
38
+ return (0, util_1.ensureString)(this.event.httpServerRequest.normalized_path_info ||
39
+ this.event.httpServerRequest.path_info);
40
+ }
41
+ }
42
+ class ClientRPCRequest {
43
+ constructor(event) {
44
+ this.event = event;
45
+ }
46
+ get status() {
47
+ return this.event.httpClientResponse.status;
48
+ }
49
+ get parameters() {
50
+ return this.event.parameters || [];
51
+ }
52
+ get returnValue() {
53
+ return this.event.returnValue;
54
+ }
55
+ get requestHeaders() {
56
+ var _a;
57
+ return ((_a = this.event.httpClientRequest) === null || _a === void 0 ? void 0 : _a.headers) || {};
58
+ }
59
+ get responseHeaders() {
60
+ var _a;
61
+ return ((_a = this.event.httpClientResponse) === null || _a === void 0 ? void 0 : _a.headers) || {};
62
+ }
63
+ get requestContentType() {
64
+ return this.event.requestContentType;
65
+ }
66
+ get responseContentType() {
67
+ return this.event.responseContentType;
68
+ }
69
+ get requestMethod() {
70
+ var _a;
71
+ return (_a = this.event.requestMethod) === null || _a === void 0 ? void 0 : _a.toLowerCase();
72
+ }
73
+ get requestPath() {
74
+ // TODO: Back-substitute query parameters into the URL.
75
+ return new url_1.URL(this.event.httpClientRequest.url).pathname;
76
+ }
77
+ }
78
+ function rpcRequestForEvent(event) {
79
+ if (event.httpServerRequest && event.httpServerResponse) {
80
+ return new ServerRPCRequest(event);
81
+ }
82
+ else if (event.httpClientRequest && event.httpClientResponse) {
83
+ return new ClientRPCRequest(event);
84
+ }
85
+ }
86
+ exports.rpcRequestForEvent = rpcRequestForEvent;
87
+ //# sourceMappingURL=rpcRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpcRequest.js","sourceRoot":"","sources":["../../../src/openapi/rpcRequest.ts"],"names":[],"mappings":";;;AAEA,6BAA0B;AAC1B,iCAAsC;AActC,MAAM,gBAAgB;IACpB,YAAoB,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;IAAG,CAAC;IAEpC,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAmB,CAAC,MAAM,CAAC;IAC/C,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;IAClC,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAChC,CAAC;IAED,IAAI,cAAc;;QAChB,OAAO,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,iBAAiB,0CAAE,OAAO,KAAI,EAAE,CAAC;IACrD,CAAC;IAED,IAAI,eAAe;;QACjB,OAAO,CAAA,MAAA,IAAI,CAAC,KAAK,CAAC,kBAAkB,0CAAE,OAAO,KAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAmB,CAAC;IACxC,CAAC;IAED,IAAI,mBAAmB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,mBAAoB,CAAC;IACzC,CAAC;IAED,IA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,QAAQ,CAAC;IAC7D,CAAC;CACF;AAED,SAAgB,kBAAkB,CAAC,KAAY;IAC7C,IAAI,KAAK,CAAC,iBAAiB,IAAI,KAAK,CAAC,kBAAkB,EAAE;QACvD,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;KACpC;SAAM,IAAI,KAAK,CAAC,iBAAiB,IAAI,KAAK,CAAC,kBAAkB,EAAE;QAC9D,OAAO,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;KACpC;AACH,CAAC;AAND,gDAMC"}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("./util");
4
+ function mergeProperties(a, b) {
5
+ a || (a = {});
6
+ b || (b = {});
7
+ return Object.keys(a)
8
+ .concat(Object.keys(b))
9
+ .reduce((memo, key) => {
10
+ memo[key] = mergeType(a[key] || {}, b[key] || {});
11
+ return memo;
12
+ }, {});
13
+ }
14
+ // Merge type, items and properties of schema objects.
15
+ function mergeType(a, b) {
16
+ var _a, _b, _c, _d;
17
+ if (b === null || b === undefined)
18
+ return a;
19
+ const result = Object.assign({}, a);
20
+ if (!a.type) {
21
+ result.type = b.type;
22
+ }
23
+ else if (b.type === 'array') {
24
+ result.type = 'array';
25
+ }
26
+ else if (b.type === 'object') {
27
+ result.type = 'object';
28
+ }
29
+ if (a.items || b.items) {
30
+ result.items = mergeType(a.items || {}, b.items);
31
+ if (((_a = a.items) === null || _a === void 0 ? void 0 : _a.properties) || ((_b = b.items) === null || _b === void 0 ? void 0 : _b.properties)) {
32
+ result.items.properties = mergeProperties((_c = a.items) === null || _c === void 0 ? void 0 : _c.properties, (_d = b.items) === null || _d === void 0 ? void 0 : _d.properties);
33
+ }
34
+ }
35
+ else {
36
+ if (a.properties || b.properties) {
37
+ result.properties = mergeProperties(a.properties, b.properties);
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ class SchemaInferrer {
43
+ constructor() {
44
+ this.examples = [];
45
+ }
46
+ openapi() {
47
+ if (this.examples.length === 0)
48
+ return;
49
+ return this.examples.reduce((memo, example) => {
50
+ const schema = (0, util_1.messageToOpenAPISchema)(example);
51
+ return mergeType(memo, schema);
52
+ }, {});
53
+ }
54
+ addExample(value) {
55
+ this.examples.push(value);
56
+ }
57
+ }
58
+ exports.default = SchemaInferrer;
59
+ //# sourceMappingURL=schemaInferrer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaInferrer.js","sourceRoot":"","sources":["../../../src/openapi/schemaInferrer.ts"],"names":[],"mappings":";;AAEA,iCAAgD;AAEhD,SAAS,eAAe,CAAC,CAAM,EAAE,CAAM;IACrC,CAAC,KAAD,CAAC,GAAK,EAAE,EAAC;IACT,CAAC,KAAD,CAAC,GAAK,EAAE,EAAC;IAET,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;SAClB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACtB,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QACpB,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QAClD,OAAO,IAAI,CAAC;IACd,CAAC,EAAE,EAAE,CAAC,CAAC;AACX,CAAC;AAED,sDAAsD;AACtD,SAAS,SAAS,CAChB,CAAM,EACN,CAAO;;IAEP,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS;QAAE,OAAO,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IACpC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;QACX,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;KACtB;SAAM,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;QAC7B,MAAM,CA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Q,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF;AAnBD,iCAmBC"}
@@ -1,56 +1,31 @@
1
1
  "use strict";
2
- function parseScheme(authorization) {
3
- const tokens = authorization.split(/\s/);
4
- if (tokens.length === 1) {
5
- return {
6
- schemeId: 'api_key',
7
- scheme: {
8
- type: 'apiKey',
9
- name: 'authorization',
10
- in: 'header',
11
- },
12
- };
13
- }
14
- const schemeId = tokens[0].toLowerCase();
15
- return {
16
- schemeId,
17
- scheme: {
18
- type: 'http',
19
- scheme: schemeId,
20
- },
21
- };
22
- }
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util_1 = require("./util");
23
4
  class SecuritySchemes {
24
5
  constructor() {
25
- this.schemes = {};
6
+ this.rpcRequests = [];
26
7
  }
27
8
  /**
28
9
  * Adds an event to the security schemes, and assigns a security scheme id.
29
10
  * If the event has no detectable security scheme, this function returns null.
30
11
  *
31
- * @param {Event} event
32
12
  * @returns the security scheme id for the event, or null.
33
13
  */
34
- addRequest(event) {
35
- const { authorization } = event.httpServerRequest;
36
- if (!authorization) {
37
- return null;
38
- }
39
- const { schemeId, scheme } = parseScheme(authorization);
40
- if (!this.schemes[schemeId]) {
41
- this.schemes[schemeId] = scheme;
42
- }
43
- return schemeId;
14
+ addRpcRequest(rpcRequest) {
15
+ this.rpcRequests.push(rpcRequest);
44
16
  }
45
17
  openapi() {
46
- return Object.keys(this.schemes)
47
- .sort()
48
- .reduce((memo, schemeId) => {
49
- // eslint-disable-next-line no-param-reassign
50
- memo[schemeId] = this.schemes[schemeId];
18
+ return this.rpcRequests
19
+ .map((rpcRequest) => rpcRequest.requestHeaders['Authorization'])
20
+ .filter((authorization) => authorization)
21
+ .reduce((memo, authorization) => {
22
+ const scheme = (0, util_1.parseScheme)(authorization);
23
+ if (!memo[scheme.schemeId]) {
24
+ memo[scheme.schemeId] = scheme.scheme;
25
+ }
51
26
  return memo;
52
27
  }, {});
53
28
  }
54
29
  }
55
- module.exports = SecuritySchemes;
30
+ exports.default = SecuritySchemes;
56
31
  //# sourceMappingURL=securitySchemes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"securitySchemes.js","sourceRoot":"","sources":["../../../src/openapi/securitySchemes.js"],"names":[],"mappings":";AAAA,SAAS,WAAW,CAAC,aAAa;IAChC,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;QACvB,OAAO;YACL,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,eAAe;gBACrB,EAAE,EAAE,QAAQ;aACb;SACF,CAAC;KACH;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACzC,OAAO;QACL,QAAQ;QACR,MAAM,EAAE;YACN,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,QAAQ;SACjB;KACF,CAAC;AACJ,CAAC;AAED,MAAM,eAAe;IACnB;QACE,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACH,UAAU,CAAC,KAAK;QACd,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC,iBAAiB,CAAC;QAClD,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,IAAI,CAAC;SACb;QAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;QACxD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC3B,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC;SACjC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,OAAO;QACL,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC;aAC7B,IAAI,EAAE;aACN,MAAM,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,EAAE;YACzB,6CAA6C;YAC7C,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YACxC,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,eAAe,CAAC"}
1
+ {"version":3,"file":"securitySchemes.js","sourceRoot":"","sources":["../../../src/openapi/securitySchemes.ts"],"names":[],"mappings":";;AAEA,iCAAqC;AAErC,MAAqB,eAAe;IAApC;QACE,gBAAW,GAAiB,EAAE,CAAC;IAwBjC,CAAC;IAtBC;;;;;OAKG;IACH,aAAa,CAAC,UAAsB;QAClC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,WAAW;aACpB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;aAC/D,MAAM,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC;aACxC,MAAM,CAAC,CAAC,IAAI,EAAE,aAAa,EAAE,EAAE;YAC9B,MAAM,MAAM,GAAG,IAAA,kBAAW,EAAC,aAAa,CAAC,CAAC;YAC1C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE;gBAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC;aACvC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,EAAE,EAAoD,CAAC,CAAC;IAC7D,CAAC;CACF;AAzBD,kCAyBC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // https://github.com/nodejs/node/blob/f1653cc9b80b521ef5b129537ce1df9098bbdc1b/lib/_http_server.js#L18-L81
4
+ exports.default = {
5
+ 100: 'Continue',
6
+ 101: 'Switching Protocols',
7
+ 102: 'Processing',
8
+ 200: 'OK',
9
+ 201: 'Created',
10
+ 202: 'Accepted',
11
+ 203: 'Non-Authoritative Information',
12
+ 204: 'No Content',
13
+ 205: 'Reset Content',
14
+ 206: 'Partial Content',
15
+ 207: 'Multi-Status',
16
+ 208: 'Already Reported',
17
+ 226: 'IM Used',
18
+ 300: 'Multiple Choices',
19
+ 301: 'Moved Permanently',
20
+ 302: 'Found',
21
+ 303: 'See Other',
22
+ 304: 'Not Modified',
23
+ 305: 'Use Proxy',
24
+ 307: 'Temporary Redirect',
25
+ 308: 'Permanent Redirect',
26
+ 400: 'Bad Request',
27
+ 401: 'Unauthorized',
28
+ 402: 'Payment Required',
29
+ 403: 'Forbidden',
30
+ 404: 'Not Found',
31
+ 405: 'Method Not Allowed',
32
+ 406: 'Not Acceptable',
33
+ 407: 'Proxy Authentication Required',
34
+ 408: 'Request Timeout',
35
+ 409: 'Conflict',
36
+ 410: 'Gone',
37
+ 411: 'Length Required',
38
+ 412: 'Precondition Failed',
39
+ 413: 'Payload Too Large',
40
+ 414: 'URI Too Long',
41
+ 415: 'Unsupported Media Type',
42
+ 416: 'Range Not Satisfiable',
43
+ 417: 'Expectation Failed',
44
+ 418: "I'm a teapot",
45
+ 421: 'Misdirected Request',
46
+ 422: 'Unprocessable Entity',
47
+ 423: 'Locked',
48
+ 424: 'Failed Dependency',
49
+ 425: 'Unordered Collection',
50
+ 426: 'Upgrade Required',
51
+ 428: 'Precondition Required',
52
+ 429: 'Too Many Requests',
53
+ 431: 'Request Header Fields Too Large',
54
+ 451: 'Unavailable For Legal Reasons',
55
+ 500: 'Internal Server Error',
56
+ 501: 'Not Implemented',
57
+ 502: 'Bad Gateway',
58
+ 503: 'Service Unavailable',
59
+ 504: 'Gateway Timeout',
60
+ 505: 'HTTP Version Not Supported',
61
+ 506: 'Variant Also Negotiates',
62
+ 507: 'Insufficient Storage',
63
+ 508: 'Loop Detected',
64
+ 509: 'Bandwidth Limit Exceeded',
65
+ 510: 'Not Extended',
66
+ 511: 'Network Authentication Required',
67
+ };
68
+ //# sourceMappingURL=statusCodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"statusCodes.js","sourceRoot":"","sources":["../../../src/openapi/statusCodes.ts"],"names":[],"mappings":";;AAAA,2GAA2G;AAC3G,kBAAe;IACb,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,YAAY;IACjB,GAAG,EAAE,IAAI;IACT,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,YAAY;IACjB,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,wBAAwB;IAC7B,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,oBAAoB;IACzB,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,iCAAiC;IACtC,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,uBAAuB;IAC5B,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,aAAa;IAClB,GAAG,EAAE,qBAAqB;IAC1B,GAAG,EAAE,iBAAiB;IACtB,GAAG,EAAE,4BAA4B;IACjC,GAAG,EAAE,yBAAyB;IAC9B,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,0BAA0B;IAC/B,GAAG,EAAE,cAAc;IACnB,GAAG,EAAE,iCAAiC;CACb,CAAC"}
@@ -1,6 +1,30 @@
1
1
  "use strict";
2
- const { buildAppMap } = require('@appland/models');
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseScheme = exports.messageToOpenAPISchema = exports.ensureString = void 0;
4
+ const utils_1 = require("../utils");
3
5
  const unrecognizedTypes = new Set();
6
+ function parseScheme(authorization) {
7
+ const tokens = authorization.split(/\s/);
8
+ if (tokens.length === 1) {
9
+ return {
10
+ schemeId: 'api_key',
11
+ scheme: {
12
+ type: 'apiKey',
13
+ name: 'authorization',
14
+ in: 'header',
15
+ },
16
+ };
17
+ }
18
+ const schemeId = tokens[0].toLowerCase();
19
+ return {
20
+ schemeId,
21
+ scheme: {
22
+ type: 'http',
23
+ scheme: schemeId,
24
+ },
25
+ };
26
+ }
27
+ exports.parseScheme = parseScheme;
4
28
  function classNameToOpenAPIType(className) {
5
29
  if (!className || className === '') {
6
30
  return 'unknown';
@@ -8,24 +32,29 @@ function classNameToOpenAPIType(className) {
8
32
  const mapRubyType = (t) => {
9
33
  switch (t) {
10
34
  case 'array':
35
+ case 'sequel::postgres::pgarray':
11
36
  return 'array';
12
37
  case 'hash':
38
+ case 'sequel::postgres::jsonbhash':
13
39
  case 'activesupport::hashwithindifferentaccess':
14
40
  return 'object';
15
- case 'nilclass':
16
- return 'string';
41
+ case 'integer':
42
+ return 'integer';
43
+ case 'float':
44
+ case 'numeric':
45
+ return 'number';
17
46
  case 'trueclass':
18
47
  case 'falseclass':
19
48
  return 'boolean';
49
+ case 'nilclass':
50
+ return 'unknown';
20
51
  case 'string':
21
52
  return 'string';
22
- default:
23
- return undefined;
24
53
  }
25
54
  };
26
55
  const mapPythonType = (t) => {
27
56
  if (!t.startsWith('builtins.')) {
28
- return undefined;
57
+ return;
29
58
  }
30
59
  switch (t.substr(9)) {
31
60
  case 'bool':
@@ -38,74 +67,65 @@ function classNameToOpenAPIType(className) {
38
67
  return 'array';
39
68
  case 'str':
40
69
  return 'string';
41
- default:
42
- return undefined;
43
70
  }
44
71
  };
45
72
  const mapJavaType = (t) => {
46
73
  switch (t) {
47
74
  case 'java.lang.string':
48
75
  return 'string';
49
- default:
50
- return undefined;
51
76
  }
52
77
  };
53
78
  const mapper = (t) => mapRubyType(t) || mapPythonType(t) || mapJavaType(t);
54
79
  const mapped = mapper(className.toLowerCase());
55
80
  if (!mapped && !unrecognizedTypes.has(className)) {
56
- console.warn(`Warning: Don't know how to map "${className}" to an OpenAPI type. You'll need to update the generated file.`);
81
+ if ((0, utils_1.verbose)()) {
82
+ console.warn(`Warning: Don't know how to map "${className}" to an OpenAPI type. You'll need to update the generated file.`);
83
+ }
57
84
  unrecognizedTypes.add(className);
58
- return className;
85
+ return 'object';
59
86
  }
60
87
  return mapped;
61
88
  }
62
89
  function messageToOpenAPISchema(message) {
63
90
  const type = classNameToOpenAPIType(message.class);
91
+ if (type === 'unknown')
92
+ return;
64
93
  const result = { type };
65
- /*
66
- if (message.value) {
67
- let example;
68
- try {
69
- example = JSON.parse(message.value);
70
- } catch (e) {
71
- example = message.value;
72
- }
73
- if (example && example !== '') {
74
- result.example = example.toString();
75
- }
76
- }
77
- */
78
- if (type === 'array') {
79
- // This is our best guess right now.
80
- result.items = { type: 'string' };
81
- }
82
- else if (type === 'object' && message.properties) {
83
- result.properties = message.properties.reduce((memo, msgProperty) => {
84
- // eslint-disable-next-line no-param-reassign
85
- memo[msgProperty.name] = {
86
- type: classNameToOpenAPIType(msgProperty.class),
87
- };
94
+ if (message.properties) {
95
+ const properties = message.properties.reduce((memo, msgProperty) => {
96
+ const type = classNameToOpenAPIType(msgProperty.class);
97
+ if (type === 'array') {
98
+ // eslint-disable-next-line no-param-reassign
99
+ memo[msgProperty.name] = { type };
100
+ }
101
+ else if (type !== 'unknown') {
102
+ // eslint-disable-next-line no-param-reassign
103
+ memo[msgProperty.name] = {
104
+ type,
105
+ };
106
+ }
88
107
  return memo;
89
108
  }, {});
109
+ if (type === 'array') {
110
+ result.items = { type: 'object', properties };
111
+ }
112
+ else {
113
+ result.properties = properties;
114
+ }
115
+ }
116
+ else {
117
+ if (type === 'array') {
118
+ result.items = { type: 'string' };
119
+ }
90
120
  }
91
121
  return result;
92
122
  }
93
- function parseHTTPServerRequests(source, collector) {
94
- const appmap = buildAppMap().source(source).normalize().build();
95
- appmap.events.filter((e) => e.httpServerRequest).forEach(collector);
96
- }
123
+ exports.messageToOpenAPISchema = messageToOpenAPISchema;
97
124
  function ensureString(value) {
98
125
  if (Array.isArray(value)) {
99
126
  return value.join('');
100
127
  }
101
128
  return value.toString();
102
129
  }
103
- function bestPathInfo(httpServerRequest) {
104
- return ensureString(httpServerRequest.normalized_path_info || httpServerRequest.path_info || '');
105
- }
106
- module.exports = {
107
- bestPathInfo,
108
- messageToOpenAPISchema,
109
- parseHTTPServerRequests,
110
- };
130
+ exports.ensureString = ensureString;
111
131
  //# sourceMappingURL=util.js.map