openapi-explorer 0.8.270 → 0.8.273

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-explorer",
3
- "version": "0.8.270",
3
+ "version": "0.8.273",
4
4
  "description": "OpenAPI Explorer - API viewer with dynamically generated components, documentation, and interaction console",
5
5
  "author": "Rhosys Developers <developers@rhosys.ch>",
6
6
  "repository": {
@@ -56,7 +56,6 @@ export default class ApiRequest extends LitElement {
56
56
  activeSchemaTab: { type: String, attribute: 'active-schema-tab' },
57
57
  schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
58
58
  schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
59
- allowSchemaDescriptionExpandToggle: { type: String, attribute: 'allow-schema-description-expand-toggle' },
60
59
  schemaHideReadOnly: { type: String, attribute: 'schema-hide-read-only' },
61
60
  fetchCredentials: { type: String, attribute: 'fetch-credentials' },
62
61
 
@@ -336,6 +335,7 @@ export default class ApiRequest extends LitElement {
336
335
  false,
337
336
  true,
338
337
  'text',
338
+ true
339
339
  );
340
340
  if (!this.selectedRequestBodyExample) {
341
341
  this.selectedRequestBodyExample = (reqBodyExamples.length > 0 ? reqBodyExamples[0].exampleId : '');
@@ -395,6 +395,7 @@ export default class ApiRequest extends LitElement {
395
395
  false,
396
396
  true,
397
397
  'text',
398
+ true
398
399
  );
399
400
  if (reqBody.schema) {
400
401
  reqBodyFormHtml = this.formDataTemplate(reqBody.schema, reqBody.mimeType, (ex[0] ? ex[0].exampleValue : ''));
@@ -422,7 +423,6 @@ export default class ApiRequest extends LitElement {
422
423
  .data = '${schemaAsObj}'
423
424
  schema-expand-level = "${this.schemaExpandLevel}"
424
425
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
425
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
426
426
  schema-hide-read-only = "${this.schemaHideReadOnly.includes(this.method)}"
427
427
  schema-hide-write-only = false
428
428
  > </schema-table>
@@ -436,7 +436,6 @@ export default class ApiRequest extends LitElement {
436
436
  .data = '${schemaAsObj}'
437
437
  schema-expand-level = "${this.schemaExpandLevel}"
438
438
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
439
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
440
439
  schema-hide-read-only = "${this.schemaHideReadOnly.includes(this.method)}"
441
440
  schema-hide-write-only = false
442
441
  > </schema-tree>
@@ -459,8 +458,8 @@ export default class ApiRequest extends LitElement {
459
458
  ? html`
460
459
  <div class="tab-panel col" style="border-width:0 0 1px 0;">
461
460
  <div class="tab-buttons row" @click="${(e) => { if (e.target.tagName.toLowerCase() === 'button') { this.activeSchemaTab = e.target.dataset.tab; } }}">
462
- <button class="tab-btn ${this.activeSchemaTab === 'model' ? 'active' : ''}" data-tab = 'model' >MODEL</button>
463
- <button class="tab-btn ${this.activeSchemaTab === 'body' ? 'active' : ''}" data-tab = 'example'>BODY</button>
461
+ <button class="tab-btn ${this.activeSchemaTab === 'model' ? 'active' : ''}" data-tab="model" >MODEL</button>
462
+ <button class="tab-btn ${this.activeSchemaTab === 'body' ? 'active' : ''}" data-tab="body">BODY</button>
464
463
  </div>
465
464
  ${html`<div class="tab-content col" style="display: ${this.activeSchemaTab === 'model' ? 'block' : 'none'}"> ${reqBodySchemaHtml}</div>`}
466
465
  ${html`<div class="tab-content col" style="display: ${this.activeSchemaTab === 'model' ? 'none' : 'block'}"> ${reqBodyExampleHtml}</div>`}
@@ -493,6 +492,7 @@ export default class ApiRequest extends LitElement {
493
492
  false,
494
493
  true,
495
494
  'text',
495
+ true
496
496
  );
497
497
 
498
498
  formDataTableRows.push(html`
@@ -568,9 +568,7 @@ export default class ApiRequest extends LitElement {
568
568
  <schema-tree
569
569
  .data = '${formdataPartSchema}'
570
570
  schema-expand-level = "${this.schemaExpandLevel}"
571
- schema-description-expanded = "${this.schemaDescriptionExpanded}"
572
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
573
- > </schema-tree>
571
+ schema-description-expanded = "${this.schemaDescriptionExpanded}"> </schema-tree>
574
572
  </div>`
575
573
  }
576
574
  ${html`
@@ -732,8 +730,8 @@ export default class ApiRequest extends LitElement {
732
730
  </div>`
733
731
  : html`
734
732
  <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'response' ? 'flex' : 'none'};" >
735
- <button class="toolbar-btn" @click='${(e) => { copyToClipboard(this.responseText, e); }}' part="btn btn-fill"> Copy </button>
736
- <pre style="white-space:pre; max-height:400px; overflow:auto">${responseFormat
733
+ <button class="toolbar-copy-btn" @click='${(e) => { copyToClipboard(this.responseText, e); }}' part="btn btn-fill">Copy</button>
734
+ <pre>${responseFormat
737
735
  ? html`<code>${unsafeHTML(Prism.highlight(this.responseText, Prism.languages[responseFormat], responseFormat))}</code>`
738
736
  : `${this.responseText}`
739
737
  }
@@ -741,12 +739,12 @@ export default class ApiRequest extends LitElement {
741
739
  </div>`
742
740
  }
743
741
  <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'headers' ? 'flex' : 'none'};" >
744
- <button class="toolbar-btn" @click='${(e) => { copyToClipboard(this.responseHeaders, e); }}' part="btn btn-fill"> Copy </button>
745
- <pre style="white-space:pre"><code>${unsafeHTML(Prism.highlight(this.responseHeaders, Prism.languages.css, 'css'))}</code></pre>
742
+ <button class="toolbar-copy-btn" @click='${(e) => { copyToClipboard(this.responseHeaders, e); }}' part="btn btn-fill">Copy</button>
743
+ <pre><code>${unsafeHTML(Prism.highlight(this.responseHeaders, Prism.languages.css, 'css'))}</code></pre>
746
744
  </div>
747
745
  <div class="tab-content col m-markdown" style="flex:1;display:${this.activeResponseTab === 'curl' ? 'flex' : 'none'};">
748
- <button class="toolbar-btn" @click='${(e) => { copyToClipboard(this.curlSyntax.replace(/\\$/, ''), e); }}' part="btn btn-fill"> Copy </button>
749
- <pre style="white-space:pre"><code>${unsafeHTML(Prism.highlight(this.curlSyntax.trim().replace(/\\$/, ''), Prism.languages.shell, 'shell'))}</code></pre>
746
+ <button class="toolbar-copy-btn" @click='${(e) => { copyToClipboard(this.curlSyntax.replace(/\\$/, ''), e); }}' part="btn btn-fill">Copy</button>
747
+ <pre><code>${unsafeHTML(Prism.highlight(this.curlSyntax.trim().replace(/\\$/, ''), Prism.languages.shell, 'shell'))}</code></pre>
750
748
  </div>
751
749
  </div>`;
752
750
  }
@@ -32,7 +32,6 @@ export default class ApiResponse extends LitElement {
32
32
  activeSchemaTab: { type: String, attribute: 'active-schema-tab' },
33
33
  schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
34
34
  schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
35
- allowSchemaDescriptionExpandToggle: { type: String, attribute: 'allow-schema-description-expand-toggle' },
36
35
  schemaHideWriteOnly: { type: String, attribute: 'schema-hide-write-only' },
37
36
  };
38
37
  }
@@ -317,7 +316,6 @@ export default class ApiResponse extends LitElement {
317
316
  class = 'example-panel ${this.renderStyle === 'read' ? 'border pad-8-16' : 'border-top pad-top-8'}'
318
317
  schema-expand-level = "${this.schemaExpandLevel}"
319
318
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
320
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
321
319
  schema-hide-read-only = false
322
320
  schema-hide-write-only = ${this.schemaHideWriteOnly}
323
321
  > </schema-tree> `
@@ -328,7 +326,6 @@ export default class ApiResponse extends LitElement {
328
326
  class = 'example-panel ${this.renderStyle === 'read' ? 'border pad-8-16' : 'pad-top-8'}'
329
327
  schema-expand-level = "${this.schemaExpandLevel}"
330
328
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
331
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
332
329
  schema-hide-read-only = false
333
330
  schema-hide-write-only = ${this.schemaHideWriteOnly}
334
331
  > </schema-tree>`
@@ -76,7 +76,7 @@ export default class JsonTree extends LitElement {
76
76
  return html`
77
77
  <div class = "json-tree" >
78
78
  <div class='toolbar'>
79
- <button class="toolbar-btn" part="btn btn-fill" @click='${(e) => { copyToClipboard(JSON.stringify(this.data, null, 2), e); }}'> Copy </button>
79
+ <button class="toolbar-copy-btn" part="btn btn-fill" @click='${(e) => { copyToClipboard(JSON.stringify(this.data, null, 2), e); }}'>Copy</button>
80
80
  </div>
81
81
  ${this.generateTree(this.data, true)}
82
82
  </div>
@@ -9,7 +9,6 @@ export default class SchemaTable extends LitElement {
9
9
  return {
10
10
  schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
11
11
  schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
12
- allowSchemaDescriptionExpandToggle: { type: String, attribute: 'allow-schema-description-expand-toggle' },
13
12
  schemaHideReadOnly: { type: String, attribute: 'schema-hide-read-only' },
14
13
  schemaHideWriteOnly: { type: String, attribute: 'schema-hide-write-only' },
15
14
  data: { type: Object },
@@ -86,15 +85,10 @@ export default class SchemaTable extends LitElement {
86
85
  return html`
87
86
  <div class="table ${this.schemaDescriptionExpanded === 'true' ? 'expanded-descr' : 'collapsed-descr'}">
88
87
  <div class='toolbar'>
89
- ${this.allowSchemaDescriptionExpandToggle === 'true'
90
- ? html`
91
- <div style="flex:1"></div>
92
- <div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
93
- ${this.schemaDescriptionExpanded === 'true' ? 'Collapse description' : 'Expand description'}
94
- </div>
95
- `
96
- : ''
97
- }
88
+ <div style="flex:1"></div>
89
+ <div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
90
+ ${this.schemaDescriptionExpanded === 'true' ? 'Collapse description' : 'Expand description'}
91
+ </div>
98
92
  </div>
99
93
  ${this.data && this.data['::description']
100
94
  ? html`<span class='m-markdown'> ${unsafeHTML(marked(this.data['::description'] || ''))}</span>`
@@ -11,7 +11,6 @@ export default class SchemaTree extends LitElement {
11
11
  data: { type: Object },
12
12
  schemaExpandLevel: { type: Number, attribute: 'schema-expand-level' },
13
13
  schemaDescriptionExpanded: { type: String, attribute: 'schema-description-expanded' },
14
- allowSchemaDescriptionExpandToggle: { type: String, attribute: 'allow-schema-description-expand-toggle' },
15
14
  schemaHideReadOnly: { type: String, attribute: 'schema-hide-read-only' },
16
15
  schemaHideWriteOnly: { type: String, attribute: 'schema-hide-write-only' },
17
16
  };
@@ -91,18 +90,12 @@ export default class SchemaTree extends LitElement {
91
90
  render() {
92
91
  return html`
93
92
  <div class="tree ${this.schemaDescriptionExpanded === 'true' ? 'expanded-descr' : 'collapsed-descr'}">
94
- <div class="toolbar">
95
- ${this.allowSchemaDescriptionExpandToggle === 'true'
96
- ? html`
97
- <div style="flex:1"></div>
98
- <div class='toolbar-item' @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
99
- ${this.schemaDescriptionExpanded === 'true' ? 'Collapse description' : 'Expand description'}
100
- </div>
101
- `
102
- : ''
103
- }
93
+ <div class="toolbar" style="display: flex; justify-content: space-between; align-items: center">
94
+ ${this.data && this.data['::description'] ? html`<span class='m-markdown' style="margin-block-start: 0"> ${unsafeHTML(marked(this.data['::description'] || ''))}</span>` : '<div>&nbsp;</div>'}
95
+ <div class="toolbar-item" @click='${() => { this.schemaDescriptionExpanded = (this.schemaDescriptionExpanded === 'true' ? 'false' : 'true'); }}'>
96
+ ${this.schemaDescriptionExpanded === 'true' ? 'Collapse description' : 'Expand description'}
97
+ </div>
104
98
  </div>
105
- ${this.data && this.data['::description'] ? html`<span class='m-markdown'> ${unsafeHTML(marked(this.data['::description'] || ''))}</span>` : ''}
106
99
  ${this.data
107
100
  ? html`${this.generateTree(this.data['::type'] === 'array' ? this.data['::props'] : this.data, this.data['::type'])}`
108
101
  : html`<span class='mono-font' style='color:var(--red)'> Schema not found </span>`
@@ -84,7 +84,6 @@ export default class OpenApiExplorer extends LitElement {
84
84
  allowSearch: { type: String, attribute: 'allow-search' },
85
85
  allowAdvancedSearch: { type: String, attribute: 'allow-advanced-search' },
86
86
  allowServerSelection: { type: String, attribute: 'show-server-selection' },
87
- allowSchemaDescriptionExpandToggle: { type: String, attribute: 'allow-schema-description-expand-toggle' },
88
87
  showComponents: { type: String, attribute: 'show-components' },
89
88
 
90
89
  // Main Colors and Font
@@ -397,7 +396,6 @@ export default class OpenApiExplorer extends LitElement {
397
396
  if (!this.showInfo || !'true, false,'.includes(`${this.showInfo},`)) { this.showInfo = 'true'; }
398
397
  if (!this.allowServerSelection || !'true, false,'.includes(`${this.allowServerSelection},`)) { this.allowServerSelection = 'true'; }
399
398
  if (!this.allowAuthentication || !'true, false,'.includes(`${this.allowAuthentication},`)) { this.allowAuthentication = 'true'; }
400
- if (!this.allowSchemaDescriptionExpandToggle || !'true, false,'.includes(`${this.allowSchemaDescriptionExpandToggle},`)) { this.allowSchemaDescriptionExpandToggle = 'true'; }
401
399
 
402
400
  if (!this.showSideNav || !'true false'.includes(this.showSideNav)) { this.showSideNav = 'true'; }
403
401
  if (!this.showComponents || !'true false'.includes(this.showComponents)) { this.showComponents = 'false'; }
@@ -113,7 +113,11 @@ export default css`
113
113
 
114
114
  .m-markdown p,
115
115
  .m-markdown-small p {
116
- margin-block-end: 0
116
+ margin-block-end: 0;
117
+ }
118
+
119
+ .toolbar .m-markdown p, .toolbar .m-markdown-small p {
120
+ margin-block-start: 0;
117
121
  }
118
122
 
119
123
  .m-markdown code span {
@@ -44,21 +44,29 @@ export default css`
44
44
  cursor: progress;
45
45
  opacity: 0.4;
46
46
  }
47
- .toolbar-btn{
47
+ .toolbar-copy-btn{
48
48
  cursor: pointer;
49
- padding: 4px;
49
+ padding: .125rem .5rem;
50
50
  margin:0 2px;
51
- font-size: var(--font-size-small);
52
- min-width: 50px;
51
+ font-size: .8rem;
52
+ width: 56px;
53
53
  color: var(--primary-btn-text-color);
54
54
  border-radius: 2px;
55
55
  border: none;
56
56
  background-color: var(--primary-color);
57
57
  }
58
- .tab-content .toolbar-btn {
58
+ .tab-content .toolbar-copy-btn {
59
59
  position: absolute;
60
60
  top: 8px;
61
61
  right: 8px;
62
+ margin-right: 8px;
63
+ }
64
+ .tab-content .toolbar-copy-btn + pre {
65
+ white-space: pre;
66
+ max-height:400px;
67
+ overflow: auto;
68
+ display: flex;
69
+ padding-right: 70px;
62
70
  }
63
71
 
64
72
  input, textarea, select, button, pre {
@@ -75,14 +75,14 @@ export default css`
75
75
  .toolbar {
76
76
  width:100%;
77
77
  padding: 2px 0;
78
- color:var(--primary-color);
79
78
  }
80
79
  .toolbar-item {
81
80
  cursor: pointer;
82
- padding:5px 0;
83
- margin:0 2px;
81
+ padding: 5px 0 5px 1rem;
82
+ margin: 0 1rem !important;
84
83
  /* TODO: add: The import highlight color variable */
85
84
  color: #38b3f9;
85
+ flex-shrink: 0;
86
86
  }
87
87
  .schema-root-type {
88
88
  cursor:auto;
@@ -34,7 +34,6 @@ export default function callbackTemplate(callbacks) {
34
34
  active-schema-tab = "${this.defaultSchemaTab}"
35
35
  schema-expand-level = "${this.schemaExpandLevel}"
36
36
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
37
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}",
38
37
  schema-hide-read-only = "${this.schemaHideReadOnly}"
39
38
  fetch-credentials = "${this.fetchCredentials}"
40
39
  exportparts="btn btn-fill btn-outline btn-try">
@@ -48,7 +47,6 @@ export default function callbackTemplate(callbacks) {
48
47
  active-schema-tab = "${this.defaultSchemaTab}"
49
48
  schema-expand-level = "${this.schemaExpandLevel}"
50
49
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
51
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
52
50
  exportparts = "btn--resp btn-fill--resp btn-outline--resp"
53
51
  > </api-response>
54
52
  </div>
@@ -24,8 +24,8 @@ export default function codeSamplesTemplate(xCodeSamples) {
24
24
  </div>
25
25
  ${xCodeSamples.map((v, i) => html`
26
26
  <div class="tab-content m-markdown code-sample-wrapper" style= "display:${i === 0 ? 'block' : 'none'}" data-tab = '${v.lang}${i}'>
27
- <button class="toolbar-btn" @click='${(e) => { copyToClipboard(v.source, e); }}'> Copy </button>
28
- <pre style="white-space:pre; display: flex;">
27
+ <button class="toolbar-copy-btn" @click='${(e) => { copyToClipboard(v.source, e); }}'>Copy</button>
28
+ <pre>
29
29
  <code>${Prism.languages[v.lang && v.lang.toLowerCase()] ? unsafeHTML(Prism.highlight(v.source, Prism.languages[v.lang && v.lang.toLowerCase()], v.lang && v.lang.toLowerCase())) : v.source}</code>
30
30
  </pre>
31
31
  </div>`)
@@ -112,7 +112,6 @@ function endpointBodyTemplate(path) {
112
112
  schema-style = "${this.schemaStyle}"
113
113
  schema-expand-level = "${this.schemaExpandLevel}"
114
114
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
115
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
116
115
  schema-hide-read-only = "${this.schemaHideReadOnly}"
117
116
  fetch-credentials = "${this.fetchCredentials}"
118
117
  exportparts="btn btn-fill btn-outline btn-try">
@@ -127,7 +126,6 @@ function endpointBodyTemplate(path) {
127
126
  schema-style="${this.schemaStyle}"
128
127
  schema-expand-level = "${this.schemaExpandLevel}"
129
128
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
130
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
131
129
  schema-hide-write-only = "${this.schemaHideWriteOnly}"
132
130
  selected-status = "${Object.keys(path.responses || {})[0] || ''}"
133
131
  exportparts = "btn--resp btn-fill--resp btn-outline--resp"
@@ -138,7 +136,7 @@ function endpointBodyTemplate(path) {
138
136
 
139
137
  export default function endpointTemplate() {
140
138
  return html`
141
- <div style="display:flex; justify-content:flex-end; padding-right: 1rem; font-size: 14px;">
139
+ <div style="display:flex; justify-content:flex-end; padding-right: 1rem; font-size: 14px; margin-top: 16px;">
142
140
  <span @click="${(e) => expandCollapseAll.call(this, e, 'expand-all')}" style="color:var(--primary-color); cursor: pointer;">Expand</span>
143
141
  &nbsp;|&nbsp;
144
142
  <span @click="${(e) => expandCollapseAll.call(this, e, 'collapse-all')}" style="color:var(--primary-color); cursor: pointer;">Collapse</span>
@@ -61,7 +61,6 @@ export function expandedEndpointBodyTemplate(path, tagName = '') {
61
61
  active-schema-tab = "${this.defaultSchemaTab}"
62
62
  schema-expand-level = "${this.schemaExpandLevel}"
63
63
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
64
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
65
64
  schema-hide-read-only = "${this.schemaHideReadOnly}"
66
65
  fetch-credentials = "${this.fetchCredentials}"
67
66
  exportparts = "btn btn-fill btn-outline btn-try"
@@ -77,7 +76,6 @@ export function expandedEndpointBodyTemplate(path, tagName = '') {
77
76
  active-schema-tab = "${this.defaultSchemaTab}"
78
77
  schema-expand-level = "${this.schemaExpandLevel}"
79
78
  schema-description-expanded = "${this.schemaDescriptionExpanded}"
80
- allow-schema-description-expand-toggle = "${this.allowSchemaDescriptionExpandToggle}"
81
79
  schema-hide-write-only = "${this.schemaHideWriteOnly}"
82
80
  selected-status = "${Object.keys(path.responses || {})[0] || ''}"
83
81
  exportparts = "btn--resp btn-fill--resp btn-outline--resp"
@@ -71,8 +71,7 @@ export default function focusedEndpointTemplate() {
71
71
  focusedTemplate = serverTemplate.call(this);
72
72
  } else if (focusElId === 'section') {
73
73
  focusedTemplate = html`
74
- <section id='section' style="margin-top:24px; margin-bottom:24px;"
75
- class='observe-me ${this.renderStyle === 'focused' ? 'section-gap--focused-mode' : 'section-gap'}'>
74
+ <section id='section' class='observe-me'>
76
75
  <slot name="custom-section"></slot>
77
76
  </section>`;
78
77
  } else if (focusElId.startsWith('cmp--') && this.showComponents === 'true') {
@@ -94,12 +94,14 @@ export function getTypeInfo(schema) {
94
94
  return info;
95
95
  }
96
96
 
97
- export function getSampleValueByType(schemaObj, fallbackPropertyName) {
97
+ export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleStrings) {
98
98
  const example = schemaObj.examples ? schemaObj.examples[0] : schemaObj.example;
99
99
  if (example === '') { return ''; }
100
100
  if (example === null) { return null; }
101
101
  if (example === 0) { return 0; }
102
+ if (skipExampleStrings && typeof example === 'string') { return ''; }
102
103
  if (example) { return example; }
104
+
103
105
  if (schemaObj.default) { return schemaObj.default; }
104
106
 
105
107
  if (Object.keys(schemaObj).length === 0) {
@@ -130,6 +132,7 @@ export function getSampleValueByType(schemaObj, fallbackPropertyName) {
130
132
  }
131
133
  if (typeValue.match(/^boolean/g)) { return false; }
132
134
  if (typeValue.match(/^null/g)) { return null; }
135
+ if (skipExampleStrings && typeValue.match(/^string/g)) { return ''; }
133
136
  if (typeValue.match(/^string/g)) {
134
137
  if (schemaObj.enum) { return schemaObj.enum[0]; }
135
138
  if (schemaObj.pattern) {
@@ -267,22 +270,10 @@ function getExampleValuesFromSchemaRecursive(schema, config = {}) {
267
270
  return config.xml ? [xmlTagProperties] : objectExamples;
268
271
  }
269
272
 
270
- const value = getSampleValueByType(schema, config.propertyName);
273
+ const value = getSampleValueByType(schema, config.propertyName, config.skipExampleStrings);
271
274
  return [value];
272
275
  }
273
276
 
274
- function addSchemaInfoToExample(schema, obj) {
275
- if (typeof obj !== 'object' || obj === null) {
276
- return;
277
- }
278
- if (schema.title) {
279
- obj['::TITLE'] = schema.title;
280
- }
281
- if (schema.description) {
282
- obj['::DESCRIPTION'] = schema.description;
283
- }
284
- }
285
-
286
277
  function removeTitlesAndDescriptions(obj) {
287
278
  if (typeof obj !== 'object' || obj === null) {
288
279
  return;
@@ -294,173 +285,6 @@ function removeTitlesAndDescriptions(obj) {
294
285
  }
295
286
  }
296
287
 
297
- function addPropertyExampleToObjectExamples(example, obj, propertyKey) {
298
- for (const key in obj) {
299
- obj[key][propertyKey] = example;
300
- }
301
- }
302
-
303
- function mergePropertyExamples(obj, propertyName, propExamples) {
304
- // Create an example for each variant of the propertyExample, merging them with the current (parent) example
305
- let i = 0;
306
- const maxCombinations = 10;
307
- const mergedObj = {};
308
- for (const exampleKey in obj) {
309
- for (const propExampleKey in propExamples) {
310
- mergedObj[`example-${i}`] = { ...obj[exampleKey] };
311
- mergedObj[`example-${i}`][propertyName] = propExamples[propExampleKey];
312
- i++;
313
- if (i >= maxCombinations) {
314
- break;
315
- }
316
- }
317
- if (i >= maxCombinations) {
318
- break;
319
- }
320
- }
321
- return mergedObj;
322
- }
323
-
324
- /* For changing JSON-Schema to a Sample Object, as per the schema (to generate examples based on schema) */
325
- export function schemaToSampleObj(schema, config = { }) {
326
- let obj = {};
327
- if (!schema) {
328
- return null;
329
- }
330
-
331
- if (schema.allOf) {
332
- const objWithAllProps = {};
333
-
334
- if (schema.allOf.length === 1 && !schema.allOf[0].properties && !schema.allOf[0].items) {
335
- // If allOf has single item and the type is not an object or array, then its a primitive
336
- if (schema.allOf[0].$ref) {
337
- return schema.allOf[0].$ref;
338
- }
339
- if (schema.allOf[0].readOnly && config.includeReadOnly) {
340
- const tempSchema = schema.allOf[0];
341
- return getSampleValueByType(tempSchema, config.propertyName);
342
- }
343
- return null;
344
- }
345
-
346
- schema.allOf.forEach((v) => {
347
- if (v.type === 'object' || v.properties || v.allOf || v.anyOf || v.oneOf) {
348
- const partialObj = schemaToSampleObj(v, config);
349
- Object.assign(objWithAllProps, partialObj);
350
- } else if (v.type === 'array' || v.items) {
351
- const partialObj = [schemaToSampleObj(v, config)];
352
- Object.assign(objWithAllProps, partialObj);
353
- } else if (v.type) {
354
- const prop = `prop${Object.keys(objWithAllProps).length}`;
355
- objWithAllProps[prop] = getSampleValueByType(v, config.propertyName);
356
- }
357
- });
358
-
359
- return objWithAllProps;
360
- }
361
-
362
- if (schema.oneOf) {
363
- if (!schema.oneOf.length) {
364
- return obj;
365
- }
366
-
367
- const objWithSchemaProps = {};
368
- for (const propertyName in (schema.properties || {})) {
369
- objWithSchemaProps[propertyName] = getSampleValueByType(schema.properties[propertyName], config.propertyName);
370
- }
371
-
372
- let i = 0;
373
- // Add all the oneof to examples
374
- for (const key in schema.oneOf) {
375
- const oneOfSamples = schemaToSampleObj(schema.oneOf[key], config);
376
- for (const sampleKey in oneOfSamples) {
377
- obj[`example-${i}`] = Object.assign({}, objWithSchemaProps, oneOfSamples[sampleKey]);
378
- addSchemaInfoToExample(schema.oneOf[key], obj[`example-${i}`]);
379
- i++;
380
- }
381
- }
382
- } else if (schema.anyOf) {
383
- // First generate values for regular properties
384
- let commonObj;
385
- if (schema.type === 'object' || schema.properties) {
386
- commonObj = { 'example-0': {} };
387
- for (const propertyName in schema.properties) {
388
- if (schema.example) {
389
- commonObj = schema;
390
- break;
391
- }
392
- if (schema.properties[propertyName].deprecated && !config.includeDeprecated) { continue; }
393
- if (schema.properties[propertyName].readOnly && !config.includeReadOnly) { continue; }
394
- if (schema.properties[propertyName].writeOnly && !config.includeWriteOnly) { continue; }
395
- commonObj = mergePropertyExamples(commonObj, propertyName, schemaToSampleObj(schema.properties[propertyName], { ...config, propertyName }));
396
- }
397
- }
398
-
399
- // Combine every variant of the regular properties with every variant of the anyOf samples
400
- let i = 0;
401
- for (const key in schema.anyOf) {
402
- const anyOfSamples = schemaToSampleObj(schema.anyOf[key], config);
403
- for (const sampleKey in anyOfSamples) {
404
- if (typeof commonObj !== 'undefined') {
405
- for (const commonKey in commonObj) {
406
- obj[`example-${i}`] = { ...commonObj[commonKey], ...anyOfSamples[sampleKey] };
407
- }
408
- } else {
409
- obj[`example-${i}`] = anyOfSamples[sampleKey];
410
- }
411
- addSchemaInfoToExample(schema.anyOf[key], obj[`example-${i}`]);
412
- i++;
413
- }
414
- }
415
- } else if (schema.type === 'object' || schema.properties) {
416
- obj['example-0'] = {};
417
- addSchemaInfoToExample(schema, obj['example-0']);
418
- if (schema.example) {
419
- obj['example-0'] = schema.example;
420
- } else {
421
- for (const propertyName in schema.properties) {
422
- if (schema.properties[propertyName].deprecated && !config.includeDeprecated) { continue; }
423
- if (schema.properties[propertyName].readOnly && !config.includeReadOnly) { continue; }
424
- if (schema.properties[propertyName].writeOnly && !config.includeWriteOnly) { continue; }
425
- if (schema.properties[propertyName].type === 'array' || schema.properties[propertyName].items) {
426
- if (schema.properties[propertyName].example) {
427
- addPropertyExampleToObjectExamples(schema.properties[propertyName].example, obj, propertyName);
428
- } else if (schema.properties[propertyName] && schema.properties[propertyName].items && schema.properties[propertyName].items.example) {
429
- // schemas and properties support single example but not multiple examples.
430
- addPropertyExampleToObjectExamples([schema.properties[propertyName].items.example], obj, propertyName);
431
- } else {
432
- const itemSamples = schemaToSampleObj(schema.properties[propertyName].items, { ...config, propertyName });
433
- const arraySamples = [];
434
- for (const key in itemSamples) {
435
- arraySamples[key] = [itemSamples[key]];
436
- }
437
- obj = mergePropertyExamples(obj, propertyName, arraySamples);
438
- }
439
- continue;
440
- }
441
- obj = mergePropertyExamples(obj, propertyName, schemaToSampleObj(schema.properties[propertyName], { ...config, propertyName }));
442
- }
443
- }
444
- } else if (schema.type === 'array' || schema.items) {
445
- if (schema.example) {
446
- obj['example-0'] = schema.example;
447
- } else if (schema.items && schema.items.example) { // schemas and properties support single example but not multiple examples.
448
- obj['example-0'] = [schema.items.example];
449
- } else {
450
- const samples = schemaToSampleObj(schema.items, config);
451
- let i = 0;
452
- for (const key in samples) {
453
- obj[`example-${i}`] = [samples[key]];
454
- addSchemaInfoToExample(schema.items, obj[`example-${i}`]);
455
- i++;
456
- }
457
- }
458
- } else {
459
- return { 'example-0': getSampleValueByType(schema, config.propertyName) };
460
- }
461
- return obj;
462
- }
463
-
464
288
  /**
465
289
  * For changing OpenAPI-Schema to an Object Notation,
466
290
  * This Object would further be an input to UI Components to generate an Object-Tree
@@ -643,7 +467,7 @@ export function schemaInObjectNotation(schema, obj, level = 0, suffix = '') {
643
467
  }
644
468
 
645
469
  /* Create Example object */
646
- export function generateExample(examples, example, schema, rawMimeType, includeReadOnly = true, includeWriteOnly = true, outputType) {
470
+ export function generateExample(examples, example, schema, rawMimeType, includeReadOnly = true, includeWriteOnly = true, outputType, skipExampleStrings = false) {
647
471
  const mimeType = rawMimeType || 'application/json';
648
472
  const finalExamples = [];
649
473
  // First check if examples is provided
@@ -735,6 +559,7 @@ export function generateExample(examples, example, schema, rawMimeType, includeR
735
559
  includeReadOnly,
736
560
  includeWriteOnly,
737
561
  includeDeprecated: true,
562
+ skipExampleStrings,
738
563
  xml: mimeType.toLowerCase().includes('xml'),
739
564
  };
740
565