0.1.1 • Published 8 months ago

zoapi v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

zoapi

GitHub License npm

zoapi provides a simple way to generate OpenAPI schemas using zod and a simple api.

Installation

npm install zoapi

Usage

import { z } from 'zod';
import { Api } from 'zoapi';


const api = new Api("3.0.0", {
    title: "My API",
    version: "1.0.0",
    description: "My API description",
});

const userSchema = z.object({
    id: z.string(),
    name: z.string(),
    email: z.string().email(),
});

const createUserSchema = userSchema.omit({ id: true });

api.get("/users").responds("200", z.array(userSchema)).withTags(["users"]);

api.post("/users").body(createUserSchema).responds("201", z.number().int()).withTags(["users"]);

api.get("/users/{id}").pathParams(z.object({ id: z.string() })).responds("200", userSchema).withTags(["users"]);

console.log(api.document());
0.1.1

8 months ago

0.1.0

8 months ago