Tools for consuming OpenAPI schemas in TypeScript.
npm i -D openapi-typescript # supports Swagger/OpenAPI v3
# or
npm i -D openapi-typescript@5 # supports OpenAPI v2
npx openapi-typescript ./path/to/my/schema.yaml -o ./path/to/my/schema.d.ts
# 🚀 ./path/to/my/schema.yaml -> ./path/to/my/schema.d.ts [7ms]
npx openapi-typescript https://myapi.dev/api/v1/openapi.yaml -o ./path/to/my/schema.d.ts
npx openapi-typescript https://myapi.dev/api/v1/openapi.yaml -o ./path/to/my/schema.d.ts
# 🚀 https://myapi.dev/api/v1/openapi.yaml -> ./path/to/my/schema.d.ts [250ms]
it works, but the generated code is not quite "idiomatic" typescript.
it works, but the generated code is not quite "idiomatic" typescript.
alternatives
mapping local file swagger/index.yml to running docker container /tmp/index.yml
# unix bash
docker run -p 8000:8080 -e SWAGGER_JSON=/tmp/index.yml -v $(pwd)/swagger:/tmp --name=swagger-ui -d swaggerapi/swagger-ui
open http://localhost:8000
# windows powershell
docker run -p 8000:8080 -e SWAGGER_JSON=/tmp/index.yml -v ${pwd}/swagger:/tmp --name=swagger-ui -d swaggerapi/swagger-ui
start http://localhost:8000
# stop and remove
docker stop swagger-ui
docker rm swagger-ui
acacode/swagger-typescript-api: TypeScript API generator via Swagger scheme @GitHub
npx swagger-typescript-api -p ./swagger.json -o ./src -n myApi.ts
Generating typescript API client from Swagger
OpenAPI-Specification/3.0.3.md at main · OAI/OpenAPI-Specification
About Swagger Specification | Documentation | Swagger
example: Rustici Software SDK from Swagger codegen
mapping local file swagger/index.yml to running docker container /tmp/index.yml
# unix bash
docker run -p 8000:8080 -e SWAGGER_JSON=/tmp/index.yml -v $(pwd)/swagger:/tmp --name=swagger-ui -d swaggerapi/swagger-ui
open http://localhost:8000
# windows powershell
docker run -p 8000:8080 -e SWAGGER_JSON=/tmp/index.yml -v ${pwd}/swagger:/tmp --name=swagger-ui -d swaggerapi/swagger-ui
start http://localhost:8000
# stop and remove
docker stop swagger-ui
docker rm swagger-ui
No comments:
Post a Comment