Skip to content

Commit

Permalink
docs: simple python example
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvanhulle committed Feb 19, 2024
1 parent aba5379 commit 7e19fdd
Show file tree
Hide file tree
Showing 67 changed files with 1,618 additions and 558 deletions.
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
4 changes: 4 additions & 0 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,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: 0 additions & 2 deletions docs/plugins/react/components/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ outline: deep

# Editor

## Editor

::: code-group

```tsx [simple]
Expand Down
16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/createUser.kt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/deleteUser.kt

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/getUserByName.kt

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/loginUser.kt

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/logoutUser.kt

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions examples/client/src/gen/clients/axios/userService/updateUser.kt

This file was deleted.

This file was deleted.

61 changes: 5 additions & 56 deletions examples/client/templates/CustomClientTemplate.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,17 @@
import { File, Function, Editor } from '@kubb/react'
import { File, Function } from '@kubb/react'
import { Client } from '@kubb/swagger-client/components'
import React from 'react'
import { useOperationFile } from '@kubb/swagger/hooks'

export const templates = {
default: function({ name, generics, returnType, params, JSDoc, client }: React.ComponentProps<typeof Client.templates.default>) {
const clientParams = [client.path.template, client.withData ? 'data' : undefined, 'options'].filter(Boolean).join(', ')

const filePython = useOperationFile({ extName: '.py' })
const fileKotlin = useOperationFile({ extName: '.kt' })

return (
<>
<Editor language="typescript">
<File.Import name="axios" path="axios" />
<Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
{`return axios.${client.method}(${clientParams})`}
</Function>
</Editor>
<Editor language="text">
<File
baseName={fileKotlin.baseName}
path={fileKotlin.path}
meta={fileKotlin.meta}
>
<File.Source>
{`
package com.example.blog
import org.springframework.stereotype.Controller
import org.springframework.ui.Model
import org.springframework.ui.set
import org.springframework.web.bind.annotation.GetMapping
@Controller
class HtmlController {
@GetMapping("${client.path.URL}")
fun ${name}(model: Model): String {
model["title"] = "Blog"
return "blog"
}
}
`}
</File.Source>
</File>
</Editor>
<Editor language="text">
<File
baseName={filePython.baseName}
path={filePython.path}
meta={filePython.meta}
>
<File.Source>
import requests
<br />
<br />
{`response = requests.${client.method}("${client.path.URL}")`}
<br />
<br />
print(response.status_code)
</File.Source>
</File>
</Editor>
<File.Import name="axios" path="axios" />
<Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
{`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,
},
},
],
],
}
})
Loading

0 comments on commit 7e19fdd

Please sign in to comment.