Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/support multi languages #815

Merged
merged 31 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d60d8dd
feat: support for other languages than typescript
stijnvanhulle Feb 7, 2024
57d606e
chore: cleanup
stijnvanhulle Feb 7, 2024
6e39777
chore: rename language by editor
stijnvanhulle Feb 7, 2024
62a7c96
Merge branch 'main' into feat/supportMultiLanguages
stijnvanhulle Feb 19, 2024
c624ed2
chore: cleanup
stijnvanhulle Feb 19, 2024
9642ee4
feat: editor component
stijnvanhulle Feb 19, 2024
24ecdec
chore: cleanup
stijnvanhulle Feb 19, 2024
0bfe2b9
chore: update
stijnvanhulle Feb 19, 2024
aba5379
docs: correct name
stijnvanhulle Feb 19, 2024
7e19fdd
docs: simple python example
stijnvanhulle Feb 19, 2024
f2db759
docs: fix import
stijnvanhulle Feb 19, 2024
ff0d79d
chore: cleanup for editor logic
stijnvanhulle Feb 19, 2024
9bd9373
chore: update snaps
stijnvanhulle Feb 19, 2024
56fc4e3
Merge branch 'main' into feat/supportMultiLanguages
stijnvanhulle Feb 24, 2024
57a78fd
feat: support for other languages than typescript
stijnvanhulle Feb 7, 2024
adfd15b
chore: cleanup
stijnvanhulle Feb 7, 2024
e89f1e1
chore: rename language by editor
stijnvanhulle Feb 7, 2024
eca2fd1
chore: cleanup
stijnvanhulle Feb 19, 2024
b7a758f
feat: editor component
stijnvanhulle Feb 19, 2024
685c10d
chore: cleanup
stijnvanhulle Feb 19, 2024
0ec1c61
chore: update
stijnvanhulle Feb 19, 2024
2c02a63
docs: correct name
stijnvanhulle Feb 19, 2024
59931b4
docs: simple python example
stijnvanhulle Feb 19, 2024
7e871b5
docs: fix import
stijnvanhulle Feb 19, 2024
f4c0c18
chore: cleanup for editor logic
stijnvanhulle Feb 19, 2024
6651f74
chore: update snaps
stijnvanhulle Feb 19, 2024
15bc67a
chore: update
stijnvanhulle Feb 24, 2024
2deb951
Merge branch 'main' into feat/supportMultiLanguages
stijnvanhulle Mar 4, 2024
f3316fb
chore: update changes
stijnvanhulle Mar 4, 2024
195695a
chore: update examples
stijnvanhulle Mar 4, 2024
e63d962
chore: fix linting
stijnvanhulle Mar 4, 2024
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
6 changes: 6 additions & 0 deletions .changeset/wet-buttons-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kubb/swagger-client": minor
"@kubb/react": minor
---

editor component to support multiple languages with Kubb templates
1 change: 1 addition & 0 deletions .codesandbox/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"/examples/advanced",
"/examples/faker",
"/examples/msw",
"/examples/python",
"/examples/msw-v2",
"/examples/react-query",
"/examples/react-query-v5",
Expand Down
8 changes: 8 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ const pluginsSidebar = [
text: 'Function',
link: '/plugins/react/components/function',
},
{
text: 'Editor <img src="/icons/experimental.svg"/> <span class="new">new</span>',
link: '/plugins/react/components/editor',
},
{
text: 'Type',
link: '/plugins/react/components/type',
Expand Down Expand Up @@ -342,6 +346,10 @@ const examplesSidebar = [
text: 'Templates <span class="new">new</span>',
link: '/examples/client',
},
{
text: 'Python <span class="new">new</span>',
link: '/examples/python',
},
]

const blogSidebar = [
Expand Down
18 changes: 18 additions & 0 deletions docs/examples/python.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Python PetStore
aside: false
---

<iframe
src="https://codesandbox.io/embed/github/kubb-project/kubb/tree/main/examples/python?fontsize=14&module=%2Fsrc%2Fgen%2Fmodels%2FPerson.ts&theme=dark&view=editor"
:style="{
width: '100%',
height: '700px',
border: 0,
borderRadius: '4px',
overflow: 'hidden'
}"
title="python"
allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking"
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
/>
2 changes: 1 addition & 1 deletion docs/guide/tutorial/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ import { defineConfig } from '@kubb/core'
import createSwagger from '@kubb/swagger'
import createSwaggerTS from '@kubb/swagger-ts'

import { templates } from './templates/CustomClientTemplates.tsx'
import { templates } from './templates/CustomClientTemplate.tsx'

export default defineConfig(async () => {
return {
Expand Down
45 changes: 45 additions & 0 deletions docs/plugins/react/components/editor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
layout: doc

title: \@kubb/react
outline: deep
---

# Editor

::: code-group

```tsx [simple]
import { createRoot, Editor } from '@kubb/react'

const root = createRoot()

const Component = () => {
return (
<Editor language="text">
export const test = 2
</Editor>
)
}

root.render(<Component />)

return root.output
```

:::

::: code-group

```typescript [simple]
export const test = 2
```

:::

## API

| Property | Description | Type | Default |
| -------- | -------------------------- | ---------------------------------- | ------- |
| language | Name of the language used. | `typescript' \| 'text' \| string` | - |
| children | | `KubbNode \| undefined` | - |
2 changes: 1 addition & 1 deletion docs/plugins/swagger-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ export default defineConfig({
})
```

<<< @/../examples/client/templates/CustomClientTemplates.tsx
<<< @/../examples/client/templates/CustomClientTemplate.tsx

:::

Expand Down
2 changes: 1 addition & 1 deletion examples/advanced/src/gen/zod/userSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const userSchema = z.object({
'username': z.string().optional(),
'firstName': z.string().optional(),
'lastName': z.string().optional(),
'email': z.string().email().optional(),
'email': z.string().optional(),
'password': z.string().optional(),
'phone': z.string().optional(),
'userStatus': z.number().describe(`User Status`).optional(),
Expand Down
2 changes: 1 addition & 1 deletion examples/client/templates/CustomClientTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const templates = {
<>
<File.Import name="axios" path="axios" />
<Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
{`return axios.${client.method}(${clientParams}`}
{`return axios.${client.method}(${clientParams})`}
</Function>
</>
)
Expand Down
23 changes: 0 additions & 23 deletions examples/client/templates/CustomClientTemplates.tsx

This file was deleted.

9 changes: 9 additions & 0 deletions examples/python/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tabWidth": 2,
"printWidth": 160,
"parser": "typescript",
"singleQuote": true,
"semi": false,
"bracketSameLine": false,
"endOfLine": "auto"
}
37 changes: 37 additions & 0 deletions examples/python/kubb.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { defineConfig } from '@kubb/core'

import { templates } from './templates/CustomClientTemplate'

export default defineConfig(async () => {
return {
root: '.',
input: {
// path: './test.json',
path: './petStore.yaml',
},
output: {
path: './src/gen',
clean: true,
},
hooks: {
// done: ['npx eslint --fix ./src/gen', 'prettier --write "**/*.{ts,tsx}"', 'pnpm typecheck'],
},
plugins: [
['@kubb/swagger', { output: false, validate: true }],
[
'@kubb/swagger-client',
{
output: {
path: './',
exportType: false,
},
group: { type: 'tag', output: './{{tag}}Service' },
templates: {
client: templates,
operations: false,
},
},
],
],
}
})
42 changes: 42 additions & 0 deletions examples/python/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "python-pet-store",
"version": "0.0.1",
"private": true,
"description": "Client PetStore example",
"repository": {
"type": "git",
"url": "git://github.com/kubb-project/kubb.git",
"directory": "packages/examples/python"
},
"license": "MIT",
"author": "Stijn Van Hulle <[email protected]",
"sideEffects": false,
"scripts": {
"build": "tsup",
"clean": "npx rimraf ./dist",
"generate": "kubb generate --config kubb.config.ts",
"start": "tsup --watch",
"test": "vitest",
"typecheck": ""
},
"dependencies": {
"@kubb/cli": "workspace:*",
"@kubb/core": "workspace:*",
"@kubb/react": "workspace:*",
"@kubb/swagger": "workspace:*",
"@kubb/swagger-client": "workspace:*",
"@kubb/swagger-ts": "workspace:*",
"axios": "^1.6.7"
},
"devDependencies": {
"@kubb/ts-config": "workspace:*",
"react": "^18.2.0",
"tsup": "^8.0.2",
"typescript": "^5.3.3"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=18",
"pnpm": ">=8.3.0"
}
}
Loading
Loading