0.5.1 • Published 1 year ago

@kong-ui-public/spec-renderer-mini v0.5.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

@kong-ui-public/spec-renderer-mini

A Kong UI mini component for displaying API specs

Features

  • Render spec styled object arrays
  • Support both table of contents and list summary views

Requirements

  • vue must be initialized in the host application

Usage

Install

Install the component in your host application

yarn add @kong-ui-public/spec-renderer-mini

Register

You can register portal-spec-renderer-mini globally or locally.

// Global registration
import { createApp } from 'vue'
import SpecRendererMini from '@kong-ui-public/spec-renderer-mini'
import '@kong-ui-public/spec-renderer-mini/dist/style.css'

const app = createApp(App)

app.use(SpecRendererMini)
<!-- Local registration -->
<template>
  <SpecRendererMini />
</template>

<script setup lang="ts">
import SpecRendererMini from '@kong-ui-public/spec-renderer-mini'
import '@kong-ui-public/spec-renderer-mini/dist/style.css'
</script>

Props

operations

  • type: Object[]
  • required: true

Operation object array. Required. The objects should conform to the following interface.

{
  /**
   * Relative operation path with optional path templating.
   * See https://swagger.io/specification/#paths-object
   */
  path: string
  /**
   * HTTP Method
   */
  method: string
  /**
   * Optional operationId
   */
  operationId: string | null
  /**
   * List of tag names for the operation used to group operations into sections
   */
  tags: string[]
  /**
   * Short summary of the operation
   */
  summary: string | null
  /**
   * Is the operation deprecated?
   */
  deprecated: boolean
}

tags

  • type: Object[]
  • required: false
  • default: []

Object array for tags. You can use this to specify tag information such as description and externalDocs.

{
  /**
   * Tag name
   * See {@link Operation.tags} for usage details
   */
  name: string
  /**
   * Optional description.
   * CommonMark formatting is not supported at the moment.
   */
  description?: string
  /**
   * Optional link to external docs of the tag
   */
  externalDocs?: {
    description?: string
    url: string
  }
}

isFilterable

  • type: Boolean
  • required: false
  • default: true

If enabled, will display filter input and enable filtering operations by tag names using case-insensitive partial matching.

width

  • type: String
  • required: false
  • default: 210

Controls the width of the rendered spec. Currently supports numbers (will be converted to px), auto, vw, vh, and percentages for width.

filterFunction

  • type: Function
  • required: false

Overrides the default filter function. Provided function must return a list of Operation objects.

Example

const operationSummaryFilterFunc: OperationListFilterFunction = ({ items, query }) => {
  return items.filter((item) => item.summary.includes(query))
}

Slots

item

Controls the content of a single operation.

Slot props

item
  • type: Object
  • required: true

Operation object of the item to display.

select
  • type: 'Function'
  • required: true

Handler function to call when item is selected, usually on click event.

section
  • type: String
  • required: false

Section (tag) name or undefined if operation is untagged.

empty-state

Controls the content displayed when the spec array is empty.

error-state

Controls the content when spec is not provided.

Emits

selected

  • returns: Object - the last clicked item data
{
  path: string
  method: string
  operationId: string | null
  tags: string[]
  summary: string | null
  deprecated: boolean
}

This is emitted whenever an item in the spec is clicked.

Theming

CSS VariablePurposeDefault
--kong-ui-spec-renderer-operations-list-filter-icon-colorOperations list filter input icon color#1C1B1F
--kong-ui-spec-renderer-operations-list-font-familyOperations list font familyRoboto, Helvetica, sans-serif
--kong-ui-spec-renderer-operations-list-font-sizeOperations list font size16px
--kong-ui-spec-renderer-operations-list-font-text-colorOperations list text color#0B172D
--kong-ui-spec-renderer-operations-list-item-border-colorOperations list item border color#f1f1f5
--kong-ui-spec-renderer-operations-list-item-paddingOperations list item padding12px 16px
--kong-ui-spec-renderer-operations-list-item-background-hoverOperations list item background on hover#f2f6fe
--kong-ui-spec-renderer-operations-list-item-background-selectedOperations list selected item background#f2f6fe
--kong-ui-spec-renderer-operations-list-item-selected-bar-widthOperations list selected item highlight bar width4px
--kong-ui-spec-renderer-operations-list-item-selected-bar-backgroundOperations list selected item highlight bar background#1155cb
--kong-ui-spec-renderer-operations-list-item-path-font-familyOperations list item resource path font familymonospace
--kong-ui-spec-renderer-operations-list-item-summary-text-colorOperations list selected item summary text color#0B172D
--kong-ui-spec-renderer-operations-list-item-summary-text-color-selectedOperations list item summary text color#3C4557
--kong-ui-spec-renderer-method-color-getOperations list item GET method badge color#1155cb
--kong-ui-spec-renderer-method-background-getOperations list item GET method badge background#f2f6fe
--kong-ui-spec-renderer-method-color-postOperations list item POST method badge color#13755e
--kong-ui-spec-renderer-method-background-postOperations list item POST method badge background#e8f8f5
--kong-ui-spec-renderer-method-color-putOperations list item PUT method badge color#a05604
--kong-ui-spec-renderer-method-background-putOperations list item PUT method badge background#fff3d8
--kong-ui-spec-renderer-method-color-patchOperations list item PATCH method badge color#006e9d
--kong-ui-spec-renderer-method-background-patchOperations list item PATCH method badge background#cdf1fe
--kong-ui-spec-renderer-method-color-deleteOperations list item DELETE method badge color#922021
--kong-ui-spec-renderer-method-background-deleteOperations list item DELETE method badge background#ffdede
--kong-ui-spec-renderer-method-color-optionsOperations list item OPTIONS method badge color#273c61
--kong-ui-spec-renderer-method-background-optionsOperations list item OPTIONS method badge background#f0f4fa
--kong-ui-spec-renderer-method-color-headOperations list item HEAD method badge color#a05604
--kong-ui-spec-renderer-method-background-headOperations list item HEAD method badge background#fff3d8
--kong-ui-spec-renderer-method-color-connectOperations list item CONNECT method badge color#473cfb
--kong-ui-spec-renderer-method-background-connectOperations list item CONNECT method badge background#eaf4fb
--kong-ui-spec-renderer-method-color-traceOperations list item TRACE method badge color#5c7299
--kong-ui-spec-renderer-method-background-traceOperations list item TRACE method badge background#f0f4fa
--kong-ui-spec-renderer-operations-list-section-backgroundOperations list section backgroundtransparent
--kong-ui-spec-renderer-operations-list-section-border-colorOperations list section border color#f1f1f5
--kong-ui-spec-renderer-operations-list-section-border-radiusOperations list section border radius4px
--kong-ui-spec-renderer-operations-list-section-paddingOperations list section padding8px
--kong-ui-spec-renderer-operations-list-section-label-font-sizeOperations list section label font size18px
--kong-ui-spec-renderer-operations-list-section-label-text-colorOperations list section label text color#0B172D
--kong-ui-spec-renderer-operations-list-section-label-text-color-collapsedOperations list collapsed section label text color#3C4557
--kong-ui-spec-renderer-operations-list-section-description-font-familyOperations list section description font familymonospace
--kong-ui-spec-renderer-operations-list-section-icon-color-collapsedOperations list collapsed section icon color#b6b6bd
--kong-ui-spec-renderer-operations-list-section-icon-color-expandedOperations list expanded section icon color#3c4557
0.3.6

1 year ago

0.3.5

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.4

1 year ago

0.5.1

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago