Skip to content

Instantly share code, notes, and snippets.

@toddlucas
Created April 1, 2019 19:03
Show Gist options
  • Save toddlucas/17aacbb472699ce4645626c79d1ee64c to your computer and use it in GitHub Desktop.
Save toddlucas/17aacbb472699ce4645626c79d1ee64c to your computer and use it in GitHub Desktop.
Takes a file generated by AspNetCore.RouteAnalyzer and converts to a CSV.
# Takes a file generated by AspNetCore.RouteAnalyzer and converts to a CSV.
# Note: you'll need to remove the RouteInformation prefix and quote the object
# keys to transform the output into legitimate JSON before using.
import sys
import json
import re
# MyController.Index(My.Namespace.Controllers.MyController.Index (My.AssemblyName))
invocationRegex = re.compile(r"(\w+)\.(\w+) \(([\w\.]+) \(([\w\.]+)\)\)")
with open('routes.json') as json_data:
objects = json.load(json_data)
for obj in objects:
area = obj['Area']
path = obj['Path'].split('/')[1:]
invocation = obj['Invocation']
m = invocationRegex.match(invocation)
if not m:
print("Could not parse invocation", file=sys.stderr)
exit(1)
controller = m.group(1)
action = m.group(2)
qualified = m.group(3)
assembly = m.group(4)
# Remove the ...Controller.Action at the end.
namespace = '.'.join(qualified.split('.')[:-2])
result = [namespace, area, controller, action]
result.extend(path)
line = ','.join(result)
print(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment