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
45 changes: 26 additions & 19 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
lockVersion: 2.0.0
id: 521af75f-d011-41f9-a5ff-9f8033773118
management:
docChecksum: 80bdf0b395520d76da9a1e1e2896dae0
docChecksum: 2bf97fa8e6ca517b859cc9784a1260b5
docVersion: 0.4.0
speakeasyVersion: 1.514.0
generationVersion: 2.546.0
releaseVersion: 2.4.0-beta
configChecksum: ef5d56dcfd4f4ba9e07e1a535f410421
speakeasyVersion: 1.665.0
generationVersion: 2.767.2
releaseVersion: 2.4.0-beta.1
configChecksum: c67003eda5007f1a820b79d20d2cfa37
repoURL: https://github.com/speakeasy-api/speakeasy-code-samples-ts.git
installationURL: https://github.com/speakeasy-api/speakeasy-code-samples-ts
published: true
features:
typescript:
additionalDependencies: 0.1.0
core: 3.21.3
core: 3.26.13
deepObjectParams: 0.1.0
defaultEnabledRetries: 0.1.0
devContainers: 2.90.0
devContainers: 2.90.1
enumUnions: 0.1.0
envVarSecurityUsage: 0.1.2
globalSecurity: 2.82.13
globalSecurity: 2.82.14
globalSecurityCallbacks: 0.1.0
globalSecurityFlattening: 0.1.0
globalServerURLs: 2.82.4
globalServerURLs: 2.83.0
globals: 2.82.2
groups: 2.81.2
mcpServer: 0.6.0
groups: 2.81.3
mcpServer: 0.9.3
nameOverrides: 2.81.2
reactQueryHooks: 0.2.2
reactQueryHooks: 0.2.3
responseFormat: 0.2.3
retries: 2.83.0
sdkHooks: 0.2.0
sdkHooks: 0.4.0
serverIDs: 2.81.2
generatedFiles:
- .devcontainer/README.md
Expand All @@ -52,8 +52,11 @@ generatedFiles:
- docs/models/operations/getcodesamplesrequest.md
- docs/models/operations/methodpaths.md
- docs/sdks/codesamples/README.md
- docs/sdks/speakeasycodesamples/README.md
- eslint.config.mjs
- examples/.env.template
- examples/README.md
- examples/codeSamplesGet.example.ts
- examples/package.json
- jsr.json
- package.json
- src/core.ts
Expand Down Expand Up @@ -84,6 +87,7 @@ generatedFiles:
- src/mcp-server/console-logger.ts
- src/mcp-server/extensions.ts
- src/mcp-server/mcp-server.ts
- src/mcp-server/prompts.ts
- src/mcp-server/resources.ts
- src/mcp-server/scopes.ts
- src/mcp-server/server.ts
Expand All @@ -99,7 +103,9 @@ generatedFiles:
- src/models/errors/error.ts
- src/models/errors/httpclienterrors.ts
- src/models/errors/index.ts
- src/models/errors/responsevalidationerror.ts
- src/models/errors/sdkvalidationerror.ts
- src/models/errors/speakeasycodesampleserror.ts
- src/models/operations/getcodesamples.ts
- src/models/operations/index.ts
- src/react-query/_context.tsx
Expand All @@ -118,21 +124,22 @@ generatedFiles:
- src/types/operations.ts
- src/types/rfcdate.ts
- src/types/streams.ts
- src/types/unrecognized.ts
- tsconfig.json
examples:
getCodeSamples:
"":
speakeasy-default-get-code-samples:
parameters:
query:
registry_url: "https://spec.speakeasy.com/my-org/my-workspace/my-source"
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
operation_ids: ["getPets"]
method_paths: [{"method": "get", "path": "/pets"}]
languages: ["python", "javascript"]
responses:
2XX:
application/json: {"snippets": [{"path": "/sbin", "method": "<value>", "operationId": "<id>", "language": "php,", "code": "<value>"}, {"path": "/root", "method": "<value>", "operationId": "<id>", "language": "unity,", "code": "<value>"}]}
application/json: {"snippets": []}
4XX:
application/json: {"message": "<value>", "status_code": 521235}
application/json: {"message": "<value>", "status_code": 887801}
default:
parameters:
query:
Expand All @@ -143,5 +150,5 @@ examples:
responses:
2XX:
application/json: {"snippets": [{"path": "/pet/{id}", "method": "get", "operationId": "getPetById", "language": "typescript", "code": "import { Petstore } from \"petstore-sdk\";\n\nconst petstore = new Petstore({\n apiKey: \"<YOUR_API_KEY_HERE>\",\n});\n\nasync function run() {\n const result = await petstore.pet.getById({\n id: 137396,\n });\n\n // Handle the result\n console.log(result);\n}\n\nrun();"}]}
examplesVersion: 1.0.0
examplesVersion: 1.0.2
generatedTests: {}
30 changes: 29 additions & 1 deletion .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,28 @@ generation:
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
sdkInitStyle: constructor
useClassNamesForArrayFields: true
fixes:
nameResolutionFeb2025: false
parameterOrderingFeb2024: false
requestResponseComponentNamesFeb2024: false
securityFeb2025: false
sharedErrorComponentsApr2025: false
auth:
oAuth2ClientCredentialsEnabled: false
oAuth2PasswordEnabled: false
hoistGlobalSecurity: true
schemas:
allOfMergeStrategy: shallowMerge
requestBodyFieldName: ""
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 +38,24 @@ typescript:
'@types/react': ^18.3.18
peerDependencies: {}
additionalPackageJSON: {}
additionalScripts: {}
alwaysIncludeInboundAndOutbound: false
author: Speakeasy
baseErrorName: SpeakeasyCodeSamplesError
clientServerStatusCodesAsErrors: true
constFieldsAlwaysOptional: true
defaultErrorName: APIError
enableCustomCodeRegions: false
enableMCPServer: true
enableReactQuery: true
enumFormat: union
exportZodModelNamespace: false
flattenGlobalSecurity: true
flatteningOrder: body-first
formStringArrayEncodeMode: encoded-string
forwardCompatibleEnumsByDefault: false
forwardCompatibleUnionsByDefault: "false"
generateExamples: true
imports:
option: openapi
paths:
Expand All @@ -44,13 +64,21 @@ typescript:
operations: models/operations
shared: models/components
webhooks: models/webhooks
inferUnionDiscriminators: true
inputModelSuffix: input
jsonpath: legacy
laxMode: strict
maxMethodParams: 1
methodArguments: require-security-and-request
modelPropertyCasing: camel
moduleFormat: esm
multipartArrayFormat: legacy
outputModelSuffix: output
packageName: '@speakeasyapi/code-samples'
responseFormat: flat
sseFlatResponse: false
templateVersion: v2
unionStrategy: left-to-right
usageSDKInitImports: []
useIndexModules: true
zodVersion: v3
14 changes: 7 additions & 7 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
speakeasyVersion: 1.514.0
speakeasyVersion: 1.665.0
sources:
speakeasy-OAS:
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:c95b7bde7a889f8d6461e405347f2dac28defaaf6a36cc19709b4ce29f4eaefb
sourceBlobDigest: sha256:706c912b2e5755fdaff8d2a95ca3ce6fb1fff777a7aa49a8afcb0b909cc22892
sourceRevisionDigest: sha256:6b8652973fd0a9bf346a3af06472bc616830e9e3c881a0f583f3bfd12979591a
sourceBlobDigest: sha256:63f67500135f962b2c56c1d0664fef7f7d040d733c89169633eae8ec2f9d1b85
tags:
- latest
- speakeasy-sdk-regen-1741642416
- speakeasy-sdk-regen-1746489958
- 0.4.0
targets:
code_samples_typescript_sdk:
source: speakeasy-OAS
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:c95b7bde7a889f8d6461e405347f2dac28defaaf6a36cc19709b4ce29f4eaefb
sourceBlobDigest: sha256:706c912b2e5755fdaff8d2a95ca3ce6fb1fff777a7aa49a8afcb0b909cc22892
sourceRevisionDigest: sha256:6b8652973fd0a9bf346a3af06472bc616830e9e3c881a0f583f3bfd12979591a
sourceBlobDigest: sha256:63f67500135f962b2c56c1d0664fef7f7d040d733c89169633eae8ec2f9d1b85
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
Loading