jdiegodcp / ramlfications

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

Regression in v0.2.2 #168

Open j616 opened 4 months ago

j616 commented 4 months ago

Hello, I've getting the following (partial) traceback as of v0.2.2.

    return RAMLLoader().load(input_file)
209
  File "/usr/local/lib/python3.10/site-packages/ramlfications/loader.py", line 123, in load
210
    raml_version, _raml_fragment_type = self._parse_raml_header(raml)
211
  File "/usr/local/lib/python3.10/site-packages/ramlfications/loader.py", line 88, in _parse_raml_header
212
    if not header.startswith(RAMLHEADER):
213
TypeError: startswith first arg must be bytes or a tuple of bytes, not str

Looks to be a strait up type error internal to ramlifications. I can try and create a minimal test case to re-create the issue if required.

jdiegodcp commented 4 months ago

Hey James, yes it would be really helpful to check what's the issue

j616 commented 4 months ago

It seems that ramlfications no longer likes file objects opened as bytes type. I'm not sure how this ever worked, given the lack of recent changes, to be honest!

If I have a dummy file:

title: Dummy RAML
version: 0.1
mediaType: application/json

documentation:
  - title: Overview
    content: |
      This is a test of
      the yaml parsing.

And a script as follows:

import ramlfications

with open("test.raml", "rb") as ramlFile:
    ramlfications.parse(ramlFile)

I get the following traceback:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/jamessa/.pyenv/versions/3.10.11/lib/python3.10/site-packages/ramlfications/__init__.py", line 68, in parse
    loader = load(raml)
  File "/home/jamessa/.pyenv/versions/3.10.11/lib/python3.10/site-packages/ramlfications/__init__.py", line 31, in load
    return load_file(raml_file)
  File "/home/jamessa/.pyenv/versions/3.10.11/lib/python3.10/site-packages/ramlfications/utils/__init__.py", line 198, in load_file
    return RAMLLoader().load(raml)
  File "/home/jamessa/.pyenv/versions/3.10.11/lib/python3.10/site-packages/ramlfications/loader.py", line 123, in load
    raml_version, _raml_fragment_type = self._parse_raml_header(raml)
  File "/home/jamessa/.pyenv/versions/3.10.11/lib/python3.10/site-packages/ramlfications/loader.py", line 88, in _parse_raml_header
    if not header.startswith(RAMLHEADER):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str