From 9701a7c9ae41c489c1839a10069e6b0c79803d72 Mon Sep 17 00:00:00 2001 From: "Dr. Stefan Schimanski" Date: Mon, 24 Jul 2023 18:58:15 +0200 Subject: [PATCH] openapi/preprocess_spec.py: expand globally shared parameters (#245) --- openapi/preprocess_spec.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/openapi/preprocess_spec.py b/openapi/preprocess_spec.py index ade8546..1cc815f 100644 --- a/openapi/preprocess_spec.py +++ b/openapi/preprocess_spec.py @@ -180,6 +180,26 @@ def drop_paths(spec): print("Ignoring non Custom Resource api path %s" %k) spec['paths'] = paths +def expand_parameters(spec): + if 'parameters' not in spec: + return + for path in spec['paths'].keys(): + if 'parameters' in spec['paths'][path]: + for i in range(len(spec['paths'][path]['parameters'])): + param = spec['paths'][path]['parameters'][i] + if '$ref' in param: + ref = param['$ref'] + param = spec['parameters'][ref.split('/')[-1]] + spec['paths'][path]['parameters'][i] = param + for method in spec['paths'][path].keys(): + if 'parameters' in spec['paths'][path][method]: + for i in range(len(spec['paths'][path][method]['parameters'])): + param = spec['paths'][path][method]['parameters'][i] + if '$ref' in param: + ref = param['$ref'] + param = spec['parameters'][ref.split('/')[-1]] + spec['paths'][path][method]['parameters'][i] = param + del spec['parameters'] def process_swagger(spec, client_language, crd_mode=False): spec = add_custom_objects_spec(spec) @@ -187,6 +207,8 @@ def process_swagger(spec, client_language, crd_mode=False): if crd_mode: drop_paths(spec) + expand_parameters(spec) + apply_func_to_spec_operations(spec, strip_tags_from_operation_id) if client_language == "csharp":