fix converter item, fix datetime handling, fix parsing of markdown description
This commit is contained in:
32
generate.py
32
generate.py
@ -68,20 +68,21 @@ apiDefinition["env"] = {
|
||||
"packagename": os.environ["PACKAGE_NAME"],
|
||||
"routeprefix": os.environ["ROUTE_PREFIX"]
|
||||
}
|
||||
statementFinder = re.compile('STATEMENTBEGIN (.*) STATEMENTEND')
|
||||
statementFinder = re.compile('STATEMENTBEGIN(\s+)(.+)(\s+)STATEMENTEND', flags=re.DOTALL)
|
||||
statementCleaner = re.compile('\s+')
|
||||
statementChecker = {
|
||||
'get': re.compile('^select', re.IGNORECASE),
|
||||
'put': re.compile('^update', re.IGNORECASE),
|
||||
'delete': re.compile('^delete', re.IGNORECASE),
|
||||
'post': re.compile('^insert', re.IGNORECASE)
|
||||
}
|
||||
databaseTagFinder = re.compile('DATABASETAGBEGIN (.*) DATABASETAGEND')
|
||||
databaseTagFinder = re.compile('DATABASETAGBEGIN(\s+)(\S+)(\s+)DATABASETAGEND', flags=re.DOTALL)
|
||||
|
||||
operations = []
|
||||
for path in apiDefinition['paths'].values():
|
||||
for (method, operation) in path.items():
|
||||
#print(f"{method=}")
|
||||
#print(f"{CsOperationNameConverter(operation['operationId'])=}")
|
||||
print(f"{method=}")
|
||||
print(f"{CsOperationNameConverter(operation['operationId'])=}")
|
||||
# if 200 in
|
||||
content = operation['responses'][200]['content']['application/json']['schema']
|
||||
if ('type' in content) and (content['type'] == 'array'):
|
||||
@ -90,20 +91,27 @@ for path in apiDefinition['paths'].values():
|
||||
else:
|
||||
isList = False
|
||||
resultType = OpenApiExtractRefType(content['$ref'])
|
||||
#print(f"{content=}")
|
||||
#print(f"{resultType=}")
|
||||
print(f"{content=}")
|
||||
print(f"{resultType=}")
|
||||
description = None
|
||||
statement = None
|
||||
if 'description' in operation:
|
||||
description = operation['description']
|
||||
print(f"{description=}")
|
||||
statementFinderResult = statementFinder.search(description)
|
||||
if statementFinderResult:
|
||||
statement = statementFinderResult.group(1)
|
||||
statement = statementCleaner.sub(' ', statementFinderResult.group(2))
|
||||
print(f"{statement=}")
|
||||
if not statementChecker[method].match(statement):
|
||||
raise Exception(f"Invalid statement {statement} for method {method}")
|
||||
else:
|
||||
print("no statement")
|
||||
databaseTagFinderResult = databaseTagFinder.search(description)
|
||||
if databaseTagFinderResult:
|
||||
databaseTag = databaseTagFinderResult.group(1)
|
||||
databaseTag = databaseTagFinderResult.group(2)
|
||||
print(f"{databaseTag=}")
|
||||
else:
|
||||
print("no databasetag")
|
||||
|
||||
bodyInputType = {}
|
||||
if 'requestBody' in operation:
|
||||
@ -132,15 +140,15 @@ for path in apiDefinition['paths'].values():
|
||||
'bodyInputType': bodyInputType,
|
||||
'paramInputTypes': paramInputTypes
|
||||
})
|
||||
#print(f"{operations=}")
|
||||
print(f"{operations=}")
|
||||
apiDefinition["operations"] = operations
|
||||
|
||||
types = {}
|
||||
for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items():
|
||||
#print(f"{typeName=}")
|
||||
print(f"{typeName=}")
|
||||
typeProperties = []
|
||||
for itemName in typeDefinition['properties']:
|
||||
#print(f"{itemName=}")
|
||||
print(f"{itemName=}")
|
||||
typeProperties.append({
|
||||
'sqlName': itemName,
|
||||
'csName': itemName.capitalize()
|
||||
@ -150,7 +158,7 @@ for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items()
|
||||
'csName': typeName.capitalize(),
|
||||
'properties': typeProperties
|
||||
}
|
||||
#print(f"{types=}")
|
||||
print(f"{types=}")
|
||||
apiDefinition['types'] = types
|
||||
|
||||
print(json.dumps(apiDefinition, indent=4))
|
||||
|
Reference in New Issue
Block a user