Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 06:13
    radiantone commented #440
  • 05:15
    sillydan1 commented #440
  • May 18 14:48
    radiantone edited #440
  • May 18 14:48
    radiantone edited #440
  • May 18 14:47
    radiantone opened #440
  • May 18 14:47
    radiantone labeled #440
  • May 15 05:51
    cmpunches labeled #439
  • May 15 05:51
    cmpunches opened #439
  • May 14 08:37
    thedumbterminal edited #438
  • May 14 08:36
    thedumbterminal labeled #438
  • May 14 08:36
    thedumbterminal opened #438
  • May 14 00:07
    boompig commented #437
  • May 14 00:05
    boompig opened #437
  • May 14 00:05
    boompig labeled #437
  • May 13 17:49
    JavaScriptDude commented #116
  • May 13 12:49
    ReznikovRoman commented #135
  • May 13 12:00
    abeiertz commented #59
  • May 12 18:48
    lyonsaj commented #192
  • May 10 05:55
    busoff edited #435
  • May 07 14:12
    ankurcharan commented #151
John Chittum
@j5awry

so the requirement is:

Given an endpoint with a variable (var == $CONDITION), have a redirect only for $CONDITION, otherwise, return properly

My gut would say, if you want a single endpoint, split by condition, to do 2 redirects. One for $CONDITION, one for everything else. and the resultant endpoints handling the marshalling. Because, in the end, if their responses are going to be different, they should probably be considered separate endpoints

and that's going to be more properly rendered in the Swagger schema as well.
serenanycvb
@serenanycvb:matrix.org
[m]
Yes. The reason that I set up redirection is because, the endpoint already exists to do 2 things where separated by if-else condition statement.
For right now, I want to separate the 2 things into 2 different endpoints.
In order to not introduce breaking change for our users, so I decided to make the redirection from old endpoint to the new endpoint before fully separate them.
It would be nice to not remove marshaling because the old endpoint still needed to be kept.
John Chittum
@j5awry

Considering you're changing core functionality based upon a condition, i'd say keeping the original endpoint with 2 redirects, split by condition. then if you want to deprecate the v1 style endpoint later, you can

the other option is to split v1 and v2 endpoints, and just tell folks to use v2 for the new setup. Versioning and moving some endpoints is normal, and versioning is supported in flask-restx. you can provide version= to the API generator.

serenanycvb
@serenanycvb:matrix.org
[m]
Hi, John. Thank you for your suggestion. I think both are valid approaches. I think I am going to implement the first approach because we as a team had agree on not introducing breaking change for this new deployment and having this redirection will give users more time to adapt to the new endpoint.
E-Kalla
@E-Kalla
Hello ,
I have a question about marshalling.
I want to use marshall_with by passing a polymorph field map in argument , but it doesn't work , can someone help me ?
https://prnt.sc/1qfkppk
I want my function to be able to marshal list of this polymorph field
Carlos PiƱa
@cpinamtz_twitter

Hi, I have a question about how can I create a field which is a fixed list of different models:

model_1 = api.model(...)
model_2 = api.model(...)
model_3 = api.model(...)

model = api.model('model', {'field': fields.List([model_1, model_2, model_3])})

I know passing the list of previous models is not expected as the first param of the fields.List class but I don't know how to achieve it. Any ideas?

Matt
@mtcarr_gitlab
Hey folks, is there any way to define an arbitrary field in an api model?
Besides going the "stringly typed" route
My first thought would have been using fields.Raw but it seems to enforce an object structure when using validate=True
e.g. it won't allow "abc" or 123, data needs to be inside a json object {}
Brock Palen
@brockpalen
I'm trying to use values that are set in the current apps .config[] list as static values in my api.models but I'm getting errors about app_context() Rather than try to push an context in my include that has all my models are there any tips you would recomend for including configuration values when marshaling results?
Brock Palen
@brockpalen
Ok looks like using current_app.confg[] in my models only throw the context error for setting validation values like min= max= but not when used in attribute= lambda
Abdur-Rahmaan Janhangeer
@Abdur-rahmaanJ
I just did this talk: Advanced Flask: Recipes For An All-weather Craft | https://www.youtube.com/watch?v=veMSbl2fbXE and mentionned Flask-restx as an example to integrate. At the end there was a question on upgrading the OpenApi spec (around 27:37). I said that we need some more helping hands
Abdur-Rahmaan Janhangeer
@Abdur-rahmaanJ
Btw
If anybody is up for a talk about restx would be awesome: https://flaskcon.com/y/2021/
People need to discover the framework more!
Tony
@axc450
Hey all :) I have a quick question I couldn't find the answer to. I'm looking for a way to use api.doc() to document a POST request which should be able to take any JSON body (that is to say a valid JSON body is required, doesn't matter what is actually inside that body). At the moment, I am using a reqparse that is passed to the api.expect() which I dont actually use in my code but is just there to force the Swagger docs to give me a JSON body when clicking "Try it out". I understand there isn't really a way to pass custom Swagger JSON (as you would be able to pass invalid JSON) so what would be the best way to do this?
failo
@arduino__test_twitter
Hi, how do I change the default response content type in swagger ui. I tried ns.produces and api.representation. I woul dlike to replace application/json to application/xml
Brock Palen
@brockpalen
Is there a way when marsharling a response to not display a field if it's null / None? I have a single code base that has nested models, and some systems don't have a given feature so rather than returning null the front end people prefer we not pass along something that doesn't exist at all on that system.
Harshal Chaudhari
@harshalchaudhari35
@brockpalen I remember vaguely there is an option to skip none fields during marshalling. You will have to check the fields.raw and other classes used for marshalling. Alternatively, you could override the output function of any fields class and change the output to suit your needs
Brock Palen
@brockpalen
@harshalchaudhari35 Looks like there is a mask= option that is a callable, I'll try that and report.
Harshal Chaudhari
@harshalchaudhari35
image.png
@brockpalen here this is what I have referring to earlier
Brock Palen
@brockpalen
@harshalchaudhari35 skip_none= is what I wanted actually, and it works perfectly becaus depending on configuration different values in the nested group are populated. In our case does our campus HPC cluster have single precision GPUs or not,
Turns out mask= does something I hacked around by having a nasty lambda function in my model so that will clean that up significantly,
Really appreciate it, I need to get in the habbit of looking at the prototypes and not just the normal example documentation,
Harshal Chaudhari
@harshalchaudhari35
@brockpalen glad that helped and worked out for you. Yeah my experience has been the same and daunting with restx. Many times I find myself overriding many functions from the library.
Brock Palen
@brockpalen
NP, I really like the library, just wish it had more community behind it, it front ends out 14,000 CPU HPC cluster, and will soon front end our 20PB research archive, our univeristy really appreciates such an easy to understand library is available,
Brock Palen
@brockpalen
Maybe I'm not grocking it, but how do I input validation when for POST requests @api.route("/<string:subaccount>/user/<string:uniquename>") How do I do stricter validation of uniquename much like parsing payloads? Do I do it all manually in my routine? Or is there something more strict than <string:varname> ?
Harshal Chaudhari
@harshalchaudhari35
Ah what you are looking for is more of base flask functionality here. Flask provides a set of converters types to validate/typecast the route params. You can create your own converter types as mentioned here. https://uniwebsidad.com/libros/explore-flask/chapter-6/url-converters
If you don't want to define your own stuff and prefer a library doing it for you heres one https://github.com/Ge0rg3/flask-parameter-validation seems to support whitelists and regex validation
Brock Palen
@brockpalen
Thanks i'll check that out
Brock Palen
@brockpalen
BTW do POST requests have to have a payload if all the values in the model are optional? I found my unit tests fail unless I send an empty payload.
Harshal Chaudhari
@harshalchaudhari35
Short answer is yes :) You could get away with using content-length header set to 0 also
Brock Palen
@brockpalen
Weird, then why do I get a 500 rc if I don't pass data=json.dumps({})
dpeschman
@dpeschman
hello!
Ryan Truran
@RyanTruran
OAS3 allows for one response to have multiple schemas, through the use of oneOf, anyOf, allOf, not.
https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/
Does restx currently support this?
Matthew Jacobsen
@mjacobsen32
Can anyone offer some live support right now? I am having trouble with my routing. Keep getting 404 when routing to my API Blueprint, but the regular flask routes are getting reached just fine
Jamin Collins
@jamin.collins_gitlab
I'm having a bit of trouble with RequestParser and how to specify that an argument is a list of strings. From what I can find, action="append" should do it, but adding this appears to drop the element from the generated Swagger documentation.
Brock Palen
@brockpalen
Is there a flask library to generally protect against URL injection through routes? The flask security page didn't have anything that stuck out,
dpeschman
@dpeschman
@j5awry @ziirish Any ETA for the next bugfix release?
Giacomo Gritzan
@ggritzan_gitlab

I currently have problems with marshalling my Responses.

I am trying to do the following:

test_model = Model(
    "Test",
    {
        "_id": fields.String,
        "name": fields.String,
        "location": fields.String,
        "ip": fields.String,
    },
)

success_model = Model(
    "Success",
    {"data": fields.List(
        fields.Nested(test_model)
    )
    },
)

Without throwing any exception the data in the response is null

[{"status": "success", "data": null}']
Can somebody give me an advice?

Patrick Ray. Huang
@phuang07
hello all, I am new to restx, wondering when creating a model that has a one to many relationship, (e.g, order and order_items), how do i specify the field in the order model?
Tiago Tavares
@BigTava
Could enable the creation of models without automatically documenting, please?
It would be great to use @api.marshal_with(model) with multiple models, but not letting all of them be documented in swagger
John Chittum
@j5awry
FYI: i'm no longer a maintainer of python-restx. @ziirish is the final member left. I've removed my privs from Github. unfortunately, I have no time. and, honestly, i've started receiving personal emails asking about merges, etc. I don't have the capacity to deal with those.