From 1ae5a04c0bc0284c49b64eb69b6c59e7e747e26a Mon Sep 17 00:00:00 2001 From: Boshi Lian Date: Wed, 28 Oct 2020 09:47:57 -0700 Subject: [PATCH] fix csharp generator missing model (#172) * fix csharp missing object * add stream --- openapi/csharp.xml | 1 - openapi/preprocess_spec.py | 22 ++++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/openapi/csharp.xml b/openapi/csharp.xml index a79cf32..d2684a3 100644 --- a/openapi/csharp.xml +++ b/openapi/csharp.xml @@ -33,7 +33,6 @@ --max-old-space-size=8192 /usr/bin/autorest - /output_dir/config.yaml --input-file=${generator.spec.path} --csharp --namespace=${generator.package.name} diff --git a/openapi/preprocess_spec.py b/openapi/preprocess_spec.py index d047d37..d081cd6 100644 --- a/openapi/preprocess_spec.py +++ b/openapi/preprocess_spec.py @@ -117,6 +117,15 @@ def strip_401_response(operation, _): if len(operation['responses']) == 0: operation['responses']['200'] = { 'description': 'OK' } + +def transform_to_csharp_stream_response(operation, _): + if operation.get('operationId', None) == 'readNamespacedPodLog' or operation.get('x-kubernetes-action', None) == 'connect': + operation['responses']['200']["schema"] = { + "type": "object", + "format": "file" , + } + + def strip_tags_from_operation_id(operation, _): operation_id = operation['operationId'] if 'tags' in operation: @@ -163,6 +172,9 @@ def process_swagger(spec, client_language, crd_mode=False): # 401s in the spec block the csharp code generator from throwing on 401 apply_func_to_spec_operations(spec, strip_401_response) + # force to autorest to generate stream + apply_func_to_spec_operations(spec, transform_to_csharp_stream_response) + apply_func_to_spec_operations(spec, strip_delete_collection_operation_watch_params) apply_func_to_spec_operations(spec, add_codegen_request_body) @@ -214,7 +226,13 @@ def format_for_language(client_language): def type_for_language(client_language): if client_language == "java": - return {"v1.Patch": "string"} + return {"v1.Patch": { "type": "string"}} + elif client_language == "csharp": + return { + "v1.Patch": { "type": "object", "properties": {"content": { "type": "object"}} }, + "resource.Quantity": { "type": "object", "properties": {"value": { "type": "string"}} }, + "intstr.IntOrString" : { "type": "object", "properties": {"value": { "type": "string"}} }, + } else: return {} @@ -389,7 +407,7 @@ def add_custom_typing(spec, custom_types): for k, v in spec['definitions'].items(): if k not in custom_types: continue - v["type"] = custom_types[k] + v.update(custom_types[k]) def add_openapi_codegen_x_implement_extension(spec, client_language): if client_language != "java":