Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse <<parameters>> in resources #2

Closed
econchick opened this issue Apr 21, 2015 · 3 comments
Closed

Parse <<parameters>> in resources #2

econchick opened this issue Apr 21, 2015 · 3 comments

Comments

@econchick
Copy link
Contributor

Within RAML, one is able to declare parameters within resource types and traits docs. It would be nice when accessing the actual resource object defined with a resource type/trait containing a parameter, to have the parameter values substitute the <<parameter>>.

Currently, it's setup as follows:

...
traits:
  - parameterTrait
      queryParameters:
        <<tokenName>>:
          description: A valid <<tokenName>> is required
/endpoint:
  get:
    is: [ parameterTrait ]
>>> endpoint.query_params
[QueryParameter(name='<<tokenName>>')]
>>> param = _[0]
>>> param.description
A valid <<tokenName>> is required

And ideally, it'd look like this:

...
traits:
  - parameterTrait
      queryParameters:
        <<tokenName>>:
          description: A valid <<tokenName>> is required
/endpoint:
  get:
    is: [ parameterTrait: { tokenName: access_token } ]
>>> endpoint.query_params
[QueryParameter(name='access_token')]
>>> param = _[0]
>>> param.description
A valid access_token is required
@econchick
Copy link
Contributor Author

This should be all set in the v0.2.0-dev branch 🎉

@bpowell65536
Copy link

@econchick Sorry to resurrect this, but I think I have found a case where the substitution of parameters doesn't work - given the following RAML:

#%RAML 0.8
title: Parameterised Resource Test
version: v1
baseUri: http://localhost:8080
resourceTypes:
  - collection-custom-variable:
      get:
        description: Get all the <<resourceType|!pluralize>>
      put:
        description: Create a new <<resourceType>>
      patch:
        description: Update an existing <<resourceType>>
      delete:
        description: Delete an existing <<resourceType>>
/jobs:
  type:
    collection-custom-variable:
      resourceType: job
/units:
  type:
    collection-custom-variable:
      resourceType: unit
/users:
  type:
    collection-custom-variable:
      resourceType: user

the resourceType parameter is not substituted into any of the method descriptions (this example doesn't work at all on the v0.2.0-dev branch because of a mistake I made in the fix for #85 - the attempted fix for the issue described here corrects that mistake as well). I have tried to develop a fix for this, but I ended up reimplementing some of the existing parameter substitution code. I would prefer to re-use the existing code if possible, but I'm not sure how to integrate it with the ramlfications.parser.main._create_resource_node method, which is where I think the substitution code needs to be. I have pushed a test case and a partial fix (which doesn't handle parameter transforms) to https://github.com/bpowell65536/ramlfications/tree/parameterised_resources_fix - would you be able to take a look? Thanks!

@bpowell65536
Copy link

@econchick After a bit more thought, I have made a better fix for this issue using ramlfications.utils.common.substitute_parameters. This fix handles parameter transforms and passes all the existing test cases, including correctly parsing the example in the previous post. I can post a pull request now if you like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants