1.0.1 • Published 6 months ago

@buildwithlayer/openapi-zod-spec v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

npm version code style: prettier

OpenAPI Zod Spec

This is a simple Zod Schema for Open API specs version 3.X.X.

Prerequisites

This project requires NodeJS (version 18 or later) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.

$ npm -v && node -v
10.2.4
v20.11.0

Table of contents

Installation

BEFORE YOU INSTALL: please read the prerequisites

To install and set up the library, run:

$ npm install @buildwithlayer/openapi-zod-spec

Or if you prefer using Yarn:

$ yarn add @buildwithlayer/openapi-zod-spec

Usage

Loading an OpenAPI Spec

From JSON:

import {OpenAPISpec} from '@buildwithlayer/openapi-zod-spec/index.js';
import {rawSpec} from './openapi.json';

const spec = OpenAPISpec.parse(rawSpec);

From YAML:

import {OpenAPISpec} from '@buildwithlayer/openapi-zod-spec/index.js';
import fs from 'fs';
import yaml from 'js-yaml';

const pathToYamlFile = './path/to/openapi.yml';
const fileContents = fs.readFileSync(pathToYamlFile, 'utf-8');
const rawSpec = yaml.load(fileContents);
const spec = OpenAPISpec.parse(rawSpec);

Upgrading an OpenAPI Spec

import {OpenAPISpec, upgrade} from '@buildwithlayer/openapi-zod-spec/index.js';
import {oldSpec} from './openapi.json';

const upgradedSpec = upgrade(OpenAPISpec.parse(oldSpec));

Contributing

These instructions will be updated soon.

Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests to us.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :sunglasses:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

License

MIT License © Andrea SonnY