Closed triStone closed 5 years ago
Hey @triStone - thanks so much for your bug report! I just got back from traveling, so I'm going to look into your issue this week. Real quick, could you tell me if this issue comes from version 0.1.9 (latest on PyPI)? or from the v0.2.0-dev
branch?
version 0.1.9
@triStone thanks!
ftr: I cannot reproduce this:
api.raml:
#%RAML 0.8
title: "blah"
version: "v1"
baseUri: https://{apiUri}/{version}
mediaType: application/json
protocols: [HTTPS]
traits:
- paging:
queryParameters:
page_size:
description: the amount of elements of each result page
type: integer
required: false
example: 10
page_no:
description: the page number
type: integer
required: false
example: 0
/items:
description: Returns items
get:
is: [ paging ]
responses:
200:
body:
application/json:
example: ["foo", "bar"]
test.py:
import ramlfications
api = ramlfications.parse('api.raml')
print("api", api)
Works just fine. Am I missing something?
Sorry, I haven't use this for a while, and cannot reproduce this bug now. Thank you for your kindly response.
I have been able to reproduce:
#%RAML 1.0
title: Example API
version: v1
resourceTypes:
collection:
usage: This resourceType should be used for any collection of items
description: The collection of <<resourcePathName>>
get:
description: Get all <<resourcePathName>>, optionally filtered
post:
description: Create a new <<resourcePathName | !singularize>>
traits:
secured:
usage: Apply this to any method that needs to be secured
description: Some requests require authentication.
headers:
access_token:
description: Access Token
example: 5757gh76
required: true
/csn:
get:
description: Hello world
In [14]: api = ramlfications.parse("a.raml")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-14-cd29d9e59fbb> in <module>()
----> 1 api = ramlfications.parse("a.raml")
~/.local/var/lib/virtualenvs/kyc-document-broker-etCozD1c/lib/python3.5/site-packages/ramlfications/__init__.py in parse(raml, config_file)
68 loader = load(raml)
69 config = setup_config(config_file)
---> 70 return parse_raml(loader, config)
71
72
~/.local/var/lib/virtualenvs/kyc-document-broker-etCozD1c/lib/python3.5/site-packages/ramlfications/parser.py in parse_raml(loaded_raml, config)
51
52 root.security_schemes = create_sec_schemes(root.raml_obj, root)
---> 53 root.traits = create_traits(root.raml_obj, root)
54 root.resource_types = create_resource_types(root.raml_obj, root)
55 root.resources = create_resources(root.raml_obj, [], root,
~/.local/var/lib/virtualenvs/kyc-document-broker-etCozD1c/lib/python3.5/site-packages/ramlfications/parser.py in create_traits(raml_data, root)
370 trait_objects = []
371 for trait in traits:
--> 372 name = list(iterkeys(trait))[0]
373 data = list(itervalues(trait))[0]
374 trait_objects.append(wrap(name, data))
~/.local/var/lib/virtualenvs/kyc-document-broker-etCozD1c/lib/python3.5/site-packages/six.py in iterkeys(d, **kw)
579 if PY3:
580 def iterkeys(d, **kw):
--> 581 return iter(d.keys(**kw))
582
583 def itervalues(d, **kw):
AttributeError: 'str' object has no attribute 'keys'
ramlfications 0.1.9
installed from pip
@roosemberth ramlfications
does not support RAML 1.0. But you might want to try making traits
a list of dictionaries rather than just a dictionary itself, e.g.
traits:
- secured:
usage: Apply this to any method that needs to be secured
description: Some requests require authentication.
headers:
access_token:
description: Access Token
example: 5757gh76
required: true
I have a trait file like below.
RAMLfications can not parse this raml file correctly. I've track the code in
parser.py
andvalidata.py
. And think these code inparser.py:371
should be changed toAnd the code in
validate.py:189
should be changed toBTW: My Python version is 3.5, and I haven't check if this bug existed in Python2