Skip to content
Prev Previous commit
Next Next commit
add postprocessing
  • Loading branch information
jdroenner committed Aug 11, 2025
commit bcce9daf1674eae3a7577e59282b2e30f596fcf7
27 changes: 18 additions & 9 deletions .generation/post-process/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
INDENT = ' '
HALF_INDENT = ' '


def api_client_py(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the api_client.py file.'''
for line in file_contents:
Expand All @@ -25,6 +26,7 @@ def api_client_py(file_contents: List[str]) -> Generator[str, None, None]:

yield line


def exceptions_py(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the exceptions.py file.'''
for line in file_contents:
Expand All @@ -39,6 +41,7 @@ def exceptions_py(file_contents: List[str]) -> Generator[str, None, None]:

yield line


def task_status_with_id_py(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the task_status_with_id.py file.'''
for line in file_contents:
Expand Down Expand Up @@ -73,12 +76,14 @@ def task_status_with_id_py(file_contents: List[str]) -> Generator[str, None, Non

yield line


EARLY_RETURN_EMPTY_HTTP_RESPONSE = indent(dedent('''\
# Note: fixed handling of empty responses
if response_data.data is None:
return None
'''), 2 * INDENT)


def tasks_api_py(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the tasks_api.py file.'''
state: Literal[None, 'abort_handler'] = None
Expand All @@ -88,12 +93,13 @@ def tasks_api_py(file_contents: List[str]) -> Generator[str, None, None]:
state = 'abort_handler'

elif state == 'abort_handler' and \
dedented_line.startswith('return self.api_client.response_deserialize('):
dedented_line.startswith('return self.api_client.response_deserialize('):
line = EARLY_RETURN_EMPTY_HTTP_RESPONSE + '\n' + line
state = None

yield line


def layers_api_py(file_contents: List[str]) -> Generator[str, None, None]:
'''Modify the tasks_api.py file.'''
state: Literal[
Expand All @@ -105,7 +111,8 @@ def layers_api_py(file_contents: List[str]) -> Generator[str, None, None]:
if state is None and (
dedented_line.startswith('def add_existing_layer_to_collection(')
or
dedented_line.startswith('def add_existing_collection_to_collection(')
dedented_line.startswith(
'def add_existing_collection_to_collection(')
or
dedented_line.startswith('def remove_collection_from_collection(')
or
Expand All @@ -116,12 +123,13 @@ def layers_api_py(file_contents: List[str]) -> Generator[str, None, None]:
state = 'add_early_return_empty_http_response'

elif state == 'add_early_return_empty_http_response' and \
dedented_line.startswith('return self.api_client.response_deserialize('):
dedented_line.startswith('return self.api_client.response_deserialize('):
line = EARLY_RETURN_EMPTY_HTTP_RESPONSE + '\n' + line
state = None

yield line


def ogc_xyz_api_py(ogc_api: Literal['wfs', 'wms']) -> Callable[[List[str]], Generator[str, None, None]]:
'''Modify the ogc_xyz_api.py file.'''
def _ogc_xyz_api_py(file_contents: List[str]) -> Generator[str, None, None]:
Expand All @@ -141,7 +149,7 @@ def _ogc_xyz_api_py(file_contents: List[str]) -> Generator[str, None, None]:
def raster_result_descriptor_py(file_contents: List[str]) -> Generator[str, None, None]:
'''
Modify the raster_result_descriptor.py file.

TODO: remove when bug is fixed:
https://github.com/OpenAPITools/openapi-generator/issues/19926
'''
Expand All @@ -161,9 +169,8 @@ def raster_result_descriptor_py(file_contents: List[str]) -> Generator[str, None

_obj = cls.model_validate({
"bands": [RasterBandDescriptor.from_dict(_item) for _item in obj["bands"]] if obj.get("bands") is not None else None,
"bbox": SpatialPartition2D.from_dict(obj["bbox"]) if obj.get("bbox") is not None else None,
"spatialGrid": SpatialGridDescriptor.from_dict(obj["spatialGrid"]) if obj.get("spatialGrid") is not None else None,
"dataType": obj.get("dataType"),
"resolution": SpatialResolution.from_dict(obj["resolution"]) if obj.get("resolution") is not None else None,
"spatialReference": obj.get("spatialReference"),
"time": TimeInterval.from_dict(obj["time"]) if obj.get("time") is not None else None,
})
Expand All @@ -172,10 +179,11 @@ def raster_result_descriptor_py(file_contents: List[str]) -> Generator[str, None

yield line


def vector_result_descriptor_py(file_contents: List[str]) -> Generator[str, None, None]:
'''
Modify the vector_result_descriptor.py file.

TODO: remove when bug is fixed:
https://github.com/OpenAPITools/openapi-generator/issues/19926
'''
Expand Down Expand Up @@ -214,7 +222,7 @@ def vector_result_descriptor_py(file_contents: List[str]) -> Generator[str, None
def plot_result_descriptor_py(file_contents: List[str]) -> Generator[str, None, None]:
'''
Modify the plot_result_descriptor.py file.

TODO: remove when bug is fixed:
https://github.com/OpenAPITools/openapi-generator/issues/19926
'''
Expand Down Expand Up @@ -242,6 +250,7 @@ def plot_result_descriptor_py(file_contents: List[str]) -> Generator[str, None,

yield line


input_file = Path(sys.argv[1])

file_modifications = {
Expand All @@ -260,6 +269,6 @@ def plot_result_descriptor_py(file_contents: List[str]) -> Generator[str, None,
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)