openapi-explorer 0.9.385 → 0.9.392

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 (53) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +3 -2
  3. package/dist/browser/openapi-explorer.min.js +7 -5
  4. package/dist/browser/openapi-explorer.min.js.map +1 -1
  5. package/dist/es/components/api-request.js +51 -18
  6. package/dist/es/components/api-response.js +17 -5
  7. package/dist/es/components/json-tree.js +3 -2
  8. package/dist/es/components/mime-types.js +5 -5
  9. package/dist/es/components/schema-table.js +1 -1
  10. package/dist/es/components/schema-tree.js +4 -3
  11. package/dist/es/languages/en.js +59 -0
  12. package/dist/es/languages/fr.js +59 -0
  13. package/dist/es/languages/index.js +20 -0
  14. package/dist/es/openapi-explorer.js +8 -3
  15. package/dist/es/styles/input-styles.js +1 -1
  16. package/dist/es/styles/schema-styles.js +1 -1
  17. package/dist/es/templates/callback-template.js +1 -1
  18. package/dist/es/templates/code-samples-template.js +2 -1
  19. package/dist/es/templates/components-template.js +4 -2
  20. package/dist/es/templates/endpoint-template.js +1 -1
  21. package/dist/es/templates/expanded-endpoint-template.js +1 -1
  22. package/dist/es/templates/navbar-template.js +3 -2
  23. package/dist/es/templates/overview-template.js +2 -1
  24. package/dist/es/templates/security-scheme-template.js +6 -5
  25. package/dist/es/templates/server-template.js +4 -3
  26. package/dist/es/utils/common-utils.js +4 -2
  27. package/dist/es/utils/schema-utils.js +51 -44
  28. package/dist/es/utils/spec-parser.js +3 -2
  29. package/dist/lib/components/api-request.js +52 -18
  30. package/dist/lib/components/api-response.js +18 -5
  31. package/dist/lib/components/json-tree.js +4 -2
  32. package/dist/lib/components/mime-types.js +8 -9
  33. package/dist/lib/components/schema-table.js +1 -1
  34. package/dist/lib/components/schema-tree.js +5 -3
  35. package/dist/lib/languages/en.js +64 -0
  36. package/dist/lib/languages/fr.js +64 -0
  37. package/dist/lib/languages/index.js +32 -0
  38. package/dist/lib/openapi-explorer.js +9 -3
  39. package/dist/lib/styles/input-styles.js +1 -1
  40. package/dist/lib/styles/schema-styles.js +1 -1
  41. package/dist/lib/templates/callback-template.js +1 -1
  42. package/dist/lib/templates/code-samples-template.js +3 -1
  43. package/dist/lib/templates/components-template.js +4 -2
  44. package/dist/lib/templates/endpoint-template.js +1 -1
  45. package/dist/lib/templates/expanded-endpoint-template.js +1 -1
  46. package/dist/lib/templates/navbar-template.js +4 -2
  47. package/dist/lib/templates/overview-template.js +3 -1
  48. package/dist/lib/templates/security-scheme-template.js +7 -5
  49. package/dist/lib/templates/server-template.js +5 -3
  50. package/dist/lib/utils/common-utils.js +4 -2
  51. package/dist/lib/utils/schema-utils.js +51 -44
  52. package/dist/lib/utils/spec-parser.js +4 -2
  53. package/package.json +7 -4
@@ -11,7 +11,7 @@ var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
11
11
 
12
12
  var _regexToStrings = require("regex-to-strings");
13
13
 
14
- var _xml = _interopRequireDefault(require("./xml/xml"));
14
+ var _xml = _interopRequireDefault(require("./xml/xml.js"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
@@ -19,27 +19,34 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  const IS_MISSING_TYPE_INFO_TYPE = '';
20
20
  /* Generates an schema object containing type and constraint info */
21
21
 
22
- function getTypeInfo(schema) {
23
- var _schema$items;
22
+ function getTypeInfo(schema, options = {
23
+ includeNulls: false
24
+ }) {
25
+ var _schema$items, _schema$const;
24
26
 
25
27
  if (!schema) {
26
28
  return undefined;
27
29
  }
28
30
 
29
- let dataType = '';
30
- let constraint = '';
31
+ let dataType = IS_MISSING_TYPE_INFO_TYPE;
31
32
 
32
33
  if (schema.circularReference) {
33
34
  dataType = `{recursive: ${schema.circularReference.name}} `;
34
35
  } else if (schema.type) {
35
36
  const arraySchema = Array.isArray(schema.type) ? schema.type : typeof schema.type === 'string' ? schema.type.split('┃') : schema.type;
36
- dataType = Array.isArray(arraySchema) ? arraySchema.filter(s => s !== 'null').join('┃') : schema.type;
37
+ dataType = Array.isArray(arraySchema) ? arraySchema.filter(s => s !== 'null' || options.includeNulls).join('┃') : schema.type;
37
38
 
38
- if (schema.format || schema.enum) {
39
- dataType = dataType.replace('string', schema.enum ? 'enum' : schema.format);
39
+ if (schema.format || schema.enum || schema.const) {
40
+ dataType = dataType.replace('string', schema.enum && 'enum' || schema.const && 'const' || schema.format);
41
+ }
42
+
43
+ if (schema.nullable && options.includeNulls) {
44
+ dataType += '┃null';
45
+ }
46
+
47
+ if (dataType.includes('┃null') && schema.format) {
48
+ schema.format += '┃null';
40
49
  }
41
- } else {
42
- dataType = IS_MISSING_TYPE_INFO_TYPE;
43
50
  }
44
51
 
45
52
  const info = {
@@ -53,21 +60,18 @@ function getTypeInfo(schema) {
53
60
  title: schema.title || '',
54
61
  description: schema.description || '',
55
62
  constraint: '',
56
- allowedValues: '',
57
- arrayType: '',
58
- html: ''
59
- }; // Set Allowed Values
60
-
61
- info.allowedValues = Array.isArray(schema.enum) ? schema.enum.join('┃') : '';
63
+ allowedValues: (_schema$const = schema.const) !== null && _schema$const !== void 0 ? _schema$const : Array.isArray(schema.enum) ? schema.enum.join('') : '',
64
+ arrayType: ''
65
+ };
62
66
 
63
67
  if (dataType === 'array' && schema.items) {
64
- var _schema$items$default;
68
+ var _schema$items$default, _schema$const2;
65
69
 
66
70
  const arrayItemType = schema.items.type;
67
71
  const arrayItemDefault = (_schema$items$default = schema.items.default) !== null && _schema$items$default !== void 0 ? _schema$items$default : '';
68
72
  info.arrayType = `${schema.type} of ${Array.isArray(arrayItemType) ? arrayItemType.join('') : arrayItemType}`;
69
73
  info.default = arrayItemDefault;
70
- info.allowedValues = Array.isArray(schema.items.enum) ? schema.items.enum.join('┃') : '';
74
+ info.allowedValues = (_schema$const2 = schema.const) !== null && _schema$const2 !== void 0 ? _schema$const2 : Array.isArray(schema.items.enum) ? schema.items.enum.join('┃') : '';
71
75
  }
72
76
 
73
77
  if (dataType.match(/integer|number/g)) {
@@ -79,25 +83,24 @@ function getTypeInfo(schema) {
79
83
  const rightBound = schema.maximum !== undefined ? ']' : ')';
80
84
 
81
85
  if (typeof minimum === 'number' || typeof maximum === 'number') {
82
- constraint = `Range: ${leftBound}${minimum !== null && minimum !== void 0 ? minimum : ''},${maximum !== null && maximum !== void 0 ? maximum : ''}${rightBound}`;
86
+ info.constraint = `Range: ${leftBound}${minimum !== null && minimum !== void 0 ? minimum : ''},${maximum !== null && maximum !== void 0 ? maximum : ''}${rightBound}`;
83
87
  }
84
88
 
85
89
  if (schema.multipleOf !== undefined) {
86
- constraint += `${constraint ? ', ' : ''}Multiples: ${schema.multipleOf}`;
90
+ info.constraint += `${info.constraint ? ', ' : ''}Multiples: ${schema.multipleOf}`;
87
91
  }
88
92
  }
89
93
 
90
94
  if (dataType.match(/string/g)) {
91
95
  if (schema.minLength !== undefined && schema.maxLength !== undefined) {
92
- constraint += `Min length: ${schema.minLength}, Max length: ${schema.maxLength}`;
96
+ info.constraint += `Min length: ${schema.minLength}, Max length: ${schema.maxLength}`;
93
97
  } else if (schema.minLength !== undefined) {
94
- constraint += `Min length: ${schema.minLength}`;
98
+ info.constraint += `Min length: ${schema.minLength}`;
95
99
  } else if (schema.maxLength !== undefined) {
96
- constraint += `Max length: ${schema.maxLength}`;
100
+ info.constraint += `Max length: ${schema.maxLength}`;
97
101
  }
98
102
  }
99
103
 
100
- info.constraint = constraint;
101
104
  info.html = JSON.stringify({
102
105
  type: info.type,
103
106
  format: info.format,
@@ -175,6 +178,10 @@ function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleString
175
178
  }
176
179
 
177
180
  if (typeValue.match(/^string/g)) {
181
+ if (schemaObj.const) {
182
+ return schemaObj.const;
183
+ }
184
+
178
185
  if (schemaObj.enum) {
179
186
  return schemaObj.enum[0];
180
187
  }
@@ -372,13 +379,13 @@ function getExampleValuesFromSchemaRecursive(schema, config = {}) {
372
379
  * For changing OpenAPI-Schema to an Object Notation,
373
380
  * This Object would further be an input to UI Components to generate an Object-Tree
374
381
  * @param {object} schema - Schema object from OpenAPI spec
375
- * @param {object} obj - recursively pass this object to generate object notation
382
+ * @param {object} options - recursively pass this object to generate object notation
376
383
  * @param {number} level - recursion level
377
384
  * @param {string} suffix - used for suffixing property names to avoid duplicate props during object composition
378
385
  */
379
386
 
380
387
 
381
- function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
388
+ function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '') {
382
389
  if (!rawSchema) {
383
390
  return undefined;
384
391
  }
@@ -396,18 +403,18 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
396
403
  allOf.map((v, i) => {
397
404
  if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
398
405
  const propSuffix = (v.anyOf || v.oneOf) && i > 0 ? i : '';
399
- const partialObj = schemaInObjectNotation(v, {}, level + 1, propSuffix);
406
+ const partialObj = schemaInObjectNotation(v, options, level + 1, propSuffix);
400
407
  Object.assign(objWithAllProps, partialObj);
401
408
  } else if (v.type === 'array' || v.items) {
402
- const partialObj = schemaInObjectNotation(v, {}, level + 1);
409
+ const partialObj = schemaInObjectNotation(v, options, level + 1);
403
410
  Object.assign(objWithAllProps, partialObj);
404
411
  } else if (v.type) {
405
412
  const prop = `prop${Object.keys(objWithAllProps).length}`;
406
- const typeObj = getTypeInfo(v);
413
+ const typeObj = getTypeInfo(v, options);
407
414
  objWithAllProps[prop] = `${typeObj.html}`;
408
415
  }
409
416
  });
410
- const obj = schemaInObjectNotation(schema, {}, 0);
417
+ const obj = schemaInObjectNotation(schema, options, 0);
411
418
  return Object.assign({}, objWithAllProps, typeof obj === 'object' && !Array.isArray(obj) ? obj : {});
412
419
  } else if (anyOf || oneOf) {
413
420
  const objWithAnyOfProps = {};
@@ -417,7 +424,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
417
424
  if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
418
425
  var _partialObj$Flags, _partialObj$Flags2;
419
426
 
420
- const partialObj = schemaInObjectNotation(v, {});
427
+ const partialObj = schemaInObjectNotation(v, options);
421
428
  objWithAnyOfProps[`::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`] = partialObj;
422
429
  objWithAnyOfProps['::type'] = 'xxx-of-option';
423
430
  readOnly = readOnly && ((_partialObj$Flags = partialObj['::flags']) === null || _partialObj$Flags === void 0 ? void 0 : _partialObj$Flags['🆁']);
@@ -426,7 +433,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
426
433
  var _partialObj$Flags3, _partialObj$Flags4;
427
434
 
428
435
  // This else-if block never seems to get executed
429
- const partialObj = schemaInObjectNotation(v, {});
436
+ const partialObj = schemaInObjectNotation(v, options);
430
437
  objWithAnyOfProps[`::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`] = partialObj;
431
438
  objWithAnyOfProps['::type'] = 'xxx-of-array';
432
439
  readOnly = readOnly && ((_partialObj$Flags3 = partialObj['::flags']) === null || _partialObj$Flags3 === void 0 ? void 0 : _partialObj$Flags3['🆁']);
@@ -435,13 +442,13 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
435
442
  var _objWithAnyOfProps$, _objWithAnyOfProps$2;
436
443
 
437
444
  const prop = `::OPTION~${index + 1}${v.title ? `~${v.title}` : ''}`;
438
- objWithAnyOfProps[prop] = `${getTypeInfo(v).html}`;
445
+ objWithAnyOfProps[prop] = `${getTypeInfo(v, options).html}`;
439
446
  objWithAnyOfProps['::type'] = 'xxx-of-option';
440
447
  readOnly = readOnly && ((_objWithAnyOfProps$ = objWithAnyOfProps['::flags']) === null || _objWithAnyOfProps$ === void 0 ? void 0 : _objWithAnyOfProps$['🆁']);
441
448
  writeOnly = writeOnly && ((_objWithAnyOfProps$2 = objWithAnyOfProps['::flags']) === null || _objWithAnyOfProps$2 === void 0 ? void 0 : _objWithAnyOfProps$2['🆆']);
442
449
  }
443
450
  });
444
- const obj = schemaInObjectNotation(schema, {}, 0);
451
+ const obj = schemaInObjectNotation(schema, options, 0);
445
452
  const resultObj = typeof obj === 'object' && !Array.isArray(obj) ? obj : {};
446
453
  resultObj[anyOf ? `::ANY~OF ${suffix}` : `::ONE~OF ${suffix}`] = objWithAnyOfProps;
447
454
  resultObj['::type'] = 'xxx-of';
@@ -475,7 +482,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
475
482
 
476
483
  if (primitiveType.length > 0) {
477
484
  subSchema.type = primitiveType.join('┃');
478
- multiPrimitiveTypes = getTypeInfo(subSchema);
485
+ multiPrimitiveTypes = getTypeInfo(subSchema, options);
479
486
 
480
487
  if (complexTypes.length === 0) {
481
488
  return `${multiPrimitiveTypes && multiPrimitiveTypes.html || ''}`;
@@ -493,7 +500,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
493
500
  multiTypeOptions[`::OPTION~${i + 1}`] = 'NULL~|~~|~~|~~|~~|~~|~~|~~|~';
494
501
  } else if ('integer, number, string, boolean,'.includes(`${v},`)) {
495
502
  subSchema.type = Array.isArray(v) ? v.join('┃') : v;
496
- const primitiveTypeInfo = getTypeInfo(subSchema);
503
+ const primitiveTypeInfo = getTypeInfo(subSchema, options);
497
504
  multiTypeOptions[`::OPTION~${i + 1}`] = primitiveTypeInfo.html;
498
505
  } else if (v === 'object') {
499
506
  // If object type iterate all the properties and create an object-type-option
@@ -510,9 +517,9 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
510
517
 
511
518
  for (const key in schema.properties) {
512
519
  if (schema.required && schema.required.includes(key)) {
513
- objTypeOption[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
520
+ objTypeOption[`${key}*`] = schemaInObjectNotation(schema.properties[key], options, level + 1);
514
521
  } else {
515
- objTypeOption[key] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
522
+ objTypeOption[key] = schemaInObjectNotation(schema.properties[key], options, level + 1);
516
523
  }
517
524
  }
518
525
 
@@ -529,7 +536,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
529
536
  '::props': schemaInObjectNotation(Object.assign({
530
537
  readOnly: schema.readOnly,
531
538
  writeOnly: schema.writeOnly
532
- }, schema.items), {}, level + 1)
539
+ }, schema.items), options, level + 1)
533
540
  };
534
541
  }
535
542
  });
@@ -551,14 +558,14 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
551
558
 
552
559
  for (const key in schema.properties) {
553
560
  if (schema.required && schema.required.includes(key)) {
554
- obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
561
+ obj[`${key}*`] = schemaInObjectNotation(schema.properties[key], options, level + 1);
555
562
  } else {
556
- obj[key] = schemaInObjectNotation(schema.properties[key], {}, level + 1);
563
+ obj[key] = schemaInObjectNotation(schema.properties[key], options, level + 1);
557
564
  }
558
565
  }
559
566
 
560
567
  if (schema.additionalProperties) {
561
- obj['<any-key>'] = schemaInObjectNotation(schema.additionalProperties, {});
568
+ obj['<any-key>'] = schemaInObjectNotation(schema.additionalProperties, options);
562
569
  }
563
570
 
564
571
  return obj;
@@ -579,7 +586,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
579
586
  deprecated: schema.deprecated,
580
587
  readOnly: schema.readOnly,
581
588
  writeOnly: schema.writeOnly
582
- }, schema.items), {}, level + 1);
589
+ }, schema.items), options, level + 1);
583
590
 
584
591
  if ((_schema$items2 = schema.items) !== null && _schema$items2 !== void 0 && _schema$items2.items) {
585
592
  obj['::array-type'] = schema.items.items.type;
@@ -588,7 +595,7 @@ function schemaInObjectNotation(rawSchema, _, level = 0, suffix = '') {
588
595
  return obj;
589
596
  }
590
597
 
591
- const typeObj = getTypeInfo(schema);
598
+ const typeObj = getTypeInfo(schema, options);
592
599
  return `${(typeObj === null || typeObj === void 0 ? void 0 : typeObj.html) || ''}`;
593
600
  }
594
601
  /* Create Example object */
@@ -9,6 +9,8 @@ var _marked = require("marked");
9
9
 
10
10
  var _commonUtils = require("./common-utils");
11
11
 
12
+ var _languages = require("../languages");
13
+
12
14
  var _lodash = _interopRequireDefault(require("lodash.clonedeep"));
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -64,7 +66,7 @@ async function ProcessSpec(specUrlOrObject, serverUrl = '') {
64
66
 
65
67
  securitySchemes.forEach(v => {
66
68
  if (v.type === 'http') {
67
- v.typeDisplay = v.scheme === 'basic' ? 'HTTP Basic' : 'HTTP Bearer';
69
+ v.typeDisplay = v.scheme === 'basic' ? (0, _languages.getI18nText)('authentication.http-basic') : 'HTTP Bearer';
68
70
  } else if (v.type === 'apiKey') {
69
71
  v.typeDisplay = `API Key (${v.name})`;
70
72
  } else if (v.type === 'oauth2') {
@@ -167,7 +169,7 @@ function getComponents(openApiSpec) {
167
169
 
168
170
  switch (component) {
169
171
  case 'schemas':
170
- cmpName = 'Schemas';
172
+ cmpName = (0, _languages.getI18nText)('menu.schemas');
171
173
  cmpDescription = '';
172
174
  break;
173
175
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "openapi-explorer",
3
- "version": "0.9.385",
3
+ "version": "0.9.392",
4
4
  "description": "OpenAPI Explorer - API viewer with dynamically generated components, documentation, and interaction console",
5
5
  "author": "Rhosys Developers <developers@rhosys.ch>",
6
+ "type": "module",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/Rhosys/openapi-explorer.git"
@@ -50,6 +51,7 @@
50
51
  "buffer": "^6.0.3",
51
52
  "color": "^4.2.3",
52
53
  "create-hash": "^1.2.0",
54
+ "i18next": "^21.9.0",
53
55
  "lit-element": "^3.2.2",
54
56
  "lit-html": "^2.3.1",
55
57
  "lodash.clonedeep": "^4.5.0",
@@ -69,7 +71,7 @@
69
71
  "start": "webpack serve --mode=development --port=8080",
70
72
  "serve": "serve -p 8080 mocks",
71
73
  "lint": "eslint --ext .js src",
72
- "test": "babel src -d lib && mocha -r esm tests/*.test.js"
74
+ "test": "ava tests/**/*.test.js"
73
75
  },
74
76
  "devDependencies": {
75
77
  "@babel/cli": "^7.13.14",
@@ -79,6 +81,7 @@
79
81
  "@babel/plugin-proposal-optional-chaining": "^7.18.9",
80
82
  "@babel/plugin-transform-modules-commonjs": "^7.18.6",
81
83
  "@babel/preset-env": "^7.13.12",
84
+ "ava": "^4.3.3",
82
85
  "babel-loader": "^8.2.2",
83
86
  "babel-plugin-template-html-minifier": "^4.1.0",
84
87
  "chai": "^4.2.0",
@@ -97,13 +100,13 @@
97
100
  "eslint-plugin-promise": "^5.1.0",
98
101
  "eslint-plugin-vue": "^7.17.0",
99
102
  "eslint-webpack-plugin": "2.5.3",
100
- "esm": "^3.2.25",
101
103
  "file-loader": "^6.2.0",
102
104
  "filemanager-webpack-plugin": "^4.0.0",
103
105
  "fs-extra": "^8.1.0",
104
106
  "glob": "^7.1.6",
105
107
  "html-webpack-plugin": "^5.3.1",
106
108
  "inspectpack": "^4.7.1",
109
+ "json-loader": "^0.5.7",
107
110
  "mocha": "^7.2.0",
108
111
  "npm-run-all": "^4.1.5",
109
112
  "sinon": "^7.5.0",
@@ -116,6 +119,6 @@
116
119
  "webpack-dev-server": "^3.11.2"
117
120
  },
118
121
  "engines": {
119
- "node": ">=12"
122
+ "node": ">=14"
120
123
  }
121
124
  }