# @balise/swagger-client-generator

> Swagger Client Generator is a tool that enables developers to easily parse Swagger API specification files and generate code bindings that are type safe using the popular validation library Zod and the flexible HTTP client Wretch. Swagger Client Generator

Latest version **0.0.6** (published 2023-06-15) · ISC license · 0 weekly downloads

## Install

```sh
npm install @balise/swagger-client-generator
pnpm add @balise/swagger-client-generator
yarn add @balise/swagger-client-generator
bun add @balise/swagger-client-generator
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2023-06-15 |
| First published | 2023-04-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 29 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | balise |
| Maintainers | balise |

## Links

- npm: https://www.npmjs.com/package/@balise/swagger-client-generator
- Repository: https://github.com/BaliseCode/SwaggerClientGenerator
- Homepage: https://github.com/BaliseCode/SwaggerClientGenerator#readme
- Issues: https://github.com/BaliseCode/SwaggerClientGenerator/issues
- npm.io page: https://npm.io/package/@balise/swagger-client-generator

## Dependencies (3)

- [zod](https://npm.io/package/zod.md) ^3.21.4
- [wretch](https://npm.io/package/wretch.md) ^2.5.2
- [prettier](https://npm.io/package/prettier.md) 2.8.7

## Recent versions

- 0.0.6 (latest) — 2023-06-15
- 0.0.5-a — 2023-06-15
- 0.0.5 — 2023-06-15
- 0.0.4 — 2023-06-15
- 0.0.3-b — 2023-06-15
- 0.0.3 — 2023-04-25
- 0.0.2 — 2023-04-25
- 0.0.1 — 2023-04-24

## README

# Introduction

Swagger Client Generator is a tool that enables developers to easily parse Swagger API specification files and generate code bindings that are type safe using the popular validation library Zod and the flexible HTTP client Wretch. Swagger Client Generator makes it easy to generate high-quality code that is both scalable and maintainable. 

# Generate your API client

## Installation


    npm install @balise/swagger-client-generator

The following code explains how to generate code bindings from a swagger.json file.

    import SwaggerGenerateClient from "@balise/swagger-client-generator";

    let Query = new SwaggerGenerateClient('inputfile.json', 'outputfile.ts');

## Integrate with Vite 

Todo


# Use the API client

## Instanciate the API
To use the Api you can add the following code to your application to instanciate a caller. That will create a Call object that you can use to call your API.

    import ApiCallerInstance from "./outputfile";

    const Call = new ApiCallerInstance({
        rootUrl: 'https://localhost:3000',
        headers: {
            'Bearer: 'SomeToken'
        }
    }).ApiCall;


## Make an API Call
Next when you need to call the API you can use the following pattern

    let u = {
        first_name: "James", 
        last_name: "Bond"
    }

    Call.Projets.Users.post(u).then((res) => {
        console.log(res)
    }).catch((err) => {
        console.error(err)
    });

the *u* object will be validated trough the Zod library, and wrech will make a post request at the *https://localhost:3000/Projets/Users* endpoint using the bearer token from the setup

#Types
The Library also generates and exports Types and Validators from schemas from the Swagger file. 

For the Project schema, ProjectValidator is a Zod validator and ProjectType is a type infered from this validator

---
_Source: https://npm.io/package/@balise/swagger-client-generator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
