From f792273be8460f2c6f96eda8135a31c8754b36cb Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Thu, 17 Aug 2017 11:25:58 +0300 Subject: [PATCH] support x-example for parameters closes #297 --- demo/swagger.yaml | 1 + .../JsonSchema/_json-schema-common.scss | 30 ++++++++++++------- lib/components/ParamsList/params-list.html | 3 ++ lib/components/Redoc/redoc.scss | 9 ++---- lib/services/schema-helper.service.ts | 3 ++ 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/demo/swagger.yaml b/demo/swagger.yaml index b4590253..88447235 100644 --- a/demo/swagger.yaml +++ b/demo/swagger.yaml @@ -242,6 +242,7 @@ paths: in: header required: false type: string + x-example: Bearer - name: petId in: path description: Pet id to delete diff --git a/lib/components/JsonSchema/_json-schema-common.scss b/lib/components/JsonSchema/_json-schema-common.scss index b6a27a2b..b9a48e89 100644 --- a/lib/components/JsonSchema/_json-schema-common.scss +++ b/lib/components/JsonSchema/_json-schema-common.scss @@ -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); @@ -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 + & { @@ -144,7 +146,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin; } .param:first-of-type { - > .param-name::before { content: ''; display: block; @@ -158,7 +159,6 @@ $sub-schema-offset: ($bullet-size / 2) + $bullet-margin; .param:last-of-type, .param.last { - > .param-name { position: relative; @@ -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; diff --git a/lib/components/ParamsList/params-list.html b/lib/components/ParamsList/params-list.html index 3f4fcc25..fc6f705a 100644 --- a/lib/components/ParamsList/params-list.html +++ b/lib/components/ParamsList/params-list.html @@ -22,6 +22,9 @@
{{param.default | json}}
+
+ {{param.example | json}} +
{{enumItem.val | json}} diff --git a/lib/components/Redoc/redoc.scss b/lib/components/Redoc/redoc.scss index abf2326e..14a82928 100644 --- a/lib/components/Redoc/redoc.scss +++ b/lib/components/Redoc/redoc.scss @@ -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 { diff --git a/lib/services/schema-helper.service.ts b/lib/services/schema-helper.service.ts index e2acd3cc..d8579d8b 100644 --- a/lib/services/schema-helper.service.ts +++ b/lib/services/schema-helper.service.ts @@ -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'; } },