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

Add fetch_link to make it much easier to follow linked URLs within an API #357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bdowling
Copy link

@bdowling bdowling commented Apr 23, 2018

This is an attempt at answering the question I had in #352

By simply adding x-operationId: [linkedOperation] in your spec to URLs that are returned from the API that are internal links, and adding add_fetch_link: True to your config, those URLs will be returned in the model as FetchLink objects that can be called to retrieve the named `[linkedOperation]' on the given URL (e.g. obtain the http_request on that url and operationId, as if a CallableOperation had been called).

I think this is fairly straightforward. The only item I question is how I added the backref to swagger_spec._client, mainly so I could access my new SwaggerClient._get_operation from the context of http_future where it seems I only had access to the operation and spec. If there was some other way around this, please let me know. Alternatively _get_operation could be added to bravado-core instead I suppose. I just felt it was similar in vein to _get_resource that is in this module.

Without the new config option, there is no changed default behaviors.

I suppose I need to add some tests for this to be accepted, but figured I'd throw it out here to get some feedback.

fixed fetching also_return_response from config
added docstrings
misc cleanups
@bdowling
Copy link
Author

Example usage:

while 'next' in data:
    url = data['next']
    if url is None:
        break
    print("URI: ", repr(url))
    nextr = url()
    data,res = nextr.result()
  MultipleInstrumentData:
    type: object
    properties:
      count:
        type: integer
        format: int32
      next:
        type: string
        format: url
        x-operationId: 'instruments'
        x-nullable: true
      previous:
        type: string
        format: url
        x-operationId: 'instruments'
        x-nullable: true
      results:
        type: array
 ....

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.1%) to 95.462% when pulling b577eb0 on bdowling:add_fetch_link into 510c7ce on Yelp:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-3.1%) to 95.462% when pulling b577eb0 on bdowling:add_fetch_link into 510c7ce on Yelp:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.1%) to 95.462% when pulling b577eb0 on bdowling:add_fetch_link into 510c7ce on Yelp:master.

@coveralls
Copy link

coveralls commented Apr 23, 2018

Coverage Status

Coverage decreased (-3.1%) to 95.462% when pulling b577eb0 on bdowling:add_fetch_link into 510c7ce on Yelp:master.

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

Successfully merging this pull request may close these issues.

2 participants