Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Swagger 2.0 support #355

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/new-jobs-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fets': patch
---

Improve Swagger 2.0 support
26 changes: 26 additions & 0 deletions examples/soccer-stats/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createClient, type NormalizeOAS } from 'fets';
import type swagger from './soccer-stats-swagger';

const client = createClient<NormalizeOAS<typeof swagger>>({
endpoint: 'https://api.sportsdata.io/v4/soccer/stats',
});

const res = await client['/{format}/Areas'].get({
params: {
format: 'json',
},
headers: {
'Ocp-Apim-Subscription-Key': 'test',
},
});

if (!res.ok) {
const err = await res.text();
throw new Error(err);
}

const data = await res.json();
console.log(`Areas: ${data.length} items`);
for (const item of data) {
console.log(`- ID: ${item.AreaId}, Name: ${item.Name}`);
}
18 changes: 18 additions & 0 deletions examples/soccer-stats/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "example-soccer-stats",
"version": "0.0.0",
"description": "An example app uses Soccer Stats API",
"private": true,
"scripts": {
"prepare": "ts-node scripts/download-oas.ts",
"start": "ts-node-dev index.ts"
},
"dependencies": {
"@types/node": "18.16.19",
"fets": "0.4.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"typescript": "^5.0.0",
"zod": "3.21.4"
}
}
Loading
Loading