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

generator-jhipster-swagger-cli

v3.0.1

Published

JHipster module to generate swagger client code from a swagger definition

Downloads

3,328

Readme

generator-jhipster-swagger-cli

NPM version Build Status Dependency Status

JHipster module to generate client code from an OpenAPI/Swagger definition

Introduction

This is a JHipster module, that is meant to be used in a JHipster application.

This module generates client code using Spring-Cloud FeignClients in your JHipster app from an OpenAPI/Swagger definition.

The generated FeignClient can be used in both Monolithic and Micro-service applications.

This module works for JHipster v5+ apps. For older JHipster version, use version 2.x of this module (branch v2.x-JHipster2-3-4)

This module works with both Swagger v2 and OpenAPI v3 definitions.

Prerequisites

As this is a JHipster module, we expect you have JHipster and its related tools already installed:

Installation

To install this module:

npm install -g generator-jhipster-swagger-cli

To update this module:

npm update -g generator-jhipster-swagger-cli

Usage

Run:

yo jhipster-swagger-cli

then answer the questions. You have the possibility to store a client configuration for future regeneration (eg. if there is an API update). If you do so, next time you launch the module, you will have the choice to generate a new client or to reuse one or several stored configurations.

Use the generated back-end Spring-Cloud FeignClient code

Client configuration

You can configure the generated FeignClients directly from the application.yml. RequestInterceptor beans are generated from the OpenAPI securitySchemes and are only activated if relevant properties are set. If the OpenAPI spec doesn't contain the securitySchemes, then you will need to configure the clients by yourself (see spring-cloud doc for details.)

Configuring basic auth

The basic auth RequestInterceptor is activated if <clientName>.security.<securityName>.username is set.

petstore:
    security:
        basicAuth:
            username: admin
            password: admin

Configuring API key auth

The API key RequestInterceptor is activated if <clientName>.security.<securityName>.key is set.

petstore:
    security:
        apiKey:
            key: 12345

Configuring OAuth2

The OAuth2 RequestInterceptor is activated if <clientName>.security.<securityName>.key is set. For details on configuring OAuth2, see the spring-security-oauth2 doc.

petstore:
    security:
        passwordOauth:
            client-id: myClientId
            client-secret: myClientSecret
            username: myUsername
            password: myPassword
            scopes:
            - read
            - write

Configuring the remote URL

The remote URL will default to the one from the OpenAPI spec but can be changed with the <clientName>.url property.

petstore:
    url: http://petstore-uat.swagger.io/v2

Use Ribbon (w/wo Eureka)

You need to add spring-cloud-starter-ribbon to your pom.xml if needed. Note that it seems to cause an issue with form-login on monoliths so it is not done by this module. Then set <cliName>.url to blank.

petstore:
    url:
    ribbon:
        listOfServers: petstore1.swagger.io,petstore2.swagger.io

Advanced configuration

If the generated clients don't fit your needs because you want to use Hystrix fallbacks, change the Ribbon context path or use different Feign client configuration, then simply create your own FeignClient beans extending the generated xxxApi classes.

Calling API methods

For instance if you generated the petstore API, you can call the addPet method like this:

@Inject
private PetApiClient petApiClient;
...
Pet myPet = new Pet();
petApiClient.addPet(myPet);

License

Apache-2.0 © [Christophe Bornet]