1.0.1 • Published 6 months ago
@buildwithlayer/openapi-zod-spec v1.0.1
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.0Table of contents
Installation
BEFORE YOU INSTALL: please read the prerequisites
To install and set up the library, run:
$ npm install @buildwithlayer/openapi-zod-specOr if you prefer using Yarn:
$ yarn add @buildwithlayer/openapi-zod-specUsage
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.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Add your changes:
git add . - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - 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