-
-
Notifications
You must be signed in to change notification settings - Fork 25
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: migrated the whole template to react #207
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,11 +18,5 @@ module.exports = { | |
} | ||
} | ||
} | ||
|
||
// If there are no schemas, we expect to find an anonymous one embedded in a payload. If we do have schemas we assume we don't need this. | ||
// This will turn out to be a bug if we ever have a file with schemas, but which also has an anonymous schema embedded in an operation. | ||
if (hasSchema) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it not needed because of or basically why |
||
fs.unlinkSync(path.resolve(generator.targetDir, 'payload.py')); | ||
} | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const _ = require('lodash'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of partials people should rather opt in to use |
||
const getTypeInfo = require('../helpers/all').getTypeInfo; | ||
const indent1 = require('../helpers/all').indent1; | ||
const indent2 = require('../helpers/all').indent2; | ||
const indent3 = require('../helpers/all').indent3; | ||
const indent4 = require('../helpers/all').indent4; | ||
|
||
function modelClass(name, properties, required, indentLevel = 1) { | ||
const className = _.upperFirst(name); | ||
|
||
let classDefinition = `${indent1(indentLevel)}class ${className}(Entity):\n`; | ||
|
||
Object.entries(properties).forEach(([propName, prop]) => { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
|
||
if (typeInfo.recursive) { | ||
classDefinition += modelClass( | ||
typeInfo.innerType, typeInfo.properties, prop.required(), indentLevel + 1 | ||
); | ||
} else if (typeInfo.generalType === 'enum') { | ||
classDefinition += `${indent2(indentLevel)}class ${typeInfo.type}(str, Enum):\n`; | ||
typeInfo.enum.forEach((value) => { | ||
classDefinition += `${indent3(indentLevel)}${value} = '${value}'\n`; | ||
}); | ||
classDefinition += `${indent2(indentLevel)}\n`; | ||
} | ||
}); | ||
|
||
classDefinition += `${indent2(indentLevel)}def __init__(self,\n`; | ||
|
||
Object.entries(properties).forEach(([propName, prop], index) => { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
const separator = index === 0 ? '' : ',\n'; | ||
classDefinition += `${separator}${indent4(indentLevel)}${typeInfo.pythonName}: ${typeInfo.pythonType}`; | ||
}); | ||
|
||
classDefinition += `):\n`; | ||
|
||
Object.entries(properties).forEach(([propName, prop]) => { | ||
const typeInfo = getTypeInfo([propName, prop]); | ||
classDefinition += `${indent3(indentLevel)}self.${typeInfo.pythonName} = ${typeInfo.pythonName}\n`; | ||
}); | ||
|
||
if (Object.keys(properties).length === 0) { | ||
classDefinition += `${indent3(indentLevel)}pass\n`; | ||
} | ||
|
||
classDefinition += `${indent1(indentLevel)}\n`; | ||
return classDefinition; | ||
} | ||
|
||
module.exports = { modelClass } |
This file was deleted.
This file was deleted.
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; |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you take this direction? did you face some issues while testing changes?