0.13.0 • Published 2 years ago

@spec-validator/open-api-endpoint v0.13.0

Weekly downloads
160
License
Apache-2.0
Repository
github
Last release
2 years ago

@spec-validator/open-api-endpoint

The endpoint decorates server configs with an additional set of routes that generate open-api spec and a ui for it.

import http from 'http'

import { createServer, _ } from '@spec-validator/rest-api-server'
import { segmentField as $, numberField, stringField } from '@spec-validator/validator/fields'
import { withOpenApi } from '@spec-validator/open-api-endpoint'
import { expectType } from '@spec-validator/test-utils/expectType'

const itemSpec = {
  title: stringField(),
  description: stringField(),
}

const server = createServer(withOpenApi({
  routes: [
    _.POST($._('/items')).spec({
      request: {
        body: itemSpec,
      },
      response: {
        body: numberField(),
        headers: {
          title: stringField(),
        },
      },
    }).handler(async () => ({
      body: 42,
      headers: {
        title: 'Foo',
      },
    })),
    _.GET($._('/items')).spec({
      response: {
        body: [itemSpec],
      },
    }).handler(async () => ({
      body: [
        {
          title: 'Item N',
          description: 'Description',
        },
      ],
    }))
  ]
}))

expectType<http.Server & { serve: () => http.Server }, typeof server>(true)

Once served via a regular call:

server.serve()

OpenApi ui will be available at http://localhost:8080/open-api-ui without any additional effort.

0.13.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.6.1

3 years ago

0.5.0

3 years ago

0.4.8

3 years ago

0.4.7

3 years ago

0.4.5

3 years ago

0.4.6

3 years ago

0.4.4

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.9

3 years ago

0.2.6

3 years ago