Skip to content

Commit

Permalink
support x-example for parameters
Browse files Browse the repository at this point in the history
closes #297
  • Loading branch information
RomanHotsiy committed Aug 17, 2017
1 parent b84177c commit f792273
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions demo/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ paths:
in: header
required: false
type: string
x-example: Bearer <TOKEN>
- name: petId
in: path
description: Pet id to delete
Expand Down
30 changes: 20 additions & 10 deletions lib/components/JsonSchema/_json-schema-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
font-weight: bold;
}

.param-type, .param-array-format {
.param-type,
.param-array-format {
vertical-align: middle;
line-height: $param-name-height;
color: rgba($black, 0.4);
Expand All @@ -73,7 +74,8 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
.param-type {
font-weight: normal;
word-break: break-all;
&.array::before, &.tuple::before {
&.array::before,
&.tuple::before {
color: $black;
font-weight: $base-font-weight;
.param-collection-format-multi + & {
Expand Down Expand Up @@ -144,7 +146,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
}

.param:first-of-type {

> .param-name::before {
content: '';
display: block;
Expand All @@ -158,7 +159,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;

.param:last-of-type,
.param.last {

> .param-name {
position: relative;

Expand Down Expand Up @@ -236,14 +236,24 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin;
}
}

.param-example {
font-size: 0.95em;

&::before {
content: 'Example: ';
}
}

.param-enum-value,
.param-default-value {
background-color: $background-color;
border: 1px solid rgba($secondary-color, 0.2);
.param-default-value,
.param-example-value {
font-family: Courier, monospace;
background-color: rgba($secondary-color, 0.02);
border: 1px solid rgba($secondary-color, 0.1);
margin: 2px 3px;
padding: 0 5px;
border-radius: 2px;
color: $secondary-color;
padding: 0.1em 0.2em 0.2em;
border-radius: $border-radius;
color: $text-color;
display: inline-block;
min-width: 20px;
text-align: center;
Expand Down
3 changes: 3 additions & 0 deletions lib/components/ParamsList/params-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ <h5 class="param-list-header" *ngIf="params.length"> Parameters </h5>
<div class="param-default" *ngIf="param.default != null">
<span class="param-default-value">{{param.default | json}}</span>
</div>
<div class="param-example" *ngIf="param.example != null">
<span class="param-example-value">{{param.example | json}}</span>
</div>
<div *ngIf="param.enum || param._enumItem" class="param-enum">
<span *ngFor="let enumItem of param.enum" class="param-enum-value {{enumItem.type}}">
{{enumItem.val | json}}
Expand Down
9 changes: 2 additions & 7 deletions lib/components/Redoc/redoc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,11 @@ footer {
code {
font-family: Courier, monospace;
background-color: rgba(38,50,56,0.04);
padding: 0.1em 0 0.2em 0;
padding: 0.1em 0.2em 0.2em;
font-size: 1em;
border-radius: $border-radius;
color: $red;
border: 1px solid rgba(38,50,56,0.1);

&:before, &:after {
letter-spacing: -0.2em;
//content: "\00a0";
}
border: 1px solid rgba(38,50,56, 0.1);
}

p:last-of-type {
Expand Down
3 changes: 3 additions & 0 deletions lib/services/schema-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ const injectors = {
injectTo._displayType = propertySchema.title ?
`${propertySchema.title} (${propertySchema.type})` : propertySchema.type;
}
if (injectTo['x-example'] && !propertySchema.example) {
injectTo.example = propertySchema['x-example'];
}
injectTo._widgetType = 'trivial';
}
},
Expand Down

0 comments on commit f792273

Please sign in to comment.