Skip to content

Commit

Permalink
Added first pass at Content-Type processing from openapi data
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Dec 14, 2023
1 parent d141d87 commit d7ca6d1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
21 changes: 20 additions & 1 deletion CloudFlare/api_decode_from_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,26 @@ def do_path(cmd, values):
deprecated = False
deprecated_date = ''
deprecated_already = False
v = {'action': action.upper(), 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already}

# The requestBody/content could be one of the following:
# "requestBody": {
# "content": {
# "application/javascript" {
# "application/json" {
# "application/octet-stream" {
# "application/x-ndjson" {
# "multipart/form-data" {

content_type = None
if 'requestBody' in values[action] and values[action]['requestBody']:
request_body = values[action]['requestBody']
if 'content' in request_body and request_body['content']:
content_type = ','.join(list(request_body['content'].keys()))

if content_type:
v = {'action': action.upper(), 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already, 'content_type': content_type}
else:
v = {'action': action.upper(), 'cmd': cmd, 'deprecated': deprecated, 'deprecated_date': deprecated_date, 'deprecated_already': deprecated_already}
cmds.append(v)
return cmds

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ lint:
openapi:
@tmp=/tmp/_$$$$_ ; \
$(PYTHON) -m cli4 --dump | sort > $$tmp.1 ; \
$(PYTHON) -m cli4 --openapi $(OPENAPI_URL) | sed -e 's/^[A-Z][A-Z]* *//' -e 's/?.*//' -e 's/\/:[a-z][A-Za-z_]*/\/:id/g' -e 's/\/:[a-z][A-Za-z_]*}/\/:id/g' -e 's/:id\/:id/:id/' -e 's/\/:id$$//' -e 's/\/:id$$//' -e 's/\/:id ;/ ;/' -e 's/\/$$//' | sort -u > $$tmp.2 ; \
egrep -v '; deprecated' < $$tmp.2 | diff $$tmp.1 - > $$tmp.3 ; \
$(PYTHON) -m cli4 --openapi $(OPENAPI_URL) | sed -e 's/^[A-Z][A-Z]* *//' -e 's/?.*//' -e 's/\/:[a-z][A-Za-z_]*/\/:id/g' -e 's/\/:[a-z][A-Za-z_]*}/\/:id/g' -e 's/:id\/:id/:id/' -e 's/\/:id$$//' -e 's/\/:id$$//' -e 's/\/:id ;/ ;/' -e 's/ ; Content-Type: .*//' -e 's/\/$$//' | sort -u > $$tmp.2 ; \
egrep -v '; deprecated' < $$tmp.2 | sed -e 's/ ; .*//' | diff $$tmp.1 - > $$tmp.3 ; \
echo "In code:" ; \
egrep '< ' < $$tmp.3 | sed -e 's/< / /' | sort | tee $$tmp.4 ; \
echo "In docs:" ; \
Expand Down
5 changes: 4 additions & 1 deletion cli4/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def dump_commands_from_web(cf, url):
else:
a.append('%-6s %s ; deprecated %s' % (r['action'], r['cmd'], r['deprecated_date']))
else:
a.append('%-6s %s' % (r['action'], r['cmd']))
if 'content_type' in r and r['content_type']:
a.append('%-6s %s ; Content-Type: %s' % (r['action'], r['cmd'], r['content_type']))
else:
a.append('%-6s %s' % (r['action'], r['cmd']))
return '\n'.join(a) + '\n'


0 comments on commit d7ca6d1

Please sign in to comment.