npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-swagger-client-generator

v3.1.0

Published

Angular REST API client generator from Swagger YAML or JSON file with camel case settigs

Downloads

14

Readme

npm npm npm

Caretaker Conventional Commits

GitHub stars Twitter URL

api-client-generator

Angular REST API client generator from Swagger YAML or JSON file with camel case settings

Description

This package generates a Angular TypeScript classes from a Swagger v2.0 specification file. The code is generated using Mustache templates.

The generated service class uses new HttpClient module of Angular (introduced in version 4.3).

Installation

Global usage:

[sudo] yarn global add api-client-generator

or

[sudo] npm install -g api-client-generator

This command will generate API client described in swagger.json file to ./output folder

api-client-generator -s ./path/to/swagger.json -o ./output

Local usage

yarn add api-client-generator

or

npm install api-client-generator

  • for quick usage create run script in your package.json scripts
"scripts": {
  "generate-api-client": "api-client-generator -s ./swagger.yaml -o ./output-folder"
},
  • then just run

npm run generate-api-client

Options

  • s - path to the swagger file (yaml or json)
  • o - path where the generated files should be emitted

Generated structure

  • if you are interested on how will the generated client with models look like, take a look in a example/ folder
output
 ├─ models
 │   ├─ some.enum.ts
 │   ├─ some.model.ts
 │   │  ...
 │   ├─ another.model.ts
 │   └─ index.ts
 ├─ api-client.service.ts
 └─ index.ts

How to use generated client

  1. import the APIClientModule in your app.module.ts (main module)
  • domain and configuration should be passed to module imports using .forRoot method
  • options and domain are optional
  • when domain is not passed, host property form swagger file is used as default
    • if host property is not defined window.href with current port is used instead
@NgModule({
  imports: [
    APIClientModule.forRoot({
      domain: 'https://api.url', // or use value defined in environment `environment.apiUrl`
    }),
    /* ... other imports */
  ],
  /* ... other stuff */
})
export class AppModule {
}
  1. use APIClient service in your components/services/...
@Component({
  selector: 'my-component',
  templateUrl: `
    <div *ngFor="let user of users$ | async">
      <p>User name: {{user.name}}</p>
    </div>
  `,
})
export class MyComponent {
  
  users$ = this.api.getUsers();

  constructor(private readonly api: APIClient) {
    this.api.getSomething().subscribe(
      (something: Something) => console.log('something', something)
    );
  }
}

Inspired by swagger-js-codegen

Generator based on angular4-swagger-client-generator