Skip to content

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

Open
bdowling wants to merge 2 commits into
Yelp:masterfrom
bdowling:add_fetch_link
Open

Add fetch_link to make it much easier to follow linked URLs within an API#357
bdowling wants to merge 2 commits into
Yelp:masterfrom
bdowling:add_fetch_link

Conversation

@bdowling
Copy link
Copy Markdown

@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.

bdowling added 2 commits April 7, 2018 23:46
fixed fetching also_return_response from config
added docstrings
misc cleanups
@bdowling
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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