Skip to content

Commit f792273

Browse files
committed
support x-example for parameters
closes #297
1 parent b84177c commit f792273

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

demo/swagger.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ paths:
242242
in: header
243243
required: false
244244
type: string
245+
x-example: Bearer <TOKEN>
245246
- name: petId
246247
in: path
247248
description: Pet id to delete

lib/components/JsonSchema/_json-schema-common.scss

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
6464
font-weight: bold;
6565
}
6666

67-
.param-type, .param-array-format {
67+
.param-type,
68+
.param-array-format {
6869
vertical-align: middle;
6970
line-height: $param-name-height;
7071
color: rgba($black, 0.4);
@@ -73,7 +74,8 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
7374
.param-type {
7475
font-weight: normal;
7576
word-break: break-all;
76-
&.array::before, &.tuple::before {
77+
&.array::before,
78+
&.tuple::before {
7779
color: $black;
7880
font-weight: $base-font-weight;
7981
.param-collection-format-multi + & {
@@ -144,7 +146,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
144146
}
145147

146148
.param:first-of-type {
147-
148149
> .param-name::before {
149150
content: '';
150151
display: block;
@@ -158,7 +159,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
158159

159160
.param:last-of-type,
160161
.param.last {
161-
162162
> .param-name {
163163
position: relative;
164164

@@ -236,14 +236,24 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
236236
}
237237
}
238238

239+
.param-example {
240+
font-size: 0.95em;
241+
242+
&::before {
243+
content: 'Example: ';
244+
}
245+
}
246+
239247
.param-enum-value,
240-
.param-default-value {
241-
background-color: $background-color;
242-
border: 1px solid rgba($secondary-color, 0.2);
248+
.param-default-value,
249+
.param-example-value {
250+
font-family: Courier, monospace;
251+
background-color: rgba($secondary-color, 0.02);
252+
border: 1px solid rgba($secondary-color, 0.1);
243253
margin: 2px 3px;
244-
padding: 0 5px;
245-
border-radius: 2px;
246-
color: $secondary-color;
254+
padding: 0.1em 0.2em 0.2em;
255+
border-radius: $border-radius;
256+
color: $text-color;
247257
display: inline-block;
248258
min-width: 20px;
249259
text-align: center;

lib/components/ParamsList/params-list.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ <h5 class="param-list-header" *ngIf="params.length"> Parameters </h5>
2222
<div class="param-default" *ngIf="param.default != null">
2323
<span class="param-default-value">{{param.default | json}}</span>
2424
</div>
25+
<div class="param-example" *ngIf="param.example != null">
26+
<span class="param-example-value">{{param.example | json}}</span>
27+
</div>
2528
<div *ngIf="param.enum || param._enumItem" class="param-enum">
2629
<span *ngFor="let enumItem of param.enum" class="param-enum-value {{enumItem.type}}">
2730
{{enumItem.val | json}}

lib/components/Redoc/redoc.scss

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,11 @@ footer {
275275
code {
276276
font-family: Courier, monospace;
277277
background-color: rgba(38,50,56,0.04);
278-
padding: 0.1em 0 0.2em 0;
278+
padding: 0.1em 0.2em 0.2em;
279279
font-size: 1em;
280280
border-radius: $border-radius;
281281
color: $red;
282-
border: 1px solid rgba(38,50,56,0.1);
283-
284-
&:before, &:after {
285-
letter-spacing: -0.2em;
286-
//content: "\00a0";
287-
}
282+
border: 1px solid rgba(38,50,56, 0.1);
288283
}
289284

290285
p:last-of-type {

lib/services/schema-helper.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ const injectors = {
119119
injectTo._displayType = propertySchema.title ?
120120
`${propertySchema.title} (${propertySchema.type})` : propertySchema.type;
121121
}
122+
if (injectTo['x-example'] && !propertySchema.example) {
123+
injectTo.example = propertySchema['x-example'];
124+
}
122125
injectTo._widgetType = 'trivial';
123126
}
124127
},

0 commit comments

Comments
 (0)