@ovotech/laminar-oapi-cli

CLI generating typescript types for @ovotech/laminar-oapi

Use @ovotech/laminar-cli
Last updated a month ago by ikerin .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @ovotech/laminar-oapi-cli 
SYNC missed versions from official npm registry.

Laminar Oapi CLI

A CLI for the Open Api implementation for the laminar http server.

Usage

Given a OpenAPI config file:

examples/oapi.yaml

---
openapi: 3.0.0
info:
  title: Test
  version: 1.0.0
servers:
  - url: http://localhost:3333
paths:
  '/test':
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema: { $ref: '#/components/schemas/User' }
      responses:
        '200':
          description: A Test Object
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Test' }
    get:
      responses:
        '200':
          description: A Test Object
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Test' }

components:
  schemas:
    User:
      additionalProperties: false
      properties:
        email:
          type: string
        scopes:
          type: array
          items:
            type: string
      required:
        - email

    Test:
      properties:
        text:
          type: string
        user:
          $ref: '#/components/schemas/User'
      required:
        - text

We can run:

yarn laminar-oapi oapi.yaml oapi.yaml.ts

Which would convert a given oapi.yaml file to a oapi.yaml.ts. Any external urls, referenced in it would be downloaded, and any local file references would be loaded as well.

Then you can load the types like this:

examples/simple.ts

import { laminar, start, describe, jsonOk } from '@ovotech/laminar';
import { createOapi } from '@ovotech/laminar-oapi';
import { join } from 'path';
import { Config } from './oapi.yaml';

const main = async () => {
  const config: Config = {
    api: join(__dirname, 'oapi.yaml'),
    paths: {
      '/test': {
        post: ({ body }) => jsonOk({ text: 'ok', user: body }),
        get: () => jsonOk({ text: 'ok', user: { email: 'me@example.com' } }),
      },
    },
  };
  const app = await createOapi(config);
  const server = laminar({ port: 3333, app });
  await start(server);
  console.log(describe(server));
};

main();

Watching for changes

You can also watch for changes and regenerate the typescript types with the --watch flag

yarn laminar-oapi --watch oapi.yaml oapi.yaml.ts

When you update the source yaml file, or any of the local files it references, laminar-oapi would rebuild the typescript files.

Generating types

You can use @ovotech/laminar-oapi-cli package to generate types.

Running the tests

You can run the tests with:

yarn test

Coding style (linting, etc) tests

Style is maintained with prettier and eslint

yarn lint

Deployment

Deployment is preferment by lerna automatically on merge / push to master, but you'll need to bump the package version numbers yourself. Only updated packages with newer versions will be pushed to the npm registry.

Contributing

Have a bug? File an issue with a simple example that reproduces this so we can take a look & confirm.

Want to make a change? Submit a PR, explain why it's useful, and make sure you've updated the docs (this file) and the tests (see test folder).

License

This project is licensed under Apache 2 - see the LICENSE file for details

Current Tags

  • 0.8.1                                ...           latest (a month ago)

21 Versions

  • 0.8.1 [deprecated]           ...           a month ago
  • 0.8.0 [deprecated]           ...           a month ago
  • 0.7.0 [deprecated]           ...           a month ago
  • 0.6.0 [deprecated]           ...           2 months ago
  • 0.5.8 [deprecated]           ...           2 months ago
  • 0.5.7 [deprecated]           ...           2 months ago
  • 0.5.6 [deprecated]           ...           4 months ago
  • 0.5.5 [deprecated]           ...           5 months ago
  • 0.5.4 [deprecated]           ...           7 months ago
  • 0.5.3 [deprecated]           ...           7 months ago
  • 0.5.2 [deprecated]           ...           7 months ago
  • 0.5.1 [deprecated]           ...           8 months ago
  • 0.5.0 [deprecated]           ...           8 months ago
  • 0.4.5 [deprecated]           ...           8 months ago
  • 0.4.4 [deprecated]           ...           8 months ago
  • 0.4.3 [deprecated]           ...           9 months ago
  • 0.4.2 [deprecated]           ...           9 months ago
  • 0.4.1 [deprecated]           ...           a year ago
  • 0.4.0 [deprecated]           ...           a year ago
  • 0.3.0 [deprecated]           ...           a year ago
  • 0.2.0 [deprecated]           ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 29
Dependencies (6)
Dev Dependencies (15)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |