diff --git a/src/components/operations/operation-details/ko/runtime/operation-details.html b/src/components/operations/operation-details/ko/runtime/operation-details.html index da923e7c4..c8cf09854 100644 --- a/src/components/operations/operation-details/ko/runtime/operation-details.html +++ b/src/components/operations/operation-details/ko/runtime/operation-details.html @@ -175,11 +175,30 @@

Request body

- + +
+
+ +
+
+
+ +
+
+
+ + + + + + + + params="{ title: representation.examples[0].title, content: representation.examples[0].value, language: representation.examples[0].format, description: representation.examples[0].description }"> + diff --git a/src/components/operations/operation-details/ko/runtime/operation-details.ts b/src/components/operations/operation-details/ko/runtime/operation-details.ts index 32fe6fc3e..91f1ea886 100644 --- a/src/components/operations/operation-details/ko/runtime/operation-details.ts +++ b/src/components/operations/operation-details/ko/runtime/operation-details.ts @@ -52,6 +52,9 @@ export class OperationDetails { public readonly protocol: ko.Computed; public readonly examples: ko.Observable; + public readonly selectedRepresentatnionsValue: ko.Observable; + + constructor( private readonly apiService: ApiService, private readonly oauthService: OAuthService, @@ -73,6 +76,8 @@ export class OperationDetails { this.defaultSchemaView = ko.observable("table"); this.useCorsProxy = ko.observable(); this.includeAllHostnames = ko.observable(); + this.selectedRepresentatnionsValue = ko.observable(); + this.requestUrlSample = ko.computed(() => { const api = this.api(); @@ -115,6 +120,7 @@ export class OperationDetails { return api.protocols?.join(", "); }); + this.examples = ko.observable({}); this.apiType = ko.observable(); @@ -231,7 +237,10 @@ export class OperationDetails { if (operation) { await this.loadDefinitions(operation); - if (this.showExamples) this.parseExamples(operation); + if (this.showExamples) this.parseResponseExamples(operation); + + this.loadRequestExamples(operation); + this.operation(operation); } else { @@ -244,6 +253,19 @@ export class OperationDetails { this.working(false); } + public async loadRequestExamples(operation: Operation): Promise { + const representations = operation.request.meaningfulRepresentations(); + const requestExamples = {}; + if (representations && representations.length) { + for(let i = 0; i < representations.length; i++) { + const value = representations[i].examples?.[0]; + if (!value) continue; + requestExamples[representations[i].contentType] = ko.observable(value.title); + } + } + this.selectedRepresentatnionsValue(requestExamples); + } + public async loadDefinitions(operation: Operation): Promise { const cachedDefinitions = this.definitionsCache.getItem(operation.id); if (cachedDefinitions) { @@ -346,11 +368,11 @@ export class OperationDetails { return result; } - private parseExamples(operation: Operation): void { + private parseResponseExamples(operation: Operation): void { const examples = operation.getMeaningfulResponses().reduce((acc, cur) => { const representations = cur.meaningfulRepresentations(); if (!representations || !representations.length) return acc; - + const examplesObj = {} representations.forEach(representation => { const value = representation.examples?.[0]?.value; diff --git a/src/themes/website/styles/operations.scss b/src/themes/website/styles/operations.scss new file mode 100644 index 000000000..b54f4169d --- /dev/null +++ b/src/themes/website/styles/operations.scss @@ -0,0 +1,11 @@ +.example-form-control{ + padding-left: 8px; + + label { + font-weight: bold; + } + + select { + margin-bottom: 0px; + } +} \ No newline at end of file diff --git a/src/themes/website/styles/styles.scss b/src/themes/website/styles/styles.scss index 3330aa1c5..148bd2bcf 100644 --- a/src/themes/website/styles/styles.scss +++ b/src/themes/website/styles/styles.scss @@ -31,3 +31,4 @@ @import "gql.scss"; @import "details.scss"; @import "subscriptions.scss"; +@import "operations.scss"; \ No newline at end of file