-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
212 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
function modelClass(name, properties, required, indentLevel) { | ||
const className = upperFirst(name); | ||
const indent1 = indent(indentLevel); | ||
const indent2 = indent(indentLevel + 1); | ||
const indent3 = indent(indentLevel + 2); | ||
const indent4 = indent(indentLevel + 3); | ||
|
||
let output = `${indent1}class ${className}(Entity):\n`; | ||
|
||
// Render nested classes and enums | ||
for (const [propName, prop] of Object.entries(properties)) { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
if (typeInfo.recursive) { | ||
output += modelClass(typeInfo.innerType, typeInfo.properties, prop.required(), indentLevel + 1); | ||
} else if (typeInfo.generalType === 'enum') { | ||
output += `${indent2}class ${typeInfo.type}(str, Enum):\n`; | ||
for (const v of typeInfo.enum) { | ||
output += `${indent3}${v} = '${v}'\n`; | ||
} | ||
} | ||
} | ||
|
||
// Render __init__ method | ||
output += `${indent2}def __init__(\n`; | ||
output += `${indent4}self`; | ||
|
||
for (const [propName, prop] of Object.entries(properties)) { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
output += `,\n${indent4}${typeInfo.pythonName}${typeInfo.pythonType ? ': ' + typeInfo.pythonType : ''}`; | ||
} | ||
output += '\n' + indent2 + '):\n'; | ||
|
||
// Render __init__ body | ||
const initBody = Object.entries(properties).map(([propName, prop]) => { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
return `${indent3}self.${typeInfo.pythonName} = ${typeInfo.pythonName}`; | ||
}); | ||
|
||
if (initBody.length > 0) { | ||
output += initBody.join('\n') + '\n'; | ||
} else { | ||
output += indent3 + 'pass\n'; | ||
} | ||
|
||
return output; | ||
} | ||
|
||
module.exports = modelClass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const sanitizeFilename = require('sanitize-filename'); | ||
|
||
function convertToFilename(string, options = { replacement: '-', maxLength: 255 }) { | ||
let sanitizedString = sanitizeFilename(string); | ||
|
||
sanitizedString = sanitizedString.replace(/[\s]+/g, options.replacement); | ||
|
||
if (sanitizedString.length > options.maxLength) { | ||
sanitizedString = sanitizedString.slice(0, options.maxLength); | ||
} | ||
|
||
return sanitizedString; | ||
} | ||
|
||
module.exports = convertToFilename; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const { File } = require('@asyncapi/generator-react-sdk'); | ||
|
||
function ReadmeFile({ asyncapi }) { | ||
return ( | ||
<File name={'README.md'}> | ||
{`# ${ asyncapi.info().title() } | ||
## Version ${ asyncapi.info().version() } | ||
${ asyncapi.info().description() }`} | ||
</File> | ||
); | ||
} | ||
|
||
module.exports = ReadmeFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { File } = require('@asyncapi/generator-react-sdk'); | ||
|
||
function ReadmeFile({ asyncapi }) { | ||
return ( | ||
<File name={'config-template.in'}> | ||
{`[DEFAULT] | ||
host= | ||
password= | ||
port= | ||
username= | ||
`} | ||
</File> | ||
); | ||
} | ||
|
||
module.exports = ReadmeFile; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import json | ||
const { File } = require('@asyncapi/generator-react-sdk'); | ||
|
||
function ReadmeFile({ asyncapi }) { | ||
return ( | ||
<File name={'entity.py'}> | ||
{`import json | ||
class Entity(): | ||
"""This is the base class for the model classes. It provides json serialization methods.""" | ||
@classmethod | ||
def from_json(cls, data): | ||
jsonObj = json.loads(data) | ||
return cls(**jsonObj) | ||
def to_json(self): | ||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=2) | ||
return json.dumps(self, default=lambda o: o.__dict__, sort_keys=True, indent=2)`} | ||
</File> | ||
); | ||
} | ||
|
||
module.exports = ReadmeFile; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
const { File } = require('@asyncapi/generator-react-sdk'); | ||
const _ = require('lodash'); | ||
const { getRealSubscriber } = require('../helpers/all.js') | ||
const {getFunctionNameByChannel } = require('../helpers/all.js') | ||
const {getPayloadClass }= require('../helpers/all.js') | ||
const {getFirstPublisherMessenger } = require('../helpers/all.js') | ||
const {getMessengers } = require('../helpers/all.js') | ||
|
||
function generatePythonCode(asyncapi, params) { | ||
let code = `#!/usr/bin/env python3 | ||
import configparser | ||
import logging | ||
import time | ||
import messaging | ||
`; | ||
|
||
if (asyncapi.components() && asyncapi.components().schemas()) { | ||
Object.entries(asyncapi.components().schemas()).forEach(([schemaName, schema]) => { | ||
const moduleName = _.lowerFirst(schemaName); | ||
code += `from ${moduleName} import ${_.upperFirst(schemaName)}\n`; | ||
}); | ||
} else { | ||
code += 'from payload import Payload\n'; | ||
} | ||
|
||
code += ` | ||
# Config has the connection properties. | ||
def getConfig(): | ||
configParser = configparser.ConfigParser() | ||
configParser.read('config.ini') | ||
config = configParser['DEFAULT'] | ||
return config | ||
`; | ||
|
||
|
||
|
||
code += ` | ||
def main(): | ||
logging.basicConfig(level=logging.INFO) | ||
logging.info('Start of main.') | ||
config = getConfig() | ||
`; | ||
|
||
// const publishMessenger = getFirstPublisherMessenger(params, asyncapi); | ||
// const messengers = getMessengers(params, asyncapi); | ||
|
||
// messengers.forEach(messenger => { | ||
// if (messenger.subscribeTopic) { | ||
// code += ` ${messenger.name} = messaging.Messaging(config, '${messenger.subscribeTopic}', ${messenger.functionName})\n`; | ||
// } else { | ||
// code += ` ${messenger.name} = messaging.Messaging(config)\n`; | ||
// } | ||
|
||
// if (publishMessenger) { | ||
// code += ` ${messenger.name}.loop_start()\n`; | ||
// } else { | ||
// code += ` ${messenger.name}.loop_forever()\n`; | ||
// } | ||
// }); | ||
|
||
// if (publishMessenger) { | ||
// code += ` | ||
// # Example of how to publish a message. You will have to add arguments to the constructor on the next line: | ||
// payload = ${publishMessenger.payloadClass}() | ||
// payloadJson = payload.to_json() | ||
// while True: | ||
// ${publishMessenger.name}.publish('${publishMessenger.publishTopic}', payloadJson) | ||
// time.sleep(1) | ||
// `; | ||
// } | ||
|
||
return code; | ||
} | ||
|
||
function MainFile({ asyncapi, params }) { | ||
const generatedCode = generatePythonCode(asyncapi, params); | ||
// const allChannels = channels.all() | ||
console.log("HIIII",asyncapi.channels()) | ||
console.log("typeof",typeof asyncapi.channels()) | ||
|
||
|
||
return ( | ||
<File name="main.py"> | ||
{generatedCode} | ||
{/* {`heello from msin`} */} | ||
</File> | ||
); | ||
} | ||
|
||
module.exports = MainFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.