Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 56 additions & 28 deletions .generation/post-process/typescript.py
Original file line number Diff line number Diff line change
@@ -1,95 +1,123 @@
#!/bin/python3

'''
"""
Post-processing of generated code.
'''
"""

import sys
from pathlib import Path
from typing import Generator, List
from textwrap import dedent, indent
from util import modify_file, version

INDENT = ' '
INDENT = " "


def runtime_ts(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the runtime.ts file.'''
"""Modify the runtime.ts file."""
for line in file_contents:
if line.startswith('export const DefaultConfig ='):
line = dedent(f'''\
if line.startswith("export const DefaultConfig ="):
line = dedent(f"""\
export const DefaultConfig = new Configuration({{
headers: {{
'User-Agent': 'geoengine/openapi-client/typescript/{version()}'
}}
}});
''')
""")

yield line


# fixes due to https://github.com/OpenAPITools/openapi-generator/issues/14831
def plot_update_ts(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the PlotUpdate.ts file.'''
"""Modify the PlotUpdate.ts file."""
for line in file_contents:
dedented_line = dedent(line)

if dedented_line.startswith('if (instanceOfPlot(value))'):
line = indent(dedent('''\
if dedented_line.startswith("if (instanceOfPlot(value))"):
line = indent(
dedent("""\
if (typeof value === 'object' && instanceOfPlot(value)) {
'''), INDENT)
"""),
INDENT,
)

yield line


# fixes due to https://github.com/OpenAPITools/openapi-generator/issues/14831
def layer_update_ts(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the LayerUpdate.ts file.'''
"""Modify the LayerUpdate.ts file."""
for line in file_contents:
dedented_line = dedent(line)

if dedented_line.startswith('if (instanceOfProjectLayer(value))'):
line = indent(dedent('''\
if dedented_line.startswith("if (instanceOfProjectLayer(value))"):
line = indent(
dedent("""\
if (typeof value === 'object' && instanceOfProjectLayer(value)) {
'''), INDENT)
"""),
INDENT,
)

yield line


# Fix: interface cannot inherit union type
def task_status_with_id_ts(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the TaskStatusWithId.ts file.'''
"""Modify the TaskStatusWithId.ts file."""
for line in file_contents:
dedented_line = dedent(line)

if dedented_line.startswith('export interface TaskStatusWithId extends TaskStatus'):
line = dedent('''\
if dedented_line.startswith(
"export interface TaskStatusWithId extends TaskStatus"
):
line = dedent("""\
export type TaskStatusWithId = { taskId: string } & TaskStatus;

export interface _TaskStatusWithId /* extends TaskStatus */ {
''')
""")

yield line


def vec_update_ts(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the VecUpdate.ts file.'''
"""Modify the VecUpdate.ts file."""
for line in file_contents:
dedented_line = dedent(line)

if dedented_line.startswith('if (instanceOfPlot(value)) {'):
line = indent("if (typeof value === 'object' && instanceOfPlot(value)) {\n", INDENT)
if dedented_line.startswith("if (instanceOfPlot(value)) {"):
line = indent(
"if (typeof value === 'object' && instanceOfPlot(value)) {\n", INDENT
)

yield line


def ogcwfsapi_ts(file_contents: List[str]) -> Generator[str, None, None]:
"""Modify the OGCWFSApi.ts file."""
for line in file_contents:
dedented_line = dedent(line)

if dedented_line.startswith("path: `/wfs/{workflow}?request=GetFeature`"):
line = line.replace("?request=GetFeature", "")
elif dedented_line.startswith("path: `/wfs/{workflow}?request=GetCapabilities"):
line = line.replace("?request=GetCapabilities", "")
yield line


input_file = Path(sys.argv[1])

file_modifications = {
'LayerUpdate.ts': layer_update_ts,
'PlotUpdate.ts': plot_update_ts,
'runtime.ts': runtime_ts,
'TaskStatusWithId.ts': task_status_with_id_ts,
'VecUpdate.ts': vec_update_ts,
"LayerUpdate.ts": layer_update_ts,
"OGCWFSApi.ts": ogcwfsapi_ts,
"PlotUpdate.ts": plot_update_ts,
"runtime.ts": runtime_ts,
"TaskStatusWithId.ts": task_status_with_id_ts,
"VecUpdate.ts": vec_update_ts,
}
if modifier_function := file_modifications.get(input_file.name):
modify_file(input_file, modifier_function)
else:
pass # leave file untouched
pass # leave file untouched

exit(0)
4 changes: 2 additions & 2 deletions typescript/dist/apis/OGCWFSApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = yield this.request({
path: `/wfs/{workflow}?request=GetCapabilities`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down Expand Up @@ -150,7 +150,7 @@ class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = yield this.request({
path: `/wfs/{workflow}?request=GetFeature`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down
4 changes: 2 additions & 2 deletions typescript/dist/esm/apis/OGCWFSApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = yield this.request({
path: `/wfs/{workflow}?request=GetCapabilities`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down Expand Up @@ -147,7 +147,7 @@ export class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = yield this.request({
path: `/wfs/{workflow}?request=GetFeature`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down
4 changes: 2 additions & 2 deletions typescript/src/apis/OGCWFSApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = await this.request({
path: `/wfs/{workflow}?request=GetCapabilities`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))).replace(`{${"version"}}`, encodeURIComponent(String(requestParameters['version']))).replace(`{${"service"}}`, encodeURIComponent(String(requestParameters['service']))).replace(`{${"request"}}`, encodeURIComponent(String(requestParameters['request']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down Expand Up @@ -238,7 +238,7 @@ export class OGCWFSApi extends runtime.BaseAPI {
}
}
const response = await this.request({
path: `/wfs/{workflow}?request=GetFeature`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
path: `/wfs/{workflow}`.replace(`{${"workflow"}}`, encodeURIComponent(String(requestParameters['workflow']))),
method: 'GET',
headers: headerParameters,
query: queryParameters,
Expand Down