Skip to content

Commit da8ced5

Browse files
committed
Fixes #266 - form-data constraints and example should be shown
1 parent ae6f1b9 commit da8ced5

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

docs/specs/request-body-multiple.yaml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ paths:
2020
value: |
2121
{
2222
amount: 10,
23-
currency: USD
23+
currency: USD,
24+
converstion: 'use-avg'
2425
}
2526
INR:
2627
description: Cost in `Indian Price`
2728
value: |
2829
{
2930
amount: 700,
30-
currency: INR
31+
currency: INR,
32+
converstion: 'use-avg'
3133
}
3234
application/xml:
3335
schema:
@@ -39,11 +41,13 @@ paths:
3941
price-in-indian-rupee:
4042
value: |
4143
amount: 700,
42-
currency: INR
44+
currency: INR,
45+
converstion: 'use-avg'
4346
price-in-us-dollars:
4447
value: |
4548
amount: 10,
46-
currency: USD
49+
currency: USD,
50+
converstion: 'use-avg'
4751
multipart/form-data:
4852
schema:
4953
$ref: "#/components/schemas/Price"
@@ -78,9 +82,25 @@ components:
7882
properties:
7983
amount:
8084
type: integer
85+
required: true
8186
description: Amount rounded to nearest integer
8287
example: 10
8388
default: 20
89+
minimum: 5
90+
maximum: 100
91+
format: int32
8492
currency:
8593
type: string
94+
description: Currency code
95+
converstion:
96+
type: array
97+
minItems: 1
98+
maxItems: 3
99+
items:
100+
type: string
101+
enum:
102+
- use-min
103+
- use-max
104+
- use-avg
105+
default: use-avg
86106

src/components/api-request.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,8 @@ export default class ApiRequest extends LitElement {
513513
for (const fieldName in schema.properties) {
514514
const fieldSchema = schema.properties[fieldName];
515515
const fieldType = fieldSchema.type;
516-
const arrayType = fieldSchema.type === 'array' ? fieldSchema.items.type : '';
517516
const formdataPartSchema = schemaInObjectNotation(fieldSchema, {});
517+
const paramSchema = getTypeInfo(fieldSchema);
518518
const formdataPartExample = generateExample(
519519
'',
520520
fieldSchema.example ? fieldSchema.example : '',
@@ -527,13 +527,13 @@ export default class ApiRequest extends LitElement {
527527
formDataTableRows.push(html`
528528
<tr>
529529
<td rowspan="${this.allowTry === 'true' ? '1' : '2'}" style="width:160px; min-width:100px;">
530-
<div class="param-name">${fieldName}</div>
531-
<div class="param-type">
532-
${fieldType === 'array'
533-
? `${fieldType} of ${arrayType}`
534-
: `${fieldType} ${fieldSchema.format ? `\u00a0(${fieldSchema.format})` : ''}`
530+
<div class="param-name">
531+
${fieldSchema.required
532+
? html`<span style='color:var(--red);'>*</span>${fieldName}`
533+
: html`${fieldName}`
535534
}
536535
</div>
536+
<div class="param-type">${paramSchema.type}</div>
537537
</td>
538538
<td style="${fieldType === 'object' ? 'width:100%; padding:0;' : 'width:160px;'} min-width:100px;">
539539
${fieldType === 'array'
@@ -612,22 +612,34 @@ export default class ApiRequest extends LitElement {
612612
}
613613
</div>`
614614
: html`
615-
${this.allowTry === 'true'
616-
? html`<input
617-
spellcheck = "false"
618-
type = "${fieldSchema.format === 'binary' ? 'file' : fieldSchema.format === 'password' ? 'password' : 'text'}"
619-
style = "width:200px"
620-
data-ptype = "${mimeType.includes('form-urlencode') ? 'form-urlencode' : 'form-data'}"
621-
data-pname = "${fieldName}"
622-
data-array = "false"
623-
/>`
624-
: ''
615+
${this.allowTry === 'true' || fieldSchema.example
616+
? html`<input
617+
value = "${fieldSchema.example || ''}"
618+
spellcheck = "false"
619+
type = "${fieldSchema.format === 'binary' ? 'file' : fieldSchema.format === 'password' ? 'password' : 'text'}"
620+
style = "width:200px"
621+
data-ptype = "${mimeType.includes('form-urlencode') ? 'form-urlencode' : 'form-data'}"
622+
data-pname = "${fieldName}"
623+
data-array = "false"
624+
/>`
625+
: ''
626+
}
627+
`
625628
}`
626-
}`
627629
}
628630
</td>
629631
<td>
630-
<div class="param-constraint"></div>
632+
<div class="param-constraint">
633+
${paramSchema.default || paramSchema.constrain || paramSchema.allowedValues
634+
? html`
635+
<div class="param-constraint">
636+
${paramSchema.default ? html`<span style="font-weight:bold">Default: </span>${paramSchema.default}<br/>` : ''}
637+
${paramSchema.constrain ? html`${paramSchema.constrain}<br/>` : ''}
638+
${paramSchema.allowedValues ? html`<span style="font-weight:bold">Allowed: </span>${paramSchema.allowedValues}` : ''}
639+
</div>`
640+
: ''
641+
}
642+
</div>
631643
</td>
632644
</tr>
633645
<tr>

0 commit comments

Comments
 (0)