From 7120c2a8942a97fa91896405b46b68e254fade4f Mon Sep 17 00:00:00 2001 From: yue9944882 <291271447@qq.com> Date: Wed, 29 May 2019 16:08:57 +0800 Subject: [PATCH] migrate java clients from swagger-codegen to openapi-generator add reflection-equality config option java: update openapi generator to 4.1.2 patch openapi-generator, format Quantity Bring in a patched openapi-generator temporarily until openapi-generator#4182 gets merged, and add a format to resource.Quantity so it can have a custom typeMapping installed. Also bring configuration of type and import mappings to the correct (newer) format for the maven plugin. remove the overrides refactor --- openapi/java.sh | 4 ++-- openapi/java.xml | 25 ++++++++++++------------- openapi/preprocess_spec.py | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/openapi/java.sh b/openapi/java.sh index ede8b41..3d50f23 100755 --- a/openapi/java.sh +++ b/openapi/java.sh @@ -46,10 +46,10 @@ pushd "${OUTPUT_DIR}" > /dev/null OUTPUT_DIR=`pwd` popd > /dev/null -source "${SCRIPT_ROOT}/swagger-codegen/client-generator.sh" +source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh" source "${SETTING_FILE}" -SWAGGER_CODEGEN_COMMIT="${SWAGGER_CODEGEN_COMMIT:-5d263e1c9cdd395d93adf061c63d5ef58a8e9ec5}"; \ +OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v4.2.0}" \ CLIENT_LANGUAGE=java; \ CLEANUP_DIRS=(docs src/test/java/io/kubernetes/client/apis src/main/java/io/kubernetes/client/apis src/main/java/io/kubernetes/client/models src/main/java/io/kubernetes/client/auth gradle); \ kubeclient::generator::generate_client "${OUTPUT_DIR}" diff --git a/openapi/java.xml b/openapi/java.xml index 7916be9..5290948 100644 --- a/openapi/java.xml +++ b/openapi/java.xml @@ -1,5 +1,5 @@ - 4.0.0 io.kubernetes @@ -10,9 +10,9 @@ - io.swagger - swagger-codegen-maven-plugin - ${swagger-codegen-version} + org.openapitools + openapi-generator-maven-plugin + ${openapi-generator-version} @@ -23,6 +23,7 @@ java kubernetes-client client-java + true kubernetes-java-client Java client for Kubernetes. @@ -37,7 +38,6 @@ client-java 1.0-SNAPSHOT src/main/java - false false false @@ -45,10 +45,9 @@ joda false okhttp-gson - intstr.IntOrString=IntOrString,resource.Quantity=Quantity - - IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity,V1Patch=io.kubernetes.client.custom.V1Patch - + int-or-string=IntOrString,quantity=Quantity + IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity + true ${generator.output.path} @@ -65,9 +64,9 @@ ${swagger-annotations-version} - io.swagger - swagger-codegen-maven-plugin - 2.2.2 + org.openapitools + openapi-generator-maven-plugin + ${openapi-generator-version} diff --git a/openapi/preprocess_spec.py b/openapi/preprocess_spec.py index 08ae4fd..5e84c09 100644 --- a/openapi/preprocess_spec.py +++ b/openapi/preprocess_spec.py @@ -14,11 +14,11 @@ from __future__ import print_function +import argparse import json import operator import os.path import sys -import argparse from collections import OrderedDict import urllib3 @@ -136,6 +136,8 @@ def process_swagger(spec, client_language): inline_primitive_models(spec, preserved_primitives_for_language(client_language)) + add_custom_formatting(spec, format_for_language(client_language)) + remove_models(spec, removed_models_for_language(client_language)) return spec @@ -150,6 +152,12 @@ def preserved_primitives_for_language(client_language): else: return [] +def format_for_language(client_language): + if client_language == "java": + return {"resource.Quantity": "quantity"} + else: + return {} + def removed_models_for_language(client_language): if client_language == "haskell-http-client": return ["intstr.IntOrString", "resource.Quantity"] @@ -298,6 +306,12 @@ def inline_primitive_models(spec, excluded_primitives): for k in to_remove_models: del spec['definitions'][k] +def add_custom_formatting(spec, custom_formats): + for k, v in spec['definitions'].items(): + if k not in custom_formats: + continue + v["format"] = custom_formats[k] + def write_json(filename, object): with open(filename, 'w') as out: json.dump(object, out, sort_keys=False, indent=2, separators=(',', ': '), ensure_ascii=True)