jdiegodcp / ramlfications

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

Parse function should be able to parse string of raml #135

Open econchick opened 7 years ago

econchick commented 7 years ago

Like in pyyaml's yaml.loads, ramlfication.parse should be able to take a string of raml format, e.g.

raml = """title: foo API
baseUri: https://foo-api.example.com
"""
ramlfications.parse(raml)
{'title': 'foo API', 'baseUri': 'https://foo-api.example.com'}

There's a preference to not need a separate function (e.g. yaml.load vs yaml.loads), but if it's the only way, that's fine.

PR 120 attempts to address this, but I don't like how it designates a file vs a string by the presence of a file header. I think it should be something like if os.exists(filename), then parse file, otherwise try to parse string as raml.

freddrake commented 7 years ago

My preference would be separate functions. The caller should know what they have; a YAML syntax error on what was expected to be a path is likely to confuse an end user.