Skip to content
Open
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
4 changes: 2 additions & 2 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ curl -fsSL https://raw.githubusercontent.com/speakeasy-api/speakeasy/main/instal
rmdir samples || true
mkdir samples

npm install
npm install -g ts-node
npm install --ignore-scripts
npm install -g ts-node --ignore-scripts
npm link
npm link @speakeasyapi/code-samples
TS_CONFIG_CONTENT=$(cat <<EOL
Expand Down
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/examples/node_modules
.DS_Store
**/.speakeasy/temp/
**/.speakeasy/logs/
.DS_Store
.env
.env.local
.env.*.local
/mcp-server
/bin
/.eslintcache
Expand Down
6 changes: 5 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
!/**/*.ts
!/**/*.js
!/**/*.mjs
!/**/*.json
!/package.json
!/jsr.json
!/dist/**/*.json
!/esm/**/*.json
!/**/*.map

/eslint.config.mjs
/.oxlintrc.json
/cjs
/.tshy
/.tshy-*
Expand Down
465 changes: 423 additions & 42 deletions .speakeasy/gen.lock

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,32 @@ generation:
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
sdkInitStyle: constructor
useClassNamesForArrayFields: true
fixes:
nameResolutionFeb2025: false
parameterOrderingFeb2024: false
requestResponseComponentNamesFeb2024: false
securityFeb2025: false
sharedErrorComponentsApr2025: false
sharedNestedComponentsJan2026: false
nameOverrideFeb2026: false
auth:
oAuth2ClientCredentialsEnabled: false
oAuth2PasswordEnabled: false
hoistGlobalSecurity: true
schemas:
allOfMergeStrategy: shallowMerge
requestBodyFieldName: ""
versioningStrategy: automatic
persistentEdits: {}
tests:
generateTests: true
generateNewTests: false
skipResponseBodyAssertions: false
typescript:
version: 2.4.0-beta
version: 2.4.0-beta.1
acceptHeaderEnum: true
additionalDependencies:
dependencies:
'@emotion/css': ^11.13.5
Expand All @@ -27,15 +42,26 @@ typescript:
'@types/react': ^18.3.18
peerDependencies: {}
additionalPackageJSON: {}
additionalScripts: {}
alwaysIncludeInboundAndOutbound: false
author: Speakeasy
baseErrorName: SpeakeasyCodeSamplesError
clientServerStatusCodesAsErrors: true
constFieldsAlwaysOptional: false
defaultErrorName: APIError
enableCustomCodeRegions: false
enableMCPServer: true
enableReactQuery: true
enumFormat: union
exportZodModelNamespace: false
fixEnumNameSanitization: false
flatAdditionalProperties: false
flattenGlobalSecurity: true
flatteningOrder: body-first
formStringArrayEncodeMode: encoded-string
forwardCompatibleEnumsByDefault: false
forwardCompatibleUnionsByDefault: "false"
generateExamples: true
imports:
option: openapi
paths:
Expand All @@ -44,13 +70,26 @@ typescript:
operations: models/operations
shared: models/components
webhooks: models/webhooks
inferUnionDiscriminators: true
inputModelSuffix: input
jsonpath: legacy
laxMode: strict
legacyFileNaming: true
maxMethodParams: 1
methodArguments: require-security-and-request
modelPropertyCasing: camel
moduleFormat: esm
multipartArrayFormat: legacy
outputModelSuffix: output
packageName: '@speakeasyapi/code-samples'
preApplyUnionDiscriminators: true
preserveModelFieldNames: false
responseFormat: flat
sseFlatResponse: false
templateVersion: v2
unionStrategy: left-to-right
usageSDKInitImports: []
useIndexModules: true
useOxlint: false
useTsgo: false
zodVersion: v3
13 changes: 6 additions & 7 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
speakeasyVersion: 1.514.0
speakeasyVersion: 1.761.9
sources:
speakeasy-OAS:
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:c95b7bde7a889f8d6461e405347f2dac28defaaf6a36cc19709b4ce29f4eaefb
sourceBlobDigest: sha256:706c912b2e5755fdaff8d2a95ca3ce6fb1fff777a7aa49a8afcb0b909cc22892
sourceRevisionDigest: sha256:26f455beda0b6b455c3c4b706d0739826263537f35a877de129f945a856664fc
sourceBlobDigest: sha256:33285be1bc6252ed7abba1696dc4643406e2df66fb154ce9b7320192a35473e5
tags:
- latest
- speakeasy-sdk-regen-1741642416
- 0.4.0
targets:
code_samples_typescript_sdk:
source: speakeasy-OAS
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:c95b7bde7a889f8d6461e405347f2dac28defaaf6a36cc19709b4ce29f4eaefb
sourceBlobDigest: sha256:706c912b2e5755fdaff8d2a95ca3ce6fb1fff777a7aa49a8afcb0b909cc22892
sourceRevisionDigest: sha256:26f455beda0b6b455c3c4b706d0739826263537f35a877de129f945a856664fc
sourceBlobDigest: sha256:33285be1bc6252ed7abba1696dc4643406e2df66fb154ce9b7320192a35473e5
codeSamplesNamespace: speakeasy-oas-typescript-code-samples
codeSamplesRevisionDigest: sha256:73a780b60ccc00d5344b505208070173d62dfcb9013e97f8f123e322230d6afe
codeSamplesRevisionDigest: sha256:b1dd14a70682337921089bf92025cbdb2a0175f13250e07d113bb9aa979db52a
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
38 changes: 13 additions & 25 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,24 @@ specific category of applications.
```typescript
import { SpeakeasyCodeSamplesCore } from "@speakeasyapi/code-samples/core.js";
import { codeSamplesGet } from "@speakeasyapi/code-samples/funcs/codeSamplesGet.js";
import { SDKValidationError } from "@speakeasyapi/code-samples/models/errors/sdkvalidationerror.js";

// Use `SpeakeasyCodeSamplesCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
apiKey: "<YOUR_API_KEY_HERE>",
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

async function run() {
const res = await codeSamplesGet(speakeasyCodeSamples, {
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
"g",
"e",
"t",
"P",
"e",
"t",
"s",
],
methodPaths: [
{
Expand All @@ -47,28 +51,12 @@ async function run() {
"javascript",
],
});

switch (true) {
case res.ok:
// The success case will be handled outside of the switch block
break;
case res.error instanceof SDKValidationError:
// Pretty-print validation errors.
return console.log(res.error.pretty());
case res.error instanceof Error:
return console.log(res.error);
default:
// TypeScript's type checking will fail on the following line if the above
// cases were not exhaustive.
res.error satisfies never;
throw new Error("Assertion failed: expected error checks to be exhaustive: " + res.error);
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("codeSamplesGet failed:", res.error);
}


const { value: result } = res;

// Handle the result
console.log(result);
}

run();
Expand Down
42 changes: 31 additions & 11 deletions REACT_QUERY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import { SpeakeasyCodeSamplesProvider } from "@speakeasyapi/code-samples/react-q

const queryClient = new QueryClient();
const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
apiKey: "<YOUR_API_KEY_HERE>",
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

// Retries are handled by the underlying SDK.
Expand Down Expand Up @@ -55,9 +55,14 @@ import { useCodeSamples } from "@speakeasyapi/code-samples/react-query/codeSampl

export function Example() {
const { data, error, status } = useCodeSamples({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
"g",
"e",
"t",
"P",
"e",
"t",
"s",
],
methodPaths: [
{
Expand Down Expand Up @@ -88,9 +93,14 @@ export function ExampleWithOptions() {
const [enabled, setEnabled] = useState(true);
const { data, error, status } = useCodeSamples(
{
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
"g",
"e",
"t",
"P",
"e",
"t",
"s",
],
methodPaths: [
{
Expand Down Expand Up @@ -189,8 +199,8 @@ import { useCodeSamplesSuspense } from "@speakeasyapi/code-samples/react-query/c

const queryClient = new QueryClient();
const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
apiKey: "<YOUR_API_KEY_HERE>",
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

export function App() {
Expand Down Expand Up @@ -222,9 +232,14 @@ export function App() {

function Example() {
const { data } = useCodeSamplesSuspense({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
"g",
"e",
"t",
"P",
"e",
"t",
"s",
],
methodPaths: [
{
Expand Down Expand Up @@ -261,14 +276,19 @@ import { prefetchCodeSamples } from "@speakeasyapi/code-samples/react-query/code
export default async function Page() {
const queryClient = new QueryClient();
const speakeasyCodeSamples = new SpeakeasyCodeSamplesCore({
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
apiKey: "<YOUR_API_KEY_HERE>",
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

await prefetchCodeSamples(queryClient, speakeasyCodeSamples, {
registryUrl: "https://spec.speakeasy.com/my-org/my-workspace/my-source",
operationIds: [
"getPets",
"g",
"e",
"t",
"P",
"e",
"t",
"s",
],
methodPaths: [
{
Expand Down
Loading