Skip to content

Instantly share code, notes, and snippets.

@elliott-beach
Last active August 21, 2017 12:55
Show Gist options
  • Save elliott-beach/120a6f26c72c8d08f2895b933d1af8ab to your computer and use it in GitHub Desktop.
Save elliott-beach/120a6f26c72c8d08f2895b933d1af8ab to your computer and use it in GitHub Desktop.
Check for json api mismatch with field name
import sys
# Error-inducing lines didn't have anything interesting.
only_errs = False
def to_camel_case(snake_str):
components = snake_str.split('_')
return "".join(x.title() for x in components)
for line in sys.stdin:
elemns = line.split(' ')
elemns = filter(lambda x: x != '', elemns)
try:
fname, fieldname = elemns[0].split('\t')
fname = fname[2:]
json = elemns[2].split(',')[0].split('"')[1]
except IndexError as e:
if only_errs:
print 'index error:', line
continue
except ValueError as e:
if only_errs:
print 'value error:', line
continue
if not only_errs:
if fieldname.lower() != to_camel_case(json).lower():
print fname, fieldname, json
# Execute in 'src/go-github/github' with: rm *test.go; grep -P '^.*`json.*$' -r . | python parse.py'' | sort -u
@elliott-beach
Copy link
Author

Very dirty - just lmk if you would like to see something more readable 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment