Skip to content

Commit

Permalink
Fixes #3: --only-collection exports only first collection
Browse files Browse the repository at this point in the history
I have fixed this bug, but I do however think the whole current approach of the script is off. Currently it is trying to make a new collection for every single resource group, which seems a bit OTT. I work on multiple APIs and each one of those is its own collection, and not just each resource for a specific API.

With this PR, the  will merge all collections into one, and the name will just be whatever the name of the first resource is. I'd prefer to use the name form the first environment, as you've done so far with other parts, and I would like to see the whole script treat each import as one collection.

Let me know if I can help with any of that, or if I can improve this PR.
  • Loading branch information
Phil Sturgeon committed Nov 17, 2014
1 parent b356160 commit db851c3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
dist/*
build/
dist/
2 changes: 1 addition & 1 deletion MANIFEST
Expand Up @@ -2,6 +2,6 @@
setup.cfg
setup.py
apiary2postman/__init__.py
apiary2postman/apiary.py
apiary2postman/apiary2postman.py
apiary2postman/blueprint.py
apiary2postman/converter.py
61 changes: 46 additions & 15 deletions apiary2postman/converter.py
Expand Up @@ -3,29 +3,60 @@
from uuid import uuid4
from time import time

def write(json_data, out=stdout, only_collection=False, pretty=False):
result = dict()
json_obj = json.loads(json_data)

# Create the header
result['version'] = 1
result['collections'] = []
result['globals'] =[]
result['headerPresets'] =[]
def _buildCollectionResponse(apiary):
environment = createEnvironment(apiary)

# Create the collection
collections = parseResourceGroups(
apiary['resourceGroups'],
environment['values'],
True)

result = {
'id' : str(uuid4()),
'name' : apiary['name'],
'description' : apiary['description'],
'timestamp' : int(time()),
'remote_id' : 0,
'synced' : False,
'folders' : [],
'requests' : [],
}

for collection in collections:
result['folders'] += collection['folders']
result['requests'] += collection['requests']

return result

def _buildFullResponse(apiary):
# Create the Environment
result['environments'] = [ createEnvironment(json_obj) ]
environment = createEnvironment(apiary)

# Create the Header
result = {
'version' : 1,
'globals' : [],
'headerPresets' : [],
'environments' : [ environment ],
}

# Create the collection
result['collections'] = parseResourceGroups(
json_obj['resourceGroups'],
apiary['resourceGroups'],
result['environments'][0]['values'],
only_collection )
False)

return result

def write(json_data, out=stdout, only_collection=False, pretty=False):
json_obj = json.loads(json_data)

result_out = result
if only_collection:
result_out = result['collections'][0]

result_out = _buildCollectionResponse(json_obj)
else:
result_out = _buildFullResponse(json_obj)

if pretty:
json.dump(result_out, out, indent=2, separators=(',', ': '))
else:
Expand Down

0 comments on commit db851c3

Please sign in to comment.