@sdk-it/typescript 0.46.2 → 0.46.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,11 +16,10 @@ generated in `minimal` mode.
16
16
  ## Generate from an OpenAPI document
17
17
 
18
18
  ```typescript
19
+ import { loadSpec } from '@sdk-it/spec';
19
20
  import { generate } from '@sdk-it/typescript';
20
21
 
21
- const spec = await fetch('https://api.openstatus.dev/v1/openapi').then(
22
- (response) => response.json(),
23
- );
22
+ const spec = await loadSpec('https://api.openstatus.dev/openapi.yaml');
24
23
 
25
24
  await generate(spec, {
26
25
  output: './src/generated/openstatus',
@@ -29,8 +28,9 @@ await generate(spec, {
29
28
  });
30
29
  ```
31
30
 
32
- `name` controls the generated client class name. `minimal` mode writes client
33
- source files directly to `output`.
31
+ `loadSpec` accepts a URL or a local path and reads JSON or YAML. `name`
32
+ controls the generated client class name. `minimal` mode writes client source
33
+ files directly to `output`.
34
34
 
35
35
  ## Use the generated client
36
36
 
@@ -38,14 +38,48 @@ source files directly to `output`.
38
38
  import { OpenStatus } from './src/generated/openstatus/index.ts';
39
39
 
40
40
  const client = new OpenStatus({
41
- baseUrl: 'https://api.openstatus.dev/v1',
42
- 'x-openstatus-key': process.env.OPENSTATUS_API_KEY,
41
+ baseUrl: 'https://api.openstatus.dev',
42
+ credentials: {
43
+ ApiKeyAuth: process.env.OPENSTATUS_API_KEY,
44
+ },
43
45
  });
44
46
 
45
- const reports = await client.request('GET /status_report', {});
47
+ const reports = await client.request(
48
+ 'POST /rpc/openstatus.status_report.v1.StatusReportService/ListStatusReports',
49
+ {},
50
+ );
46
51
  console.log(reports);
47
52
  ```
48
53
 
54
+ ## Security credentials
55
+
56
+ Credential keys are the exact names from `components.securitySchemes`.
57
+ Generated types enforce the value required by each scheme:
58
+
59
+ - API keys, Bearer/custom HTTP, OAuth 2, and OpenID Connect use a string.
60
+ - HTTP Basic uses `{ username, password }`.
61
+ - Mutual TLS uses `true`; the configured `fetch` implementation owns the
62
+ client certificate.
63
+
64
+ Each value may instead be a sync or async provider. Providers receive the
65
+ scheme name plus the current operation's OpenAPI scopes or roles:
66
+
67
+ ```typescript
68
+ const client = new ExampleClient({
69
+ baseUrl: 'https://api.example.com',
70
+ credentials: {
71
+ oauth: async ({ scopes }) => issueToken(scopes),
72
+ bearer: ({ roles }) => tokenForRoles(roles),
73
+ },
74
+ });
75
+ ```
76
+
77
+ The client preserves OpenAPI security semantics: alternatives in the security
78
+ array are OR, schemes inside one requirement are AND, `security: []` sends no
79
+ credentials, and an empty requirement (`{}`) permits anonymous access. When
80
+ anonymous and authenticated alternatives coexist, configured authentication
81
+ is preferred.
82
+
49
83
  `request` returns unwrapped response data. It throws `ParseError` when input
50
84
  validation fails and an `APIError` subclass when the server returns a
51
85
  non-successful response:
@@ -58,12 +92,17 @@ import {
58
92
  } from './src/generated/openstatus/index.ts';
59
93
 
60
94
  const client = new OpenStatus({
61
- baseUrl: 'https://api.openstatus.dev/v1',
62
- 'x-openstatus-key': process.env.OPENSTATUS_API_KEY,
95
+ baseUrl: 'https://api.openstatus.dev',
96
+ credentials: {
97
+ ApiKeyAuth: process.env.OPENSTATUS_API_KEY,
98
+ },
63
99
  });
64
100
 
65
101
  try {
66
- const report = await client.request('GET /status_report/{id}', { id: '42' });
102
+ const report = await client.request(
103
+ 'POST /rpc/openstatus.status_report.v1.StatusReportService/GetStatusReport',
104
+ { id: '42' },
105
+ );
67
106
  console.log(report);
68
107
  } catch (error) {
69
108
  if (error instanceof ParseError) {