Skip to content

Commit

Permalink
playground component
Browse files Browse the repository at this point in the history
  • Loading branch information
walker-tx committed Feb 6, 2025
1 parent 3e3e219 commit 788455f
Show file tree
Hide file tree
Showing 35 changed files with 8,604 additions and 2,466 deletions.
28 changes: 0 additions & 28 deletions .eslintrc.cjs

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.eslintcache
/models
/models/errors
/types
Expand All @@ -17,4 +18,4 @@
/.tshy-*
/__tests__
/.speakeasy/reports
/react.*
/react.*
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
!/**/*.json
!/**/*.map

/.eslintrc.js
/eslint.config.mjs
/cjs
/.tshy
/.tshy-*
Expand Down
59 changes: 9 additions & 50 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ id: 521af75f-d011-41f9-a5ff-9f8033773118
management:
docChecksum: a16089f06495dd5f7de1f5121d72ec45
docVersion: 0.4.0
speakeasyVersion: 1.469.1
generationVersion: 2.493.21
releaseVersion: 2.1.5
configChecksum: 04582a1dd2d7ea07d7682cb354d2593a
speakeasyVersion: 1.484.1
generationVersion: 2.503.2
releaseVersion: 2.1.6
configChecksum: 21f134167daabccf2f501cd418de0227
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.18.16
core: 3.18.22
deepObjectParams: 0.1.0
defaultEnabledRetries: 0.1.0
devContainers: 2.90.0
Expand All @@ -23,7 +23,7 @@ features:
globalSecurityCallbacks: 0.1.0
globalSecurityFlattening: 0.1.0
globalServerURLs: 2.82.4
globals: 2.82.1
globals: 2.82.2
groups: 2.81.2
nameOverrides: 2.81.2
reactQueryHooks: 0.2.2
Expand All @@ -35,7 +35,6 @@ generatedFiles:
- .devcontainer/README.md
- .devcontainer/devcontainer.json
- .devcontainer/setup.sh
- .eslintrc.cjs
- .gitattributes
- .npmignore
- FUNCTIONS.md
Expand All @@ -53,6 +52,7 @@ generatedFiles:
- docs/models/operations/methodpaths.md
- docs/sdks/codesamples/README.md
- docs/sdks/speakeasycodesamples/README.md
- eslint.config.mjs
- jsr.json
- package.json
- src/core.ts
Expand Down Expand Up @@ -106,15 +106,6 @@ generatedFiles:
- tsconfig.json
examples:
getCodeSamples:
speakeasy-default-get-code-samples:
parameters:
query:
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
responses:
2XX:
application/json: {"snippets": [{"operationId": "<id>", "language": "<value>", "code": "<value>"}, {"operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 558834}
"":
parameters:
query:
Expand All @@ -124,42 +115,9 @@ examples:
languages: ["python", "javascript"]
responses:
2XX:
application/json: {"snippets": [{"path": "/usr/bin", "method": "<value>", "operationId": "<id>", "language": "<value>", "code": "<value>"}, {"path": "/sbin", "method": "<value>", "operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 558834}
python:
parameters:
query:
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
operation_ids: ["getPetById"]
languages: ["python"]
responses:
2XX:
application/json: {"snippets": [{"operationId": "<id>", "language": "<value>", "code": "<value>"}, {"operationId": "<id>", "language": "<value>", "code": "<value>"}]}
application/json: {"snippets": [{"path": "/sbin", "method": "<value>", "operationId": "<id>", "language": "<value>", "code": "<value>"}, {"path": "/root", "method": "<value>", "operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 521235}
typescript:
parameters:
query:
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
operation_ids: ["getPetById"]
languages: ["typescript"]
responses:
2XX:
application/json: {"snippets": [{"operationId": "<id>", "language": "<value>", "code": "<value>"}, {"operationId": "<id>", "language": "<value>", "code": "<value>"}, {"operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 458049}
java:
parameters:
query:
registry_url: "https://spec.speakeasy.com/org/ws/my-source"
operation_ids: ["getPetById"]
languages: ["java"]
responses:
2XX:
application/json: {"snippets": [{"operationId": "<id>", "language": "<value>", "code": "<value>"}]}
4XX:
application/json: {"message": "<value>", "status_code": 262795}
default:
parameters:
query:
Expand All @@ -170,4 +128,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
generatedTests: {}
7 changes: 4 additions & 3 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ generation:
oAuth2ClientCredentialsEnabled: false
oAuth2PasswordEnabled: false
typescript:
version: 2.1.5
version: 2.1.6
additionalDependencies:
dependencies: {}
dependencies:
'@speakeasy-api/moonshine': ^0.69.0
devDependencies: {}
peerDependencies:
highlight.js: ^11.11.1
Expand All @@ -42,7 +43,7 @@ typescript:
inputModelSuffix: input
maxMethodParams: 1
methodArguments: require-security-and-request
moduleFormat: esm
moduleFormat: dual
outputModelSuffix: output
packageName: '@speakeasyapi/code-samples'
responseFormat: flat
Expand Down
8 changes: 3 additions & 5 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
speakeasyVersion: 1.469.1
speakeasyVersion: 1.484.1
sources:
speakeasy-OAS:
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:a284a288efce8e30ca155f36afa6d57032371ebf0ee011be67935518d5f6ed0e
sourceRevisionDigest: sha256:67db66bfe8bee7caf24220f613e60760c90e0a7fe721b9f70d46e584d61a8d79
sourceBlobDigest: sha256:63701f5ff26c0ac6e0ea6e314b9dc7bf7063bf75b72a16206b62050baf740623
tags:
- latest
Expand All @@ -11,10 +11,8 @@ targets:
code_samples_typescript_sdk:
source: speakeasy-OAS
sourceNamespace: speakeasy-oas
sourceRevisionDigest: sha256:a284a288efce8e30ca155f36afa6d57032371ebf0ee011be67935518d5f6ed0e
sourceRevisionDigest: sha256:67db66bfe8bee7caf24220f613e60760c90e0a7fe721b9f70d46e584d61a8d79
sourceBlobDigest: sha256:63701f5ff26c0ac6e0ea6e314b9dc7bf7063bf75b72a16206b62050baf740623
codeSamplesNamespace: speakeasy-oas-typescript-code-samples
codeSamplesRevisionDigest: sha256:0aedfcea07baf7ac910025bd5491f555d24eba851d90db84232eef11a8167b26
workflow:
workflowVersion: 1.0.0
speakeasyVersion: latest
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ yarn add @tanstack/react-query react react-dom
```

> [!NOTE]
> This package is published as an ES Module (ESM) only. For applications using
> CommonJS, use `await import("@speakeasyapi/code-samples")` to import and use this package.
> This package is published with CommonJS and ES Modules (ESM) support.
<!-- End SDK Installation [installation] -->
<!-- Start Requirements [requirements] -->
Expand Down Expand Up @@ -140,8 +139,8 @@ run();
### React Component

This library includes a React component that fetches and highlights code
snippets using `highlight.js`. Along with displaying the snippet, it shows a loading state during
fetching and provides a fallback view if an error occurs.
snippets using `highlight.js`. Along with displaying the snippet, it shows a
loading state during fetching and provides a fallback view if an error occurs.

```tsx
import { SpeakeasyCodeSamplesCore } from "@speakeasyapi/code-samples/core";
Expand Down
21 changes: 21 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

/** @type {import('eslint').Linter.Config[]} */
export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
{
rules: {
"no-constant-condition": "off",
// Handled by typescript compiler
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-object-type": "off",
"@typescript-eslint/no-namespace": "off",
},
},
];
3 changes: 3 additions & 0 deletions example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

VITE_SPEAKEASY_REGISTRY_URL=https://spec.speakeasy.com/walker/esv/esv-org-api-with-code-samples
VITE_SPEAKEASY_API_KEY=eyJpZCI6ImNtNnI5NXM2MDAwMDAyZTdvbmY5bWpodXkiLCJuYW1lIjoiY29kZS1zYW1wbGUtc2RrLWV4YW1wbGUiLCJ3b3Jrc3BhY2VJZCI6ImNtNm5zbWNueDAwMDAyZTc4MHF6dmxhZWUiLCJjcmVhdGVkQXQiOiIyMDI1LTAyLTA1VDAxOjUxOjE3LjIwOFoiLCJhbGciOiJTSEFSRURfU0VDUkVUIiwic2VjcmV0IjoiWldrbE1rTWxRelVsUVRFbFF6SWxRallsUXpNbE9FVWxSVElsT0RBbE9Ua2xRek1sUVVOc1ZUQWxSVElsT0RBbE9VTXhKVU16SlRnM0pVTXpKVGd4SlRFMWVYb2xRek1sT0RjbFF6TWxPVEUySlVNMUpVSTRKVU16SlRrNWVpVkROU1ZDUkNVd1JDMGxReklsUVROeEpUZENKVEE1TFhBbE1UVWxNVVFsUXpNbE9FVWxOREFsUlRJbE9EQWxPVVFsUXpJbFFVRWxRek1sT1VZbFF6VWxRVEVvSlVNeUpVRkdXVk5RWmpnbFF6TWxRVVFsTURVbFF6VWxRa1FsUXpNbFFVWWxReklsUWtNbFF6TWxRVVpZVUVVbFF6TWxRVVlsUXpVbE9USWxReklsT1RBbFF6SWxRa0VsTVRNbFF6SWxRa1VsTURNPSIsImNyZWF0ZWRCeSI6IjhjMjRkMTNmLThhMjQtNGIyNC1hOGZlLTQyODVmOTA3MTY2MyJ9
24 changes: 24 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
50 changes: 50 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react'

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
})
```
28 changes: 28 additions & 0 deletions example/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
15 changes: 15 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">-->
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/9000.0.1/themes/prism.min.css" integrity="sha512-/mZ1FHPkg6EKcxo0fKXF51ak6Cr2ocgDi5ytaTBjsQZIH/RNs6GF6+oId/vPe3eJB836T36nXwVh/WBl/cWT4w==" crossorigin="anonymous" referrerpolicy="no-referrer" />-->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading

0 comments on commit 788455f

Please sign in to comment.