Open hadesbox opened 10 years ago
While this is not a critical Bug, today I tried to troubleshoot it. So far no success BUT... I've discovered that the problem is on the traits.coffee file, more specifically on apply_traits and/or apply_trait.
When a trait is applied to the resource (or method), there is a missing condition somewhere that should check if that particular property is not overwrriten, so the trait its NOT applied.
I would like to ask Norberto what happen if a queryparameter defined on a trait, that later is overwriten in the speification, should all properties be merged or overwritted values prevail.!!!!
So the whole enchilada is in src/nodes.coffee
class @MappingNode extends @CollectionNode
id: 'mapping'
clone: ->
properties = []
for property in @value
name = property[0].clone()
value = property[1].clone()
properties.push [name, value]
temp = new @constructor(@tag, properties, @start_mark, @end_mark, @flow_style)
return temp
The thing as I suspect, is that the clone method should be comparing against the original Mapping Node/property, make a DEEP comparisons of each property, and in the case that a parent property exist with the same name (i.e. queryParam X is defined on method and in trait, header Y is defined in method and in trait), it should NOT be cloned... this will prevent merging of properties in traits and explicit properties in methods.
Sadly I don't know coffee script enough to propose a pull request.
@hadesbox this is a really good catch, and thanks for the analysis.
I am not entirely sure how to fix this either (in terms of the functionality, not the code, that part should be easy)... We need to think about whether there are cases in which we want arrays mixed in, and cases where the array should be entirely overwritten.
If there is a case where we want this dual behaviour (sometimes overwritten and sometimes mixed in), the fix will not be simple at all...
I know it wont be simple... I tried to find a way but the deep cloning function its kinda complex to modify...
I would propose that the RAML workgroup defines how and when the overwrite of traits with explicit properties in the services should happen. The parser should NOT do what I "think" or "feel", but what the Spec says.
I mentioned something here so maybe its clarified in 1.0 and then this can be implemented on the js parser :).
So if you define a queryParam inside a trait, and you use this trait for one method but then you override it on the method definition, the enums get added/joined/merged instead of overriden.
Here is the sample RAML file.
In this example the enum [day, month week] defined in the trait, is not overriden by the enum defined in the method definition which is only month. As you can see in the console screenshot, the enum says [day, week, month, month], and it should be only [month] so the raml parser is merging/joining the enums rather than overriding them.
This is the output JSON of the resources properties, after it gets rendered by the raml-js-parser