@cblx-br/openapi-typescript
Typescript model and client generator for OpenApi
Last updated 24 days ago by guimabdo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @cblx-br/openapi-typescript 
SYNC missed versions from official npm registry.

openapi-typescript

openapi client generator for typescript

npm install @cblx-br/openapi-typescript --save-dev

create an openapi-typescript.config.js

var config = {
    url: "<url>/swagger.json",
    outputDir: "./src/client",
};

module.exports = config;

execute it:

npx openapi-typescript


Angular example:

create an app-connector.ts

import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { OpenApiConnector } from '@cblx-br/openapi-typescript';

@Injectable({
    providedIn: 'root'
})
export class AppConnector implements OpenApiConnector {

    constructor(@Inject('BASE_URL') private baseUrl: string, private http: HttpClient) {}

    async request(method: string, path: string, parameters: any, body: any) {
        return await this.http.request(method, this.baseUrl + path, {
            body: body,
            params: parameters
        }).toPromise();
    }
}

openapi-typescript.config.js

var config = {
    url: "<url>/swagger.json",
    outputDir: "./src/client",
     events: {
        beforeWriteServiceClass: () => {
            var content = '';
            content += `import { Inject, Injectable } from '@angular/core';\n`;
            content += `import { AppConnector } from 'app/app-connector';\n`;
            content += `@Injectable({ providedIn: 'root' })\n`;
            return content;
        },
        createConnectorDecorator: () => {
            return `@Inject(AppConnector) `;
        }
    }
};

module.exports = config;

Current Tags

  • 0.10.1                                ...           latest (24 days ago)

16 Versions

  • 0.10.1                                ...           24 days ago
  • 0.10.0                                ...           24 days ago
  • 0.9.4                                ...           2 months ago
  • 0.0.0-master.6                                ...           2 months ago
  • 0.9.3                                ...           2 months ago
  • 0.9.2                                ...           2 months ago
  • 0.9.1                                ...           2 months ago
  • 0.9.0                                ...           2 months ago
  • 0.8.0                                ...           2 months ago
  • 0.7.0                                ...           2 months ago
  • 0.6.0                                ...           2 months ago
  • 0.5.2                                ...           2 months ago
  • 0.5.1                                ...           2 months ago
  • 0.5.0                                ...           2 months ago
  • 0.4.2                                ...           2 months ago
  • 0.4.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 16
This Month 16
Last Day 0
Last Week 0
Last Month 50
Dependencies (3)
Dev Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |