Last active
August 21, 2017 12:55
-
-
Save elliott-beach/120a6f26c72c8d08f2895b933d1af8ab to your computer and use it in GitHub Desktop.
Check for json api mismatch with field name
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very dirty - just lmk if you would like to see something more readable 😄