raml-spec
raml-spec copied to clipboard
Resource Parameter Conditional Processing
Use case: Simple conditional processing is necessary for resource parameters. There are multiple use cases for this.
- Preventing content if a resource parameter is not provided
"". For example, if I have a trait that has an id parameterfooIdand a second id parameterbarId, not all of the resources leveraging this trait might need abarId. - Being able to alter descriptions to accurately describe the behavior of a response or body, with controls to form better English responses.
- Having default value support and the ability to detect a non-default value
- Being able to restrict the values allowed to be passed as parameters. For example, for a parameter intended to be used as a number, exclude strings and require the number to be less than 10000
- Have the ability to create new variables from parameters. For example, if I have a property that represents a URL
https://<<param>>mulesoft.com/, if I passparamas'subdomain'I would want to append a period to that to makehttps://subdomain.mulesoft.com/. if I pass"", indicating I do not want a subdomain, then I don't want to append a period. Given the size of the trait, this pattern might repeat multiple times, it would be better to set this once and refer to it later in the trait as necessary, such as<< domain=param.>>
I would like to be able to support something similar to the following:
traits:
...
description:
This response is returned whenever the << if barId -eq "" >>combination of the passed <<fooId>> and <<barId>><<else>>the passed <<fooId>><<fi>> is expected.
body:
application/problem+json:
properties:
<<fooId>>: string
<< if ! barId -eq "" >><<barId>>: string<<fi>>