This package has been deprecated

Author message:

Use @ovotech/laminar-cli

@ovotech/laminar-oapi-cli
TypeScript icon, indicating that this package has built-in type declarations

0.8.1 • Public • Published

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

/@ovotech/laminar-oapi-cli/

    Package Sidebar

    Install

    npm i @ovotech/laminar-oapi-cli

    Weekly Downloads

    2

    Version

    0.8.1

    License

    Apache-2.0

    Unpacked Size

    35 kB

    Total Files

    14

    Last publish

    Collaborators

    • ovox
    • oep-accounts-bot
    • ovo.backstage.admins
    • bookings-team
    • orion-bot
    • bizval-bot
    • oeptariffs
    • props
    • metering-reads-health-bot
    • ovotech-identity
    • paceteamkaluza
    • trading-and-dispatch
    • retail-payg-tech
    • accrecovo
    • ovo.trading.tech
    • qe-team
    • ovotech-smart-thermostat
    • rise-team
    • engagement-insights
    • myovo-self-serve-service-account
    • mars-rover
    • ape-team
    • kaluza-devex
    • ohs-aurora
    • kaluza-rnr
    • ipa-bot
    • kawbot
    • data.discovery.ovo
    • ovotech-sg
    • ovotech-qs
    • ovoenergyapps
    • homemoves
    • ovo-oot-bot
    • cp-ui-tooling
    • ovo-bit-tech
    • sir_hiss