Skip to content

Commit

Permalink
patch openapi-generator, format Quantity
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
fabiokung committed Oct 22, 2019
1 parent 5e33683 commit 1dacfc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
3 changes: 2 additions & 1 deletion openapi/java.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ popd > /dev/null
source "${SCRIPT_ROOT}/openapi-generator/client-generator.sh"
source "${SETTING_FILE}"

OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-v4.1.2}" \
OPENAPI_GENERATOR_USER_ORG="${OPENAPI_GENERATOR_USER_ORG:-fabiokung}" \
OPENAPI_GENERATOR_COMMIT="${OPENAPI_GENERATOR_COMMIT:-mapping-ref-string}" \
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}"
4 changes: 2 additions & 2 deletions openapi/java.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
<useRxJava>false</useRxJava>
<library>okhttp-gson</library>
<useReflectionEqualsHashCode>true</useReflectionEqualsHashCode>
<type-mappings>intstr.IntOrString=IntOrString,resource.Quantity=Quantity</type-mappings>
<import-mappings>IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity</import-mappings>
</configOptions>
<typeMappings>int-or-string=IntOrString,quantity=Quantity</typeMappings>
<importMappings>IntOrString=io.kubernetes.client.custom.IntOrString,Quantity=io.kubernetes.client.custom.Quantity</importMappings>
<output>${generator.output.path}</output>
</configuration>
</execution>
Expand Down
16 changes: 15 additions & 1 deletion openapi/preprocess_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1dacfc1

Please sign in to comment.