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

@oxide/openapi-gen-ts

v0.5.0

Published

OpenAPI client generator used to generate Oxide TypeScript SDK

Downloads

92

Readme

@oxide/openapi-gen-ts

This is a TypeScript OpenAPI client generator built for use with schemas generated by Dropshot. It has not been tested on any other specs and is unlikely to handle them well.

Usage

npx @oxide/openapi-gen-ts@version <schema url or file> <output dir>

Note that fixing a version with @0.1.0 is important because you don't want your generated output to between runs. See the Versioning section below for details.

Interesting files

The core logic for looping over the spec and creating the methods is in src/client/api.ts and the mapping from OpenAPI schemas to TS types is in src/schema/types.ts. The mapping from OpenAPI schemas to Zod schemas is in src/schema/zod.ts.

The files in src/client/static/ are copied over to the client as-is during generation. We generate several distinct pieces:

| File | Description | | ----------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | Api.ts | A Fetch-based TS client to the Oxide API | | validate.ts | Zod validators for API request and response types | | msw-handlers.ts | Helpers used to build a mock API with Mock Service Worker in the console repo |

Why a custom generator?

We tried many existing generators, and while most worked in a basic sense, we found it hard to make customizations, whether through CLI flags, templates, or patching with patch-package. We decided to prototype our own TS generator after seeing other Oxide devs do the same for Rust (progenitor and oxide.rs) and Go (oxide.go). It quickly became clear that a special-purpose generator could be dramatically simpler than a general one, so writing one was easier than existing generators made it look.

The TypeScript client code will be written to oxide-api/src.

Versioning scheme

Generator versions on npm are semver-ish. Breaking changes to the generator's own API (not the generated output) should be major releases. Currently, the generator has no programmatic API and can only be used as a CLI app (e.g., through npx), so we will consider the CLI to be the external API.

| Version bump | Example changes | | ------------ | -------------------------------------------------------------- | | Major | Breaking changes to CLI args or flags | | Minor | Semantic changes (i.e., modulo formatting) to generated output | | Patch | Internal changes or non-meaningful changes to generated output |