Skip to content

Commit

Permalink
change linter and add openai tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchoz49 committed Jul 19, 2024
1 parent c0e530d commit 390aa4f
Show file tree
Hide file tree
Showing 18 changed files with 4,918 additions and 236 deletions.
15 changes: 0 additions & 15 deletions .eslintrc.json

This file was deleted.

Binary file added .github/assets/logo.webp
Binary file not shown.
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: Tests
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
![Types for your OpenAPI](.github/assets/logo.webp 'Types for your OpenAPI')

# openapi-box
Generate [TypeBox](https://github.com/sinclairzx81/typebox) types from OpenApi `V3` IDL + End-to-end typesafe HTTP client library.

> It works for TypeScript and JavaScript.
![Tests](https://github.com/geut/openapi-box/actions/workflows/test.yml/badge.svg)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat)](https://standardjs.com)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard--ext-05ae89.svg)](https://github.com/tinchoz49/eslint-config-standard-ext)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat)](https://github.com/RichardLitt/standard-readme)

[![Made by GEUT][geut-badge]][geut-url]
Expand All @@ -17,16 +19,15 @@ $ npm install @geut/openapi-box @sinclair/typebox

## Usage


1. Generate the schema from an OpenApi url (it can a be filepath too):
```bash
$ openapi-box https://petstore3.swagger.io/api/v3/openapi.json
```

2. Load your schemas into the End-to-end typesafe `fetch` client:
```js
import { createClient } from './src/client.js'
import { schema } from './schema.js'
import { createClient } from './src/client.js'

const client = createClient({
schema,
Expand Down
22 changes: 12 additions & 10 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env node
import { writeFile } from 'fs/promises'
import ora from 'ora'
import { writeFile } from 'node:fs/promises'

import meow from 'meow'
import ora from 'ora'

import { write } from '../src/writer.js'

const cli = meow(`
Expand All @@ -26,22 +28,22 @@ const cli = meow(`
output: {
type: 'string',
shortFlag: 'o',
default: 'schema.js'
default: 'schema.js',
},
header: {
type: 'string',
shortFlag: 'h',
isMultiple: true
isMultiple: true,
},
cjs: {
type: 'boolean',
default: false
default: false,
},
removePrefix: {
type: 'string',
shortFlag: 'r'
}
}
shortFlag: 'r',
},
},
})

if (cli.input.length === 0) {
Expand All @@ -53,7 +55,7 @@ const input = cli.input[0]
const spinner = ora(`Generating schema from ${input}`).start()

const headers = {}
cli.flags.header.forEach(header => {
cli.flags.header.forEach((header) => {
const splitIdx = header.indexOf('=')
if (splitIdx === -1) {
spinner.fail('Fetch: the header provided is not valid, it must be: key=value')
Expand All @@ -69,7 +71,7 @@ try {
schema = await write(input, {
cjs: cli.flags.cjs,
headers,
removePrefix: cli.flags.removePrefix
removePrefix: cli.flags.removePrefix,
})
} catch (err) {
spinner.fail(err.message)
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { standard } from 'eslint-config-standard-ext'

export default standard()
57 changes: 29 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,51 @@
{
"name": "@geut/openapi-box",
"type": "module",
"version": "4.0.0",
"description": "Generate TypeBox types from OpenApi IDL + End-to-end typesafe HTTP client library.",
"type": "module",
"browser": "./dist/client.cjs",
"main": "./dist/client.cjs",
"bin": "./bin/cli.js",
"author": {
"name": "GEUT",
"email": "[email protected]"
},
"license": "MIT",
"homepage": "https://github.com/geut/openapi-box#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/geut/openapi-box.git"
},
"bugs": {
"url": "https://github.com/geut/openapi-box/issues"
},
"keywords": [
"create",
"geut",
"module"
],
"exports": {
".": {
"require": "./dist/client.cjs",
"import": "./dist/client.js"
"import": "./dist/client.js",
"require": "./dist/client.cjs"
},
"./writer": {
"require": "./dist/writer.cjs",
"import": "./dist/writer.js"
"import": "./dist/writer.js",
"require": "./dist/writer.cjs"
},
"./package.json": "./package.json"
},
"main": "./dist/client.cjs",
"bin": "./bin/cli.js",
"files": [
"src",
"bin",
"dist",
"bin"
"src"
],
"scripts": {
"start": "node index.js",
"build": "tsup src/client.js src/writer.js --dts --format esm,cjs",
"test": "node --test",
"posttest": "npm run lint",
"lint": "eslint",
"lint": "eslint .",
"test:types": "tsc",
"prepublishOnly": "npm test && npm run build"
},
Expand All @@ -49,6 +67,7 @@
"@sinclair/typebox": "^0.31.17",
"@types/node": "^20.6.2",
"eslint": "^8.46.0",
"eslint-config-standard-ext": "^0.0.27",
"eslint-plugin-jsdoc": "^46.8.1",
"expect-type": "^0.16.0",
"fastify": "^4.21.0",
Expand All @@ -64,24 +83,6 @@
"browser"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/geut/openapi-box.git"
},
"keywords": [
"create",
"geut",
"module"
],
"author": {
"name": "GEUT",
"email": "[email protected]"
},
"license": "MIT",
"bugs": {
"url": "https://github.com/geut/openapi-box/issues"
},
"homepage": "https://github.com/geut/openapi-box#readme",
"publishConfig": {
"access": "public"
}
Expand Down
Loading

0 comments on commit 390aa4f

Please sign in to comment.