jdiegodcp / ramlfications

Python parser for RAML
https://ramlfications.readthedocs.org
Apache License 2.0
234 stars 49 forks source link

validation raises a TypeError under Python 3 #53

Closed lelit closed 8 years ago

lelit commented 9 years ago

Line 199 of validate.py is not compatible with Python 3:

$ ramlfications validate Products.raml
Traceback (most recent call last):
  File "/usr/local/bin/ramlfications", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.5/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/__main__.py", line 30, in validate
    vvalidate(ramlfile, config)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/__init__.py", line 98, in validate
    parse_raml(loader, config)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/parser.py", line 49, in parse_raml
    parent=None)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/parser.py", line 821, in create_resources
    root=root)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/parser.py", line 1305, in create_node
    errors=root.errors
  File "<attrs generated init 43f90bc3d742f347d17b69205878e20748db828b>", line 27, in __init__
  File "/usr/local/lib/python3.5/site-packages/attr/_make.py", line 395, in validate
    a.validator(inst, a, getattr(inst, a.name))
  File "/usr/local/lib/python3.5/site-packages/ramlfications/_decorators.py", line 7, in func_wrapper
    func(inst, attr, value)
  File "/usr/local/lib/python3.5/site-packages/ramlfications/validate.py", line 199, in assigned_traits
    if not isinstance(v.keys()[0], str):  # NOCOV
TypeError: 'odict_keys' object does not support indexing

Python 3.4 raises the same error.

econchick commented 9 years ago

Thanks @lelit - are you able to share your RAML file by chance?

lelit commented 9 years ago

Sure, here a minimal RAML that exhibits the problem (inline, as GH did not allow me to attach it... let me know if that's a problem):

#%RAML 0.8
---
title: Test
baseUri: http://customer.example.com/

traits:
  - orderable:
      queryParameters:
        sort:
          description: |
            Order the collection by arbitrary field(s).

            The value must be a JSON array of dictionaries like
            [{"property": "fieldName", "direction": "dir"}]
            where "dir" may be either "ASC", or "DESC.
          example: |
            sort=<<example>>
  - filterable:
      queryParameters:
        filters:
          description: |
            Filter the collection with the specified constraints.

            The value must be a JSON array of dictionaries like
            [{"property": "fieldName", "operator": "op", "value": "someValue"}]
            where "operator" may be one of: =, ~, ~=, >=, >, <=, <, <>.
          example: |
            filters=<<example>>
  - pageable:
      queryParameters:
        start:
          description: Skip over a number of elements by specifying an offset value for the query
          type: integer
          required: false
          example: start=20
          default: 0
        limit:
          description: Limit the number of elements on the response
          type: integer
          required: false
          example: limit=80
          default: null

/:
  get:
    description: Get a collection
    is:
      - orderable:
          example: "[{\"property\":\"description_en\",\"direction\":\"DESC\"}]"
      - filterable:
          example: "[{\"property\":\"description_en\",\"operator\":\"=\",\"value\": \"Dynamite\"}]"
      - pageable
econchick commented 8 years ago

Should be better now :) will include this in the v0.1.9 release (not for another week or two) but it's in master. Thanks so much!