-
-
Save mohsen1/b2576b7749a2c58732a10c46e96a4a38 to your computer and use it in GitHub Desktop.
Swagger TypeScript client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Client from 'swagger-typed-client' | |
const client = new Client({swagger: ` | |
swagger: '2.0' | |
info: | |
version: 0.0.0 | |
title: Simple API | |
basePath: /api | |
host: localhost | |
paths: | |
/foo: | |
get: | |
parameters: | |
- name: limit | |
in: query | |
description: Limit | |
type: number | |
responses: | |
200: | |
description: OK | |
schema: | |
type: object | |
properties: | |
bar: | |
type: string | |
`}); | |
const obj = await client.paths['/foo'].get({ parameters: {limit: 10} }); | |
// obj type is {bar: string} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Client from 'swagger-typed-client' | |
const client = new Client({ | |
swaggerUrl: 'path/to/swagger.yaml', | |
overrides: { | |
host: process.env.DEV_SERVER_URL | |
} | |
}); | |
const obj = await client.paths['/foo'].get({ parameters: {limit: 10} }); | |
// obj type is {bar: string} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Client from 'swagger-typed-client' | |
const client = new Client({swaggerUrl: 'path/to/swagger.yaml'}); | |
const obj = await client.paths['/foo'].get({ parameters: {limit: 10} }); | |
// obj type is {bar: string} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment