Skip to content

Fixed examples displaying in the Operation details widget in knockout #2745

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

Merged
merged 1 commit into from
Jan 15, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ <h4>Request body</h4>
<div class="tab-content">
<!-- ko if: representation.typeName -->
<type-definition
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: $component.getDefinitionForRepresentation(representation), defaultSchemaView: $component.defaultSchemaView }">
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: $component.getDefinitionForRepresentation(representation), defaultSchemaView: $component.defaultSchemaView, showExamples: $component.showExamples }">
</type-definition>
<!-- /ko -->

Expand Down Expand Up @@ -265,7 +265,7 @@ <h4>Response headers</h4>
<div class="tab-content">
<!-- ko if: representation.typeName -->
<type-definition
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: $component.getDefinitionForRepresentation(representation), defaultSchemaView: $component.defaultSchemaView, examples: $component.examples()[response.identifier]?.[representation.contentType] }">
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: $component.getDefinitionForRepresentation(representation), defaultSchemaView: $component.defaultSchemaView, showExamples: $component.showExamples }">
</type-definition>
<!-- /ko -->

Expand Down Expand Up @@ -308,7 +308,7 @@ <h3>Definitions</h3>

<!-- ko foreach: { data: definitions, as: 'definition' } -->
<type-definition
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: definition, anchor: true, defaultSchemaView: $component.defaultSchemaView }">
params="{ apiName: $component.api().name, operationName: $component.operation().name, definition: definition, anchor: true, defaultSchemaView: $component.defaultSchemaView, showExamples: $component.showExamples }">
</type-definition>
<!-- /ko -->
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!-- ko if: properties.length > 0 -->

<div role="table" class="table-preset table-preset-schema" data-bind="css: {'table-preset-schema-examples': $component.examples, 'table-preset-schema-readonly': readOnly}">
<div role="table" class="table-preset table-preset-schema" data-bind="css: {'table-preset-schema-examples': $component.showExamples, 'table-preset-schema-readonly': readOnly}">
<div class="d-contents" role="rowgroup">
<div class="d-contents" role="row">
<div role="columnheader" class="table-preset-head text-truncate">Name</div>
Expand All @@ -9,7 +9,7 @@
<div role="columnheader" class="table-preset-head text-truncate">Read-only</div>
<!-- /ko -->
<div role="columnheader" class="table-preset-head text-truncate">Type</div>
<!-- ko if: $component.examples -->
<!-- ko if: $component.showExamples -->
<div role="columnheader" class="table-preset-head text-truncate">Example</div>
<!-- /ko -->
<div role="columnheader" class="table-preset-head">Description</div>
Expand Down Expand Up @@ -66,7 +66,7 @@

<!-- /ko -->
</div>
<!-- ko if: $component.examples -->
<!-- ko if: $component.showExamples -->
<div role="cell" class="text-truncate" data-bind="text: property.example, attr: {title: property.example}"></div>
<!-- /ko -->
<div role="cell" data-bind="markdown: property.description"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class TypeDefinitionViewModel {
this.rawSchemaFormat = ko.observable();
this.schemaView = ko.observable();
this.defaultSchemaView = ko.observable();
this.showExamples = ko.observable(false);
}

@Param()
Expand All @@ -54,6 +55,9 @@ export class TypeDefinitionViewModel {
@Param()
public examples?: Record<string, string>;

@Param()
public showExamples?: ko.Observable<boolean>;

@OnMounted()
public initialize(): void {
this.schemaView(this.defaultSchemaView() || "table");
Expand Down