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

@massive/swagger-client-gen

v0.2.3

Published

Swagger code generator for Haxe and BrightScript

Downloads

11

Readme

Haxe Swagger generator

Prerequisite

This tool supports swagger 2.0 only.

Running or building the tool requires NodeJS 10+.

Running the tool

From npm:

npm install @massive/swagger-client-gen
npx haxe-swagger-gen example/config_file.json
npx brightscript-swagger-gen example/config_file.json

From source:

node bin/haxe-swagger-generator.js example/config_file.json
node bin/brightscript-swagger-generator.js example/config_file.json

Configuration file

{
    "srcPath": "../src", // the destination directory
    "apiUrls": [ // urls used to generate classes
        ["https://api-server.com/spec"]
    ],
    "packages": { // classes packages
        "definitions": "swagger.gen.model",
        "paths": "swagger.gen.api", // apis
        "parameters": "swagger.gen.parameters"
    }
}

How to use the API

Haxe

Generated classes

The API is generating static methods which returns a Promise<T>.

Example:

ListsAPI.getList(list.id, {
    page: 2,
	page_size: 12,
	device: "web_browser"
});

This method takes all required parameters, and an object of the optional ones. If you don't want to specify any optional parameters, you can just do:

ListsAPI.getList(list.id);

As the call returns a typed Promise, you will receive a typed object:

ConfigAPI.getAppConfig().then(function(config: AppConfig) {
    // Now you have the config, enjoy :)
});

Use the actions with a Redux middleware

If you want to use the generated actions in a custom middleware, you can map the middleware with the generated actions:

// During store creation:
mapMiddleware(PageAction, new PageMiddleware())

// Your middleware should look like:
class PageMiddleware implements IMiddleware<PageAction, AppState> {

    public function new() {}

    public function middleware(action: PageAction, next: Void->Dynamic):Dynamic {
        return switch action {
            case GetList(...):
            ...
        }
    }
}

Brightscript

The generator creates API files for each Swagger section.

options = ConfigAPI_getAppConfig("roku")
'options = {
'    method: "GET",
'    params: { device: "roku" },
'    uri: "/config"
'}

service.load(options)

Building the tool

npm install
npm run test
npm run build

The JS script will be generated into bin/. If you update this tool, please also commit the .js so it can be used from git without compilation.

Haxe tooling

The tool is written in Haxe, targeting NodeJS. No need to install Haxe.

The Haxe toolchain and libraries are automatically installed by lix, a Haxe SDK and package manager. Lix is installed by npm as a package.json dependency.

If you're using VSCode you should install the following extensions:

  • VSHaxe extension (nadako.vshaxe)
  • Lix package manager (lix.lix)

Updating a dependency

lix switch <lib-name> <version>