fix converter item, fix datetime handling, fix parsing of markdown description
This commit is contained in:
@ -59,7 +59,7 @@ namespace com.krohne.genericdatabaseapiservice.Services {
|
|||||||
|
|
||||||
public string GetInfoStringByTag(string tag) {
|
public string GetInfoStringByTag(string tag) {
|
||||||
return String.Format(
|
return String.Format(
|
||||||
"Server={0};User ID={1};Password={2};Database={3}",
|
"Server={0};User ID={1};Password={2};Database={3};Convert Zero Datetime=true",
|
||||||
GetInfoByTag(tag).Host,
|
GetInfoByTag(tag).Host,
|
||||||
GetInfoByTag(tag).User,
|
GetInfoByTag(tag).User,
|
||||||
GetInfoByTag(tag).Password,
|
GetInfoByTag(tag).Password,
|
||||||
|
32
generate.py
32
generate.py
@ -68,20 +68,21 @@ apiDefinition["env"] = {
|
|||||||
"packagename": os.environ["PACKAGE_NAME"],
|
"packagename": os.environ["PACKAGE_NAME"],
|
||||||
"routeprefix": os.environ["ROUTE_PREFIX"]
|
"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 = {
|
statementChecker = {
|
||||||
'get': re.compile('^select', re.IGNORECASE),
|
'get': re.compile('^select', re.IGNORECASE),
|
||||||
'put': re.compile('^update', re.IGNORECASE),
|
'put': re.compile('^update', re.IGNORECASE),
|
||||||
'delete': re.compile('^delete', re.IGNORECASE),
|
'delete': re.compile('^delete', re.IGNORECASE),
|
||||||
'post': re.compile('^insert', 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 = []
|
operations = []
|
||||||
for path in apiDefinition['paths'].values():
|
for path in apiDefinition['paths'].values():
|
||||||
for (method, operation) in path.items():
|
for (method, operation) in path.items():
|
||||||
#print(f"{method=}")
|
print(f"{method=}")
|
||||||
#print(f"{CsOperationNameConverter(operation['operationId'])=}")
|
print(f"{CsOperationNameConverter(operation['operationId'])=}")
|
||||||
# if 200 in
|
# if 200 in
|
||||||
content = operation['responses'][200]['content']['application/json']['schema']
|
content = operation['responses'][200]['content']['application/json']['schema']
|
||||||
if ('type' in content) and (content['type'] == 'array'):
|
if ('type' in content) and (content['type'] == 'array'):
|
||||||
@ -90,20 +91,27 @@ for path in apiDefinition['paths'].values():
|
|||||||
else:
|
else:
|
||||||
isList = False
|
isList = False
|
||||||
resultType = OpenApiExtractRefType(content['$ref'])
|
resultType = OpenApiExtractRefType(content['$ref'])
|
||||||
#print(f"{content=}")
|
print(f"{content=}")
|
||||||
#print(f"{resultType=}")
|
print(f"{resultType=}")
|
||||||
description = None
|
description = None
|
||||||
statement = None
|
statement = None
|
||||||
if 'description' in operation:
|
if 'description' in operation:
|
||||||
description = operation['description']
|
description = operation['description']
|
||||||
|
print(f"{description=}")
|
||||||
statementFinderResult = statementFinder.search(description)
|
statementFinderResult = statementFinder.search(description)
|
||||||
if statementFinderResult:
|
if statementFinderResult:
|
||||||
statement = statementFinderResult.group(1)
|
statement = statementCleaner.sub(' ', statementFinderResult.group(2))
|
||||||
|
print(f"{statement=}")
|
||||||
if not statementChecker[method].match(statement):
|
if not statementChecker[method].match(statement):
|
||||||
raise Exception(f"Invalid statement {statement} for method {method}")
|
raise Exception(f"Invalid statement {statement} for method {method}")
|
||||||
|
else:
|
||||||
|
print("no statement")
|
||||||
databaseTagFinderResult = databaseTagFinder.search(description)
|
databaseTagFinderResult = databaseTagFinder.search(description)
|
||||||
if databaseTagFinderResult:
|
if databaseTagFinderResult:
|
||||||
databaseTag = databaseTagFinderResult.group(1)
|
databaseTag = databaseTagFinderResult.group(2)
|
||||||
|
print(f"{databaseTag=}")
|
||||||
|
else:
|
||||||
|
print("no databasetag")
|
||||||
|
|
||||||
bodyInputType = {}
|
bodyInputType = {}
|
||||||
if 'requestBody' in operation:
|
if 'requestBody' in operation:
|
||||||
@ -132,15 +140,15 @@ for path in apiDefinition['paths'].values():
|
|||||||
'bodyInputType': bodyInputType,
|
'bodyInputType': bodyInputType,
|
||||||
'paramInputTypes': paramInputTypes
|
'paramInputTypes': paramInputTypes
|
||||||
})
|
})
|
||||||
#print(f"{operations=}")
|
print(f"{operations=}")
|
||||||
apiDefinition["operations"] = operations
|
apiDefinition["operations"] = operations
|
||||||
|
|
||||||
types = {}
|
types = {}
|
||||||
for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items():
|
for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items():
|
||||||
#print(f"{typeName=}")
|
print(f"{typeName=}")
|
||||||
typeProperties = []
|
typeProperties = []
|
||||||
for itemName in typeDefinition['properties']:
|
for itemName in typeDefinition['properties']:
|
||||||
#print(f"{itemName=}")
|
print(f"{itemName=}")
|
||||||
typeProperties.append({
|
typeProperties.append({
|
||||||
'sqlName': itemName,
|
'sqlName': itemName,
|
||||||
'csName': itemName.capitalize()
|
'csName': itemName.capitalize()
|
||||||
@ -150,7 +158,7 @@ for (typeName, typeDefinition) in apiDefinition['components']['schemas'].items()
|
|||||||
'csName': typeName.capitalize(),
|
'csName': typeName.capitalize(),
|
||||||
'properties': typeProperties
|
'properties': typeProperties
|
||||||
}
|
}
|
||||||
#print(f"{types=}")
|
print(f"{types=}")
|
||||||
apiDefinition['types'] = types
|
apiDefinition['types'] = types
|
||||||
|
|
||||||
print(json.dumps(apiDefinition, indent=4))
|
print(json.dumps(apiDefinition, indent=4))
|
||||||
|
24
openapi.yaml
24
openapi.yaml
@ -4,11 +4,7 @@ info:
|
|||||||
title: Generic Database API Service
|
title: Generic Database API Service
|
||||||
version: "2.0.0"
|
version: "2.0.0"
|
||||||
|
|
||||||
|
|
||||||
paths:
|
paths:
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
# --- baseItem -------------------------------------------------------------------------------------
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
/pdb/v2/baseItem/{articleNumber}:
|
/pdb/v2/baseItem/{articleNumber}:
|
||||||
get:
|
get:
|
||||||
tags: [ "Regular" ]
|
tags: [ "Regular" ]
|
||||||
@ -46,10 +42,6 @@ paths:
|
|||||||
$ref: "#/components/responses/clientSideError"
|
$ref: "#/components/responses/clientSideError"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/serverSideError"
|
$ref: "#/components/responses/serverSideError"
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
# --- productionOrderItem --------------------------------------------------------------------------
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
/pdb/v2/productionOrderItem/{productionOrder}:
|
/pdb/v2/productionOrderItem/{productionOrder}:
|
||||||
get:
|
get:
|
||||||
tags: [ "Regular" ]
|
tags: [ "Regular" ]
|
||||||
@ -93,10 +85,6 @@ paths:
|
|||||||
$ref: "#/components/responses/clientSideError"
|
$ref: "#/components/responses/clientSideError"
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/serverSideError"
|
$ref: "#/components/responses/serverSideError"
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
# --- converterItem --------------------------------------------------------------------------------
|
|
||||||
# --------------------------------------------------------------------------------------------------
|
|
||||||
/pdb/v2/converterItem/{serialNumber}:
|
/pdb/v2/converterItem/{serialNumber}:
|
||||||
get:
|
get:
|
||||||
tags: [ "Regular" ]
|
tags: [ "Regular" ]
|
||||||
@ -129,9 +117,9 @@ paths:
|
|||||||
,(CASE WHEN ISNULL(anonyme_cg_geraete.Artikelcode) THEN (CASE WHEN auftraege.C_Nummer = \"\" THEN NULL ELSE auftraege.C_Nummer END) ELSE anonyme_cg_geraete.C_Nummer END) AS cgNumber
|
,(CASE WHEN ISNULL(anonyme_cg_geraete.Artikelcode) THEN (CASE WHEN auftraege.C_Nummer = \"\" THEN NULL ELSE auftraege.C_Nummer END) ELSE anonyme_cg_geraete.C_Nummer END) AS cgNumber
|
||||||
,(CASE WHEN ISNULL(ems.Seriennummer) THEN auftraege.IX ELSE ems.Equi_index END) AS bomIndex
|
,(CASE WHEN ISNULL(ems.Seriennummer) THEN auftraege.IX ELSE ems.Equi_index END) AS bomIndex
|
||||||
,(CASE WHEN ISNULL(ems.Seriennummer) THEN FALSE ELSE TRUE END) AS hasEmsUpdate
|
,(CASE WHEN ISNULL(ems.Seriennummer) THEN FALSE ELSE TRUE END) AS hasEmsUpdate
|
||||||
,FALSE AS is_testConverter
|
,FALSE AS isTestConverter
|
||||||
,geraete_daten.montagedatum AS initialTestDate
|
,geraete_daten.montagedatum AS initialTestDate
|
||||||
,(CASE WHEN geraete_daten.ergebnis_erstinbetriebnahme = \"PASS\" THEN TRUE ELSE FALSE END) AS intialTestResult
|
,(CASE WHEN geraete_daten.ergebnis_erstinbetriebnahme = \"PASS\" THEN TRUE ELSE FALSE END) AS initialTestResult
|
||||||
,geraete_daten.hv_test_datum AS hvTestDate
|
,geraete_daten.hv_test_datum AS hvTestDate
|
||||||
,(CASE WHEN geraete_daten.hv_test_ergebnis = \"PASS\" THEN TRUE ELSE FALSE END) AS hvTestResult
|
,(CASE WHEN geraete_daten.hv_test_ergebnis = \"PASS\" THEN TRUE ELSE FALSE END) AS hvTestResult
|
||||||
,geraete_daten.temp_test_datum AS temperatureTestDate
|
,geraete_daten.temp_test_datum AS temperatureTestDate
|
||||||
@ -148,20 +136,20 @@ paths:
|
|||||||
STATEMENTEND
|
STATEMENTEND
|
||||||
```
|
```
|
||||||
parameters:
|
parameters:
|
||||||
- name: productionOrder
|
- name: serialNumber
|
||||||
in: path
|
in: path
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: integer
|
type: integer
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Here are your productionOrderItem items
|
description: Here are your converterItem items
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/components/schemas/productionOrderItem"
|
$ref: "#/components/schemas/converterItem"
|
||||||
400:
|
400:
|
||||||
$ref: "#/components/responses/clientSideError"
|
$ref: "#/components/responses/clientSideError"
|
||||||
500:
|
500:
|
||||||
@ -301,7 +289,7 @@ components:
|
|||||||
hasEmsUpdate:
|
hasEmsUpdate:
|
||||||
type: boolean
|
type: boolean
|
||||||
nullable: true
|
nullable: true
|
||||||
testConverter:
|
isTestConverter:
|
||||||
type: boolean
|
type: boolean
|
||||||
nullable: true
|
nullable: true
|
||||||
initialTestDate:
|
initialTestDate:
|
||||||
|
Reference in New Issue
Block a user