Code Monkey home page Code Monkey logo

Comments (7)

danballance avatar danballance commented on May 14, 2024

Okay, digging into the code a little more now and I can see that the operationId is the view_func for Flask.add_url_rule.

I can also see that the Operation class uses a series of decorators to transform the view_func response. And according to line 126 of decorators/produces.py when I return a flask.Response object, the code decides to just return my response with no further processing.

So should I be looking at trying to add an additional decorator that will add extra headers? Would anyone be able to point me in the right direction here and I could try and get a pull request together for you next week?

Is this functionality you'd like to see added or should I be approaching this problem differently?

from connexion.

hjacobs avatar hjacobs commented on May 14, 2024

Do you want to have generic logic of adding the location header (e.g. pointing to "GET" of the same path when doing a PUT)? Where do you decide how to fill the "Location" header?

from connexion.

danballance avatar danballance commented on May 14, 2024

Hi,

So I am trying to find a way to return some headers of my own, along with the response body, from the view_func specified via the operationId. Perhaps some kind of decorator on the view function might work? Or alternatively maybe some kind of collection could be added as an attribute to the view function? So something like:

def my_view_func():
pass
my_view_func.headers = list_of_tuples

I'm not sure what would be the best approach. So adding a Location header is my use case here, but I think having the ability to return response headers as well as a response body would be useful in a range of different scenarios.

Does that make more sense to you now?

Dan

from connexion.

danballance avatar danballance commented on May 14, 2024

Hi there,

I've been thinking a bit more about this. I can see in the code that a tuple of length 2 is returned from the view function. I was thinking of modifying BaseSerializer.get_data_status_code to handle a tuple of length 2 or 3 - with the third element being a list of tuples of additional headers. Once the Response object has been generated, if the headers are not an empty list, then these headers are added to the response before Produces and Jsonifier return.

Would a technique like this of adding optional headers from the view function be of interest to you? If you like I could write this and open a pull request?

Dan

from connexion.

danballance avatar danballance commented on May 14, 2024

Okay, looks like I should have referenced this issue in my pull request to link this issue in. Since I didn't do that, here's the link:

Pull Request: #77

from connexion.

hjacobs avatar hjacobs commented on May 14, 2024

@danballance thanks for the PR, we'll check it 😄

from connexion.

jmcs avatar jmcs commented on May 14, 2024

#77 was already merged.

from connexion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.