an2deg / pyraml-parser

pyraml-parser - Python parser to RAML, the RESTful API Modeling Language.
81 stars 31 forks source link

Query parameters in HTTP methods #5

Closed scranen closed 10 years ago

scranen commented 10 years ago

It seems that method.queryParameters is not implemented (although the queryParameters do appear in the traits). If this is not intentional, I suggest the following patch:

diff --git a/pyraml/entities.py b/pyraml/entities.py
index 930c301..84614f5 100644
--- a/pyraml/entities.py
+++ b/pyraml/entities.py
@@ -79,6 +79,7 @@ class RamlMethod(Model):
     description = String()
     body = Reference(RamlBody)
     responses = Map(Int(), Reference(RamlBody))
+    queryParameters = Map(String(), Reference(RamlQueryParameter))

 class RamlResource(Model):
diff --git a/pyraml/parser.py b/pyraml/parser.py
index e4d37d5..7b0cae3 100644
--- a/pyraml/parser.py
+++ b/pyraml/parser.py
@@ -10,7 +10,7 @@ from collections import OrderedDict

 from raml_elements import ParserRamlInclude
 from fields import String, Reference
-from entities import RamlRoot, RamlResource, RamlMethod, RamlBody, RamlResourceType, RamlTrait
+from entities import RamlRoot, RamlResource, RamlMethod, RamlBody, RamlResourceType, RamlTrait, RamlQueryParameter
 from constants import RAML_SUPPORTED_FORMAT_VERSION
 import bootstrap

@@ -263,6 +263,7 @@ def parse_method(c, parent_object):
     method.responses = c.get_property_with_schema("responses", RamlMethod.responses)
     method.description = c.get_string_property("description")
     method.body = parse_body(ParseContext(c.get("body"), c.relative_path), method)
+    method.queryParameters = c.get_property_with_schema("queryParameters", RamlMethod.queryParameters)
     return method
an2deg commented 10 years ago

Hi scranen!

Thank you very match for your interest to the project. I've added supporting of queryParameters to RAML Method (queryParameters in RAML Traits will be tomorrow)

scranen commented 10 years ago

Thanks! Here are some more suggestions for alteration. The 'type' field in RamlResource is not according to the spec, I believe. I think the following would be better:

diff --git a/pyraml/entities.py b/pyraml/entities.py
index 5976008..8e0d9d6 100644
--- a/pyraml/entities.py
+++ b/pyraml/entities.py
@@ -97,7 +97,8 @@ class RamlResource(Model):
     displayName = String()
     description = String()
     uri = String()
-    type = Reference(RamlTrait, field_name="is")
+    is_ = List(Reference(RamlTrait, field_name="is"))
+    type = Reference(RamlResourceType)
     parentResource = Reference("pyraml.entities.RamlResource")
     methods = Map(String(), Reference(RamlBody))
     resources = Map(String(), Reference("pyraml.entities.RamlResource"))

Also, I don't have any way to distinguish between the situation in which a Resource had a body field specified, but did not contain any RAML info (e.g. because it only defines custom keywords), and the situation in which the Resource did not have a body tag in it at all. This could be fixed as follows (looking at the docstring, you actually intended to do this anyway).

diff --git a/pyraml/parser.py b/pyraml/parser.py
index 5c894d9..2a8fcac 100644
--- a/pyraml/parser.py
+++ b/pyraml/parser.py
@@ -281,6 +281,9 @@ def parse_body(c, parent_object):
     :return: RamlMethod  or None
     :rtype: RamlMethod
     """
+    
+    if c.data is None:
+        return None

     body = RamlBody()
     body.example = c.get_string_property("example")
an2deg commented 10 years ago

Ok, thank you very much for your help. I've added your code it to master branch.