Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve allowed values display. #246

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This package follows standard semvar, `<major>.<minor>.<build>`. No breaking cha
* Handle invalid JSON parsing in request bodies
* Fix the request body that keeps changing preventing editing of it.
* Set min height on syntax rendering to be 2rem, so that the copy button always fully shows correctly.
* Fix default display when the value is falsy.

## 2.1
* Add `x-locale` vendor extension to specify the locale of the spec.
Expand Down
6 changes: 3 additions & 3 deletions src/components/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class ApiRequest extends LitElement {
@change="${(e) => { this.storedParamValues[param.name] = e.detail.value; this.computeCurlSyntax(); }}">
${paramSchema.allowedValues.map((allowedValue) => html`
<option value="${allowedValue}" ?selected = '${allowedValue === this.storedParamValues[param.name]}'>
${allowedValue}
${allowedValue === null ? '-' : allowedValue}
</option>`
)}
</select>`
Expand Down Expand Up @@ -251,15 +251,15 @@ export default class ApiRequest extends LitElement {
${html`
<a part="anchor anchor-param-constraint" class = "${this.allowTry === 'true' ? '' : 'inactive-link'}"
data-type="${paramSchema.type === 'array' ? 'array' : 'string'}"
data-enum="${v.trim()}"
data-enum="${v?.trim()}"
@click="${(e) => {
const inputEl = e.target.closest('table').querySelector(`[data-pname="${param.name}"]`);
if (inputEl) {
inputEl.value = e.target.dataset.type === 'array' ? [e.target.dataset.enum] : e.target.dataset.enum;
}
}}"
>
${v}
${v === null ? '-' : v}
</a>`
}`)}
</div>`
Expand Down
2 changes: 1 addition & 1 deletion src/components/api-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default class ApiResponse extends LitElement {
<div class="m-markdown-small regular-font" >${unsafeHTML(marked(v.description || ''))}</div>
</td>
<td style="padding:8px; vertical-align: baseline; border-top: 1px solid var(--light-border-color); text-overflow: ellipsis;">
${typeData?.example || typeData?.default || ''}
${typeData?.example ?? typeData?.default ?? ''}
</td>
</tr>
`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/request-form-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ function generatePrimitiveRow(rowData, parentRecursionOptions) {
${html`
<a part="anchor anchor-param-constraint"
data-type="${type === 'array' ? type : 'string'}"
data-enum="${v.trim()}"
data-enum="${v?.trim()}"
@click="${(e) => {
const inputEl = e.target.closest('table').querySelector(`[data-pname="${keyLabel}"]`);
if (inputEl) {
inputEl.value = e.target.dataset.type === 'array' ? [e.target.dataset.enum] : e.target.dataset.enum;
}
this.computeCurlSyntax();
}}">
${v}
${v === null ? '-' : v}
</a>`
}`)
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/schema-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ export default class SchemaTable extends LitElement {
${unsafeHTML(marked(`${`${(schemaTitle || title) ? `**${schemaTitle || title}${schemaDescription || description ? ':' : ''}**` : ''} ${schemaDescription || description}` || ''}`))}
</span>
${constraints.length ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px;'><span class='bold-text'>Constraints: </span>${constraints.join(', ')}</div><br>` : ''}
${defaultValue ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div><br>` : ''}
${allowedValues ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues.join('')}</div><br>` : ''}
${defaultValue !== '' ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div><br>` : ''}
${allowedValues ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues.filter(v => v !== null && v !== undefined).join('')}</div><br>` : ''}
${pattern ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Pattern: </span>${pattern}</div><br>` : ''}
${example ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Example: </span>${example}</div><br>` : ''}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/schema-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ export default class SchemaTree extends LitElement {
</span>
${this.schemaDescriptionExpanded ? html`
${constraints.length ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Constraints: </span>${constraints.join(', ')}</div><br>` : ''}
${defaultValue ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div><br>` : ''}
${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues.join('')}</div><br>` : ''}
${defaultValue !== '' ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Default: </span>${defaultValue}</div><br>` : ''}
${allowedValues ? html`<div style='display:inline-block; line-break:anywhere; margin-right:8px'><span class='bold-text'>Allowed: </span>${allowedValues.filter(v => v !== null && v !== undefined).join('')}</div><br>` : ''}
${pattern ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Pattern: </span>${pattern}</div><br>` : ''}
${example ? html`<div style='display:inline-block; line-break: anywhere; margin-right:8px'><span class='bold-text'>Example: </span>${example}</div><br>` : ''}` : ''}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getTypeInfo(parameter, options = { includeNulls: false, enableEx
readOrWriteOnly: schema.readOnly && '🆁' || schema.writeOnly && '🆆' || '',
deprecated: !!schema.deprecated,
example: examples || '',
default: schema.default || '',
default: schema.default ?? '',
title: schema.title || '',
description: schema.description || '',
constraints: [],
Expand Down
Loading