MCPcopy
hub / github.com/rapi-doc/RapiDoc / formDataTemplate

Method formDataTemplate

src/components/api-request.js:876–1022  ·  view source on GitHub ↗
(schema, mimeType, exampleValue = '')

Source from the content-addressed store, hash-verified

874 }
875
876 formDataTemplate(schema, mimeType, exampleValue = '') {
877 const formDataTableRows = [];
878 if (schema.properties) {
879 for (const fieldName in schema.properties) {
880 const fieldSchema = schema.properties[fieldName];
881 if (fieldSchema.readOnly) {
882 continue;
883 }
884 const fieldExamples = fieldSchema.examples || fieldSchema.example || '';
885 const fieldType = fieldSchema.type;
886 const paramSchema = getTypeInfo(fieldSchema);
887 const labelColWidth = 'read focused'.includes(this.renderStyle) ? '200px' : '160px';
888 const example = normalizeExamples((paramSchema.examples || paramSchema.example), paramSchema.type);
889 formDataTableRows.push(html`
890 <tr title="${fieldSchema.deprecated ? 'Deprecated' : ''}">
891 <td style="width:${labelColWidth}; min-width:100px;">
892 <div class="param-name ${fieldSchema.deprecated ? 'deprecated' : ''}">
893 ${fieldName}${(schema.required?.includes(fieldName) || fieldSchema.required) ? html`<span style='color:var(--red);'>*</span>` : ''}
894 </div>
895 <div class="param-type">${paramSchema.type}</div>
896 </td>
897 <td
898 style="${fieldType === 'object' ? 'width:100%; padding:0;' : this.allowTry === 'true' ? '' : 'display:none;'} min-width:100px;"
899 colspan="${fieldType === 'object' ? 2 : 1}">
900 ${fieldType === 'array'
901 ? fieldSchema.items?.format === 'binary'
902 ? html`
903 <div class="file-input-container col" style='align-items:flex-end;' @click="${(e) => this.onAddRemoveFileInput(e, fieldName, mimeType)}">
904 <div class='input-set row'>
905 <input
906 type = "file"
907 part = "file-input"
908 style = "width:100%"
909 data-pname = "${fieldName}"
910 data-ptype = "${mimeType.includes('form-urlencode') ? 'form-urlencode' : 'form-data'}"
911 data-array = "false"
912 data-file-array = "true"
913 />
914 <button class="file-input-remove-btn"> &#x2715; </button>
915 </div>
916 <button class="m-btn primary file-input-add-btn" part="btn btn-fill" style="margin:2px 25px 0 0; padding:2px 6px;">ADD</button>
917 </div>
918 `
919 : html`
920 <tag-input
921 style = "width:100%"
922 data-ptype = "${mimeType.includes('form-urlencode') ? 'form-urlencode' : 'form-data'}"
923 data-pname = "${fieldName}"
924 data-example = "${Array.isArray(fieldExamples) ? fieldExamples.join('~|~') : fieldExamples}"
925 data-array = "true"
926 placeholder = "add-multiple &#x21a9;"
927 .value = "${Array.isArray(fieldExamples) ? Array.isArray(fieldExamples[0]) ? fieldExamples[0] : fieldExamples : []}"
928 >
929 </tag-input>
930 `
931 : html`
932 ${fieldType === 'object'
933 ? this.formDataParamAsObjectTemplate.call(this, fieldName, fieldSchema, mimeType)

Callers 1

requestBodyTemplateMethod · 0.95

Calls 8

onAddRemoveFileInputMethod · 0.95
getTypeInfoFunction · 0.90
normalizeExamplesFunction · 0.90
htmlFunction · 0.85
markedFunction · 0.50
includesMethod · 0.45
pushMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected