@aqzhyi/openapi
v0.7.0
Published
[astro]: https://astro.build [nextjs]: https://nextjs.org [openapi-fetch]: https://openapi-ts.dev/openapi-fetch/ [openapi-react-query]: https://www.npmjs.com/package/openapi-react-query [openapi-typescript-fetch]: https://www.npmjs.com/package/openapi-typ
Maintainers
Readme
@aqzhyi/openapi
[!NOTE]
A type-safe instance builder for RESTful API services, respecting
swagger.jsonand following openapi
- [x] 🔋 type-safe and schema for RESTful API services and its instance.
- [ ] 🔋 type-safe react-hooks. (alternative openapi-react-query, swr-openapi)
- [ ] 🔋 some built-in middlewares. e.g.
jwtMiddleware
Installation
pnpm add @aqzhyi/openapi -DConfiguration
create a file named
openapi.config.tsin your project folder:import { build } from '@aqzhyi/openapi' build({ services: [ { name: 'myApiService', baseUrl: 'https://api.example.com/v1', swaggerUrl: '/openapi/swagger.json', // optional outDir: './app/services', }, ], })run the script in your terminal.
pnpx tsx openapi.config.ts- will create
'./app/services/myApiService/index.ts' - will export
myApiServiceas type-safe instance
- will create
Debug
DEBUG=openapi:* pnpx tsx openapi.config.tsUsage
[!TIP]
for more details, see openapi-fetch
import { myApiService, Schemas, Paths } from './app/services/myApiService'
myApiService.GET('/search', {
params: {
query: {
limit: 10,
},
},
})