Skip to content

Commit f38ae8e

Browse files
committed
Merge branch 'main' of github.com:speakeasy-api/speakeasy-code-samples-ts
2 parents fd6fe49 + 9d6628d commit f38ae8e

18 files changed

+467
-90
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
/.tshy-*
1818
/__tests__
1919
/.speakeasy/reports
20+
/react.*

.speakeasy/gen.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ id: 521af75f-d011-41f9-a5ff-9f8033773118
33
management:
44
docChecksum: a0841885f1d2df6bf65c33550d1be776
55
docVersion: 0.4.0
6-
speakeasyVersion: 1.468.0
7-
generationVersion: 2.492.3
8-
releaseVersion: 2.0.11
9-
configChecksum: 6131813611c165f99630ca021de715dc
6+
speakeasyVersion: 1.468.5
7+
generationVersion: 2.493.11
8+
releaseVersion: 2.0.13
9+
configChecksum: bb0274b648f58e16f339f488f406677b
1010
repoURL: https://github.com/speakeasy-api/speakeasy-code-samples-ts.git
1111
installationURL: https://github.com/speakeasy-api/speakeasy-code-samples-ts
1212
published: true
1313
features:
1414
typescript:
1515
additionalDependencies: 0.1.0
16-
core: 3.18.12
16+
core: 3.18.14
1717
defaultEnabledRetries: 0.1.0
1818
devContainers: 2.90.0
1919
envVarSecurityUsage: 0.1.2

.speakeasy/gen.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ generation:
1616
oAuth2ClientCredentialsEnabled: false
1717
oAuth2PasswordEnabled: false
1818
typescript:
19-
version: 2.0.11
19+
version: 2.0.13
2020
additionalDependencies:
2121
dependencies: {}
2222
devDependencies: {}
23-
peerDependencies: {}
23+
peerDependencies:
24+
highlight.js: ^11.11.1
2425
additionalPackageJSON: {}
2526
author: Speakeasy
2627
clientServerStatusCodesAsErrors: true
2728
defaultErrorName: APIError
29+
enableCustomCodeRegions: false
2830
enableReactQuery: true
2931
enumFormat: enum
3032
flattenGlobalSecurity: true
@@ -40,7 +42,7 @@ typescript:
4042
inputModelSuffix: input
4143
maxMethodParams: 1
4244
methodArguments: require-security-and-request
43-
moduleFormat: commonjs
45+
moduleFormat: esm
4446
outputModelSuffix: output
4547
packageName: '@speakeasyapi/code-samples'
4648
responseFormat: flat

.speakeasy/workflow.lock

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
speakeasyVersion: 1.468.0
1+
speakeasyVersion: 1.468.5
22
sources:
33
speakeasy-OAS:
44
sourceNamespace: speakeasy-oas
5-
sourceRevisionDigest: sha256:771ed09dacf285d6f18e27f01e0492f45f9248110476d381d0a6768cb4021320
5+
sourceRevisionDigest: sha256:eccb5c0b494c102a3985fedd96b152ad956b8be90681e6f5f21b5756463f66ab
66
sourceBlobDigest: sha256:6d9de4a70686f4366747b9dbf16917300a43dea8857ad6583f35ef3531bffbdb
77
tags:
88
- latest
@@ -11,10 +11,8 @@ targets:
1111
code_samples_typescript_sdk:
1212
source: speakeasy-OAS
1313
sourceNamespace: speakeasy-oas
14-
sourceRevisionDigest: sha256:771ed09dacf285d6f18e27f01e0492f45f9248110476d381d0a6768cb4021320
14+
sourceRevisionDigest: sha256:eccb5c0b494c102a3985fedd96b152ad956b8be90681e6f5f21b5756463f66ab
1515
sourceBlobDigest: sha256:6d9de4a70686f4366747b9dbf16917300a43dea8857ad6583f35ef3531bffbdb
16-
codeSamplesNamespace: speakeasy-oas-typescript-code-samples
17-
codeSamplesRevisionDigest: sha256:12997450a71bf46eaf590c8da28f9c7599305c352f80814d77a29071c25a1f03
1816
workflow:
1917
workflowVersion: 1.0.0
2018
speakeasyVersion: latest

README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @speakeasyapi/code-samples
22

3-
Developer-friendly & type-safe Typescript SDK specifically catered to leverage *@speakeasyapi/code-samples* API.
3+
Developer-friendly & type-safe Typescript SDK specifically catered to leverage _@speakeasyapi/code-samples_ API.
44

55
<div align="left">
66
<a href="https://www.speakeasy.com/?utm_source=@speakeasyapi/code-samples&utm_campaign=typescript"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
@@ -9,8 +9,8 @@ Developer-friendly & type-safe Typescript SDK specifically catered to leverage *
99
</a>
1010
</div>
1111

12-
1312
<br /><br />
13+
1414
> [!IMPORTANT]
1515
> This SDK is not yet ready for production use. To complete setup please follow the steps outlined in your [workspace](https://app.speakeasy.com/org/speakeasy-self/speakeasy-self). Delete this section before > publishing to a package manager.
1616
@@ -84,6 +84,10 @@ yarn add @tanstack/react-query react react-dom
8484
# Note that Yarn does not install peer dependencies automatically. You will need
8585
# to install zod as shown above.
8686
```
87+
88+
> [!NOTE]
89+
> This package is published as an ES Module (ESM) only. For applications using
90+
> CommonJS, use `await import("@speakeasyapi/code-samples")` to import and use this package.
8791
<!-- End SDK Installation [installation] -->
8892
8993
<!-- Start Requirements [requirements] -->
@@ -119,6 +123,49 @@ run();
119123
```
120124
<!-- End SDK Example Usage [usage] -->
121125

126+
### React Component
127+
128+
This library includes a React component that fetches and highlights code
129+
snippets using `highlight.js`. Along with displaying the snippet, it shows a loading state during
130+
fetching and provides a fallback view if an error occurs.
131+
132+
```tsx
133+
import { SpeakeasyCodeSamplesCore } from "@speakeasyapi/code-samples/core";
134+
import {
135+
CodeSample,
136+
SpeakeasyCodeSamplesProvider,
137+
} from "@speakeasyapi/code-samples/react";
138+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
139+
140+
const queryClient = new QueryClient();
141+
142+
const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
143+
apiKey: "<YOUR_API_KEY_HERE>",
144+
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
145+
});
146+
147+
// Retries are handled by the underlying SDK.
148+
queryClient.setQueryDefaults(["@speakeasyapi/code-samples"], { retry: false });
149+
150+
queryClient.setMutationDefaults(["@speakeasyapi/code-samples"], {
151+
retry: false,
152+
});
153+
154+
function App() {
155+
return (
156+
<QueryClientProvider client={queryClient}>
157+
<SpeakeasyCodeSamplesProvider client={speakeasyCodeSamples}>
158+
<CodeSample operationId="getPetById" language="typescript" />
159+
</SpeakeasyCodeSamplesProvider>
160+
</QueryClientProvider>
161+
);
162+
}
163+
```
164+
165+
> [!NOTE]
166+
> To apply styles to the highlighted code, import a `highlight.js` theme CSS
167+
> file into your project using methods like a `<link>` tag.
168+
122169
<!-- Start Authentication [security] -->
123170
## Authentication
124171

@@ -537,7 +584,7 @@ looking for the latest version.
537584

538585
## Contributions
539586

540-
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
541-
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
587+
While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
588+
We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
542589

543590
### SDK Created by [Speakeasy](https://www.speakeasy.com/?utm_source=@speakeasyapi/code-samples&utm_campaign=typescript)

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{
44
"name": "@speakeasyapi/code-samples",
5-
"version": "2.0.11",
5+
"version": "2.0.13",
66
"exports": {
77
".": "./src/index.ts",
88
"./models/errors": "./src/models/errors/index.ts",

package-lock.json

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,47 @@
11
{
22
"name": "@speakeasyapi/code-samples",
3-
"version": "2.0.11",
3+
"version": "2.0.13",
44
"author": "Speakeasy",
5-
"main": "./index.js",
5+
"type": "module",
6+
"main": "./esm/index.js",
7+
"exports": {
8+
".": {
9+
"source": "./src/index.ts",
10+
"types": "./esm/index.d.ts",
11+
"default": "./esm/index.js"
12+
},
13+
"./package.json": "./package.json",
14+
"./types": {
15+
"source": "./src/types/index.ts",
16+
"types": "./esm/types/index.d.ts",
17+
"default": "./esm/types/index.js"
18+
},
19+
"./models/errors": {
20+
"source": "./src/models/errors/index.ts",
21+
"types": "./esm/models/errors/index.d.ts",
22+
"default": "./esm/models/errors/index.js"
23+
},
24+
"./models/components": {
25+
"source": "./src/models/components/index.ts",
26+
"types": "./esm/models/components/index.d.ts",
27+
"default": "./esm/models/components/index.js"
28+
},
29+
"./models/operations": {
30+
"source": "./src/models/operations/index.ts",
31+
"types": "./esm/models/operations/index.d.ts",
32+
"default": "./esm/models/operations/index.js"
33+
},
34+
"./*.js": {
35+
"source": "./src/*.ts",
36+
"types": "./esm/*.d.ts",
37+
"default": "./esm/*.js"
38+
},
39+
"./*": {
40+
"source": "./src/*.ts",
41+
"types": "./esm/*.d.ts",
42+
"default": "./esm/*.js"
43+
}
44+
},
645
"sideEffects": false,
746
"repository": {
847
"type": "git",
@@ -15,6 +54,7 @@
1554
},
1655
"peerDependencies": {
1756
"@tanstack/react-query": "^5",
57+
"highlight.js": "^11.11.1",
1858
"react": "^18 || ^19",
1959
"react-dom": "^18 || ^19",
2060
"zod": ">= 3"

src/funcs/codeSamplesGet.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { SpeakeasyCodeSamplesCore } from "../core.js";
66
import { encodeFormQuery } from "../lib/encodings.js";
77
import * as M from "../lib/matchers.js";
8+
import { compactMap } from "../lib/primitives.js";
89
import { safeParse } from "../lib/schemas.js";
910
import { RequestOptions } from "../lib/sdks.js";
1011
import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
@@ -65,9 +66,9 @@ export async function codeSamplesGet(
6566
"registry_url": payload.registry_url ?? client._options.registryUrl,
6667
});
6768

68-
const headers = new Headers({
69+
const headers = new Headers(compactMap({
6970
Accept: "application/json",
70-
});
71+
}));
7172

7273
const secConfig = await extractSecurity(client._options.apiKey);
7374
const securityInput = secConfig == null ? {} : { apiKey: secConfig };

src/lib/clsx.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export function clsx(...args: Array<string | undefined>) {
2+
let i = 0,
3+
tmp,
4+
str = "";
5+
const len = args.length;
6+
for (; i < len; i++) {
7+
if ((tmp = args[i])) {
8+
if (typeof tmp === "string") {
9+
str += (str && " ") + tmp;
10+
}
11+
}
12+
}
13+
return str;
14+
}

0 commit comments

Comments
 (0)