Skip to content

Instantly share code, notes, and snippets.

@mohsen1
Last active September 20, 2018 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohsen1/b2576b7749a2c58732a10c46e96a4a38 to your computer and use it in GitHub Desktop.
Save mohsen1/b2576b7749a2c58732a10c46e96a4a38 to your computer and use it in GitHub Desktop.
Swagger TypeScript client
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}
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}
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