Skip to content

Commit

Permalink
Merge pull request #9 from speakeasy-sdks/walker/spe-4574-feature-cod…
Browse files Browse the repository at this point in the history
…esamples-sdk

feat: migrate to the new code_samples API
  • Loading branch information
walker-tx authored Jan 9, 2025
2 parents 900531c + 9e1a965 commit 3e1d774
Show file tree
Hide file tree
Showing 61 changed files with 1,643 additions and 1,700 deletions.
5 changes: 0 additions & 5 deletions .devcontainer/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@

<div align="center">
<a href="https://codespaces.new/speakeasy-sdks/code-sample-api.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
</div>
<br>

> **Remember to shutdown a GitHub Codespace when it is not in use!**
# Dev Containers Quick Start
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/react-query
/.speakeasy/reports
/models
/models/errors
/types
Expand Down
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
**/*
!/FUNCTIONS.md
!/RUNTIMES.md
!/REACT_QUERY.md
!/**/*.ts
!/**/*.js
!/**/*.map
Expand Down
91 changes: 32 additions & 59 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
@@ -1,68 +1,56 @@
lockVersion: 2.0.0
id: c7686174-7704-4859-9d59-8dab3c98a47f
id: 74386feb-f8da-4ec0-8b02-29dfddf22161
management:
docChecksum: c43b59c2013089d85388de072b9a0283
docChecksum: a0841885f1d2df6bf65c33550d1be776
docVersion: 0.4.0
speakeasyVersion: 1.441.0
generationVersion: 2.460.1
releaseVersion: 1.0.0
configChecksum: 71305aa56b02d549908d5e2cbee7c48f
repoURL: https://github.com/speakeasy-sdks/code-sample-api.git
installationURL: https://github.com/speakeasy-sdks/code-sample-api
speakeasyVersion: 1.463.1
generationVersion: 2.486.6
releaseVersion: 2.0.0
configChecksum: 88c5e327e8ad8129a9654dc84dd0c36d
published: true
features:
typescript:
acceptHeaders: 2.81.2
additionalDependencies: 0.1.0
core: 3.18.5
core: 3.18.12
defaultEnabledRetries: 0.1.0
devContainers: 2.90.0
downloadStreams: 0.1.1
enumUnions: 0.1.0
envVarSecurityUsage: 0.1.2
flattening: 2.82.0
globalSecurity: 2.82.11
globalSecurity: 2.82.12
globalSecurityCallbacks: 0.1.0
globalSecurityFlattening: 0.1.0
globalServerURLs: 2.82.4
globals: 2.82.1
groups: 2.81.2
nameOverrides: 2.81.2
reactQueryHooks: 0.2.2
responseFormat: 0.2.3
retries: 2.83.0
sdkHooks: 0.2.0
serverIDs: 2.81.2
tests: 0.7.0
uploadStreams: 0.1.0
generatedFiles:
- .devcontainer/README.md
- .devcontainer/devcontainer.json
- .devcontainer/setup.sh
- .eslintrc.cjs
- .gitattributes
- .npmignore
- CONTRIBUTING.md
- FUNCTIONS.md
- REACT_QUERY.md
- RUNTIMES.md
- USAGE.md
- docs/lib/utils/retryconfig.md
- docs/models/components/codesampleschemainput.md
- docs/models/components/codesamplesjobstatus.md
- docs/models/components/schemafile.md
- docs/models/components/security.md
- docs/models/components/usagesnippet.md
- docs/models/components/usagesnippets.md
- docs/models/errors/errort.md
- docs/models/operations/generatecodesamplepreviewasyncresponsebody.md
- docs/models/operations/generatecodesamplepreviewresponse.md
- docs/models/operations/getcodesamplepreviewasyncrequest.md
- docs/models/operations/getcodesamplepreviewasyncresponse.md
- docs/models/operations/getcodesamplepreviewasyncresponsebody.md
- docs/models/operations/getcodesamplesglobals.md
- docs/models/operations/getcodesamplesrequest.md
- docs/sdks/codesamples/README.md
- docs/sdks/sdk/README.md
- docs/sdks/speakeasycodesamples/README.md
- jsr.json
- package.json
- src/core.ts
- src/funcs/codesamplesGetAsync.ts
- src/funcs/codesamplesPreview.ts
- src/funcs/codesamplesPreviewAsync.ts
- src/funcs/codeSamplesGet.ts
- src/hooks/hooks.ts
- src/hooks/index.ts
- src/hooks/types.ts
Expand All @@ -82,19 +70,21 @@ generatedFiles:
- src/lib/sdks.ts
- src/lib/security.ts
- src/lib/url.ts
- src/models/components/codesampleschemainput.ts
- src/models/components/codesamplesjobstatus.ts
- src/models/components/index.ts
- src/models/components/security.ts
- src/models/components/usagesnippet.ts
- src/models/components/usagesnippets.ts
- src/models/errors/apierror.ts
- src/models/errors/error.ts
- src/models/errors/httpclienterrors.ts
- src/models/errors/index.ts
- src/models/errors/sdkvalidationerror.ts
- src/models/operations/generatecodesamplepreview.ts
- src/models/operations/generatecodesamplepreviewasync.ts
- src/models/operations/getcodesamplepreviewasync.ts
- src/models/operations/getcodesamples.ts
- src/models/operations/index.ts
- src/react-query/_context.tsx
- src/react-query/_types.ts
- src/react-query/codeSamplesGet.ts
- src/react-query/index.ts
- src/sdk/codesamples.ts
- src/sdk/index.ts
- src/sdk/sdk.ts
Expand All @@ -108,31 +98,14 @@ generatedFiles:
- src/types/streams.ts
- tsconfig.json
examples:
generateCodeSamplePreview:
speakeasy-default-generate-code-sample-preview:
requestBody:
multipart/form-data: {"languages": ["<value>"], "schema_file": {}}
responses:
4XX:
application/json: {"message": "<value>", "status_code": 159498}
"200": {}
generateCodeSamplePreviewAsync:
speakeasy-default-generate-code-sample-preview-async:
requestBody:
multipart/form-data: {"languages": ["<value>", "<value>"], "schema_file": {}}
responses:
"202":
application/json: {"job_id": "<id>", "status": "pending"}
4XX:
application/json: {"message": "<value>", "status_code": 677743}
getCodeSamplePreviewAsync:
speakeasy-default-get-code-sample-preview-async:
getCodeSamples:
speakeasy-default-get-code-samples:
parameters:
path:
jobID: "<id>"
query:
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
responses:
"202":
application/json: {"status": "pending"}
2XX:
application/json: {"snippets": [{"operationId": "<id>", "language": "<value>", "code": "<value>"}, {"operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 893724}
"200": {}
application/json: {"message": "<value>", "status_code": 558834}
generatedTests: {}
13 changes: 7 additions & 6 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ generation:
devContainers:
enabled: true
schemaPath: openapi.json
sdkClassName: SDK
sdkClassName: SpeakeasyCodeSamples
maintainOpenAPIOrder: true
usageSnippets:
optionalPropertyRendering: withExample
useClassNamesForArrayFields: true
fixes:
nameResolutionDec2023: true
parameterOrderingFeb2024: true
requestResponseComponentNamesFeb2024: true
nameResolutionDec2023: false
parameterOrderingFeb2024: false
requestResponseComponentNamesFeb2024: false
auth:
oAuth2ClientCredentialsEnabled: false
oAuth2PasswordEnabled: false
typescript:
version: 1.0.0
version: 2.0.0
additionalDependencies:
dependencies: {}
devDependencies: {}
Expand All @@ -25,6 +25,7 @@ typescript:
author: Speakeasy
clientServerStatusCodesAsErrors: true
defaultErrorName: APIError
enableReactQuery: true
enumFormat: enum
flattenGlobalSecurity: true
flatteningOrder: body-first
Expand All @@ -41,7 +42,7 @@ typescript:
methodArguments: require-security-and-request
moduleFormat: commonjs
outputModelSuffix: output
packageName: '@speakeasyapi/code-samples'
packageName: "@speakeasyapi/code-samples"
responseFormat: flat
templateVersion: v2
useIndexModules: true
6 changes: 2 additions & 4 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
speakeasyVersion: 1.441.0
speakeasyVersion: 1.463.1
sources:
speakeasy-OAS:
sourceNamespace: speakeasy-oas
Expand All @@ -13,8 +13,6 @@ targets:
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:3ce4076b437393a6fb3f102ac083c3d05a6e9e3e6daf47f99c6c4cf3a65b0e4c
sourceBlobDigest: sha256:785a83db337cb309aac27c4a805335396096391c489e7140d753840935ef8e55
codeSamplesNamespace: speakeasy-oas-code-samples
codeSamplesRevisionDigest: sha256:e5da15a44c4e0e5137d00c8cba0a0349cac5002cb0232608b12c6d34a517724f
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand All @@ -26,7 +24,7 @@ workflow:
- location: overlay.yaml
transformations:
- filterOperations:
operations: generateCodeSamplePreview, generateCodeSamplePreviewAsync, getCodeSamplePreviewAsync
operations: getCodeSamples
include: true
registry:
location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-public/speakeasy-oas
Expand Down
42 changes: 21 additions & 21 deletions .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
workflowVersion: 1.0.0
speakeasyVersion: latest
sources:
speakeasy-OAS:
inputs:
- location: https://www.speakeasy.com/openapi.yaml
overlays:
- location: overlay.yaml
transformations:
- filterOperations:
operations: generateCodeSamplePreview, generateCodeSamplePreviewAsync, getCodeSamplePreviewAsync
include: true
registry:
location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-public/speakeasy-oas
speakeasy-OAS:
inputs:
- location: https://www.speakeasy.com/openapi.yaml
overlays:
- location: overlay.yaml
transformations:
- filterOperations:
operations: getCodeSamples
include: true
registry:
location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-public/speakeasy-oas
targets:
code_samples_typescript_sdk:
target: typescript
source: speakeasy-OAS
publish:
npm:
token: $npm_token
codeSamples:
registry:
location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-public/speakeasy-oas-code-samples
blocking: false
code_samples_typescript_sdk:
target: typescript
source: speakeasy-OAS
publish:
npm:
token: $npm_token
codeSamples:
registry:
location: registry.speakeasyapi.dev/speakeasy-self/speakeasy-public/speakeasy-oas-code-samples
blocking: false
21 changes: 8 additions & 13 deletions FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,20 @@ specific category of applications.
## Example

```typescript
import { SDKCore } from "@speakeasyapi/code-samples/core.js";
import { codesamplesPreview } from "@speakeasyapi/code-samples/funcs/codesamplesPreview.js";
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";
import { openAsBlob } from "node:fs";

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

async function run() {
const res = await codesamplesPreview(sdk, {
languages: [
"<value>",
],
schemaFile: await openAsBlob("example.file"),
const res = await codeSamplesGet(speakeasyCodeSamples, {
registryUrl: "https://spec.speakeasy.com/org/ws/my-source",
});

switch (true) {
Expand Down
Loading

0 comments on commit 3e1d774

Please sign in to comment.