generate exceptions in implementation

This commit is contained in:
2021-12-02 11:59:10 +01:00
parent fe9c431999
commit c9e54aebc8
7 changed files with 68 additions and 9 deletions

View File

@ -13,6 +13,10 @@ parser.add_argument('--apiDefinitionFile', '-a',
help='API definition file. Default: openapi.yaml in the current folder.',
required=False,
default='./openapi.yaml')
parser.add_argument('--errorDefinitionFile', '-e',
help='Error definition file. Default: serviceErrorCodes.yaml in the current folder.',
required=False,
default='./serviceErrorCodes.yaml')
parser.add_argument('--template', '-t',
help="""Template file, templates files must be named as the final output file
with an additional .tmpl extension. Default: all template files recursively from the current folder.""",
@ -23,6 +27,9 @@ args = parser.parse_args()
with open(args.apiDefinitionFile) as apiDefinitionFile:
apiDefinition = yaml.load(apiDefinitionFile, Loader=SafeLoader)
with open(args.errorDefinitionFile) as errorDefinitionFile:
errorDefinition = yaml.load(errorDefinitionFile, Loader=SafeLoader)
apiDefinition["GENERATED_SQL_COMMENT"] = """
@ -142,9 +149,10 @@ for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items()
apiDefinition['types'] = types
print(json.dumps(apiDefinition, indent=4))
print(json.dumps(errorDefinition, indent=4))
for f in glob.glob(args.template, recursive=True):
print(f"process {f}")
tmpl = Template(file=f, searchList=[apiDefinition])
tmpl = Template(file=f, searchList=[apiDefinition, errorDefinition])
with open(f[:-5], 'w') as outFile:
outFile.write(str(tmpl))