in src/models/console/consoleRequest.ts [28:88]
constructor(request: Request) {
this.description = request.description;
this.representations = request.representations.map(representation => new ConsoleRepresentation(representation));
this.queryParameters = ko.observableArray(request.queryParameters.map(parameter => new ConsoleParameter(parameter)));
this.headers = ko.observableArray(request.headers.map(header => new ConsoleHeader(header)));
this.meaningfulHeaders = ko.computed(() => this.headers().filter(x => !!x.value()));
this.body = ko.observable();
this.isBodyEdited = ko.observable(false);
this.binary = ko.observable();
this.binary.extend(<any>{ maxFileSize: 3 * 1024 * 1024 });
this.bodyFormat = ko.observable(RequestBodyType.raw);
this.bodyDataItems = ko.observableArray([]);
this.sample = "";
this.selectedRepresentation = ko.observable(this.representations[0]);
this.selectedRepresentation.subscribe(representation => {
this.sample = representation.sample;
this.body(this.sample);
this.representationContentType = representation.contentType;
});
this.body.subscribe(body => this.isBodyEdited(body !== this.sample));
if (this.representations?.length === 0) {
return;
}
const representation = this.representations[0];
this.body(representation.sample);
this.representationContentType = representation.contentType;
// do not convert formParameters for contentType = application/x-www-form-urlencoded
// do not add Content-Type header for multipart/form-data
const bodyRepresentation = this.representationContentType === "multipart/form-data" && request.representations.find(r => r.formParameters?.length > 0);
if (bodyRepresentation) {
this.hasBody = true;
this.readonlyBodyFormat = true;
this.bodyFormat(RequestBodyType.form);
const dataItems = bodyRepresentation.formParameters.map(parameter => {
const item = new FormDataItem();
item.name(parameter.name);
item.type(parameter.type);
item.description(parameter.description);
item.required(parameter.required);
return item;
});
this.bodyDataItems(dataItems);
}
else if (this.representationContentType && this.headers().find(h => h.name() === KnownHttpHeaders.ContentType) === undefined) {
const consoleHeader = new ConsoleHeader();
consoleHeader.name(KnownHttpHeaders.ContentType);
consoleHeader.value(this.representationContentType);
this.headers.push(consoleHeader);
}
}