-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for IntOrString in Java #30
Merged
mbohlool
merged 5 commits into
kubernetes-client:master
from
lewisheadden:IntOrStringSupport
Nov 3, 2017
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ def add_custom_objects_spec(spec): | |
return spec | ||
|
||
|
||
def process_swagger(spec): | ||
def process_swagger(spec, client_language): | ||
spec = add_custom_objects_spec(spec) | ||
|
||
apply_func_to_spec_operations(spec, strip_tags_from_operation_id) | ||
|
@@ -127,10 +127,15 @@ def process_swagger(spec): | |
|
||
remove_model_prefixes(spec) | ||
|
||
inline_primitive_models(spec) | ||
inline_primitive_models(spec, preserved_primitives_for_language(client_language)) | ||
|
||
return spec | ||
|
||
def preserved_primitives_for_language(client_language): | ||
if client_language == "java": | ||
return ["intstr.IntOrString"] | ||
else: | ||
return [] | ||
|
||
def rename_model(spec, old_name, new_name): | ||
if new_name in spec['definitions']: | ||
|
@@ -180,7 +185,7 @@ def remove_deprecated_models(spec): | |
models = {} | ||
for k, v in spec['definitions'].items(): | ||
if is_model_deprecated(v): | ||
print("Removing deprecated model %s" %k) | ||
print("Removing deprecated model %s" % k) | ||
else: | ||
models[k] = v | ||
spec['definitions'] = models | ||
|
@@ -252,41 +257,48 @@ def find_replace_ref_recursive(root, ref_name, replace_map): | |
find_replace_ref_recursive(v, ref_name, replace_map) | ||
|
||
|
||
def inline_primitive_models(spec): | ||
def inline_primitive_models(spec, excluded_primitives): | ||
to_remove_models = [] | ||
for k, v in spec['definitions'].items(): | ||
if "properties" not in v: | ||
if k == "intstr.IntOrString": | ||
v["type"] = "object" | ||
if "type" not in v: | ||
v["type"] = "object" | ||
print("Making model `%s` inline as %s..." % (k, v["type"])) | ||
find_replace_ref_recursive(spec, "#/definitions/" + k, v) | ||
to_remove_models.append(k) | ||
if k not in excluded_primitives: | ||
if "properties" not in v: | ||
if k == "intstr.IntOrString": | ||
v["type"] = "object" | ||
if "type" not in v: | ||
v["type"] = "object" | ||
print("Making model `%s` inline as %s..." % (k, v["type"])) | ||
find_replace_ref_recursive(spec, "#/definitions/" + k, v) | ||
to_remove_models.append(k) | ||
|
||
for k in to_remove_models: | ||
del spec['definitions'][k] | ||
|
||
def write_json(filename, object): | ||
with open(filename, 'w') as out: | ||
json.dump(object, out, sort_keys=False, indent=2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I don't really love this line breaking, can you get it all on one line? |
||
separators=(',', ': '), ensure_ascii=True) | ||
|
||
|
||
|
||
def main(): | ||
if len(sys.argv) != 3: | ||
print("Usage:\n\n\tpython preprocess_spec.py kuberneres_branch " \ | ||
if len(sys.argv) != 4: | ||
print("Usage:\n\n\tpython preprocess_spec.py client_language kuberneres_branch " \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may as well fix the 'kuberneres_branch' typo while you're in here... |
||
"output_spec_path") | ||
return 1 | ||
client_language = sys.argv[1] | ||
spec_url = 'https://raw.githubusercontent.com/kubernetes/kubernetes/' \ | ||
'%s/api/openapi-spec/swagger.json' % sys.argv[1] | ||
output_path = sys.argv[2] | ||
'%s/api/openapi-spec/swagger.json' % sys.argv[2] | ||
output_path = sys.argv[3] | ||
|
||
pool = urllib3.PoolManager() | ||
with pool.request('GET', spec_url, preload_content=False) as response: | ||
if response.status != 200: | ||
print("Error downloading spec file. Reason: %s" % response.reason) | ||
return 1 | ||
in_spec = json.load(response, object_pairs_hook=OrderedDict) | ||
out_spec = process_swagger(in_spec) | ||
with open(output_path, 'w') as out: | ||
json.dump(out_spec, out, sort_keys=False, indent=2, | ||
separators=(',', ': '), ensure_ascii=True) | ||
write_json(output_path + ".unprocessed", in_spec) | ||
out_spec = process_swagger(in_spec, client_language) | ||
write_json(output_path, out_spec) | ||
return 0 | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think I'd prefer