add example code generator

This commit is contained in:
marys
2026-06-03 10:36:11 +02:00
parent b4ad1d2fd7
commit 03b5f3c2ea
17 changed files with 308 additions and 56 deletions
+30 -6
View File
@@ -1,7 +1,31 @@
//1
import { File } from '@asyncapi/generator-react-sdk'
//2
// //1
// import { File } from '@asyncapi/generator-react-sdk'
// //2
// export default function ({ asyncapi }) {
// //3
// return <File name="client.py">{asyncapi.info().title()}</File>
// }
import { File } from '@asyncapi/generator-react-sdk';
export default function ({ asyncapi }) {
//3
return <File name="client.py">{asyncapi.info().title()}</File>
}
return (
<File name="client.py">
{`import paho.mqtt.client as mqtt
mqttBroker = "test.mosquitto.org"
class TemperatureServiceClient:
def __init__(self):
self.client = mqtt.Client()
self.client.connect(mqttBroker)
def sendTemperatureChange(self, id):
topic = "temperature/changed"
self.client.publish(topic, id)`}
</File>
)
}
+29
View File
@@ -0,0 +1,29 @@
// //1
// import { File } from '@asyncapi/generator-react-sdk'
// //2
// export default function ({ asyncapi }) {
// //3
// return <File name="client.py">{asyncapi.info().title()}</File>
// }
import { File } from '@asyncapi/generator-react-sdk';
export default function ({ asyncapi, params }) {
const channels = Object.keys(asyncapi.components());
let content = ''
for (const channel of channels) {
content += `# channel: ${channel}\n`
}
return (
<File name="client2.py"># {asyncapi.info().title()}
{`\n`}
# {asyncapi.info().description()}
{`\n`}
{channels.map((ch) => `# channel: ${ch}\n`)}
{content}
</File>
)
}