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

sdk-example-generator

v0.1.4

Published

我们拥有多个语言的sdk,都基于 swagger 定义生成,我们需要给每个 api 写示例,实际上是一个比较重复的过程,但是每种 sdk 构建参数的行为不一样。 我们需要定义一套规则,用于描述每个 api 的参数构建行为,然后根据这个规则,生成对应语言的示例代码。 从而只需要输入一份json文件,以及就可以生成多种语言的示例代码。

Downloads

17

Readme

Sdk Example Converter

我们拥有多个语言的sdk,都基于 swagger 定义生成,我们需要给每个 api 写示例,实际上是一个比较重复的过程,但是每种 sdk 构建参数的行为不一样。 我们需要定义一套规则,用于描述每个 api 的参数构建行为,然后根据这个规则,生成对应语言的示例代码。 从而只需要输入一份json文件,以及就可以生成多种语言的示例代码。

定义代码生成规则

我们可以将一个完整的 sdk 示例代码拆分为两大部分:

  1. 前置代码,包含:
    1. 依赖的引用,其中又分为通用的依赖和需要的依赖
    2. main function 的构建,其中包括:
      1. 构建完整的代码,比如 入口方法,引用,包名等等
      2. 创建 Client 并鉴权
  2. 业务代码,包含:
    1. 创建对应的Api实例
    • python:
      • 代码:vm_api = VmApi(api_client) ${tag}Api(api_client)
      • 额外引用 from cloudtower import VmApi from cloudtower import ${tag}Api
    • java:
      • 代码: VmApi vmApi = new VmApi(apiClient); ${tag}Api ${tag}Api = new ${tag}Api(apiClient);
      • 额外引用: 无
    • go:
      • 代码:vmApi := client.VM ${lower(tag)}Api := client.${upper(tag)}
      • 额外引用: 无
    • node:
      • 代码:const vmApi = new VmApi(apiClient) const ${tag}Api = new ${tag}Api(apiClient)
      • 额外引用:import { VmApi } from 'cloudtower' `import { ${tag}Api } from 'cloudtower'
    1. 构建请求参数
    • python: json payload
    • java:
    • go:
      • params := vm.NewCreateVmParams() ${lower(tag)}.New${apiName}Params()
      • params.RequestBody = &models.VMCreationParams{{...}}
    • node: json payload
    1. 发送请求
    2. 等待请求返回

部分1可以