Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 28 15:29
    mostermann96 labeled #393
  • Nov 28 15:29
    mostermann96 opened #393
  • Nov 27 04:14
    BrikerMan closed #48
  • Nov 26 19:38
    szymonpru opened #392
  • Nov 25 00:30
    2ykwang opened #391
  • Nov 23 10:36
    winterwind37 commented #387
  • Nov 23 10:23
    winterwind37 commented #389
  • Nov 22 17:37
    pythonhubpy labeled #390
  • Nov 22 17:37
    pythonhubpy opened #390
  • Nov 18 14:23
    Sladerix edited #389
  • Nov 18 14:23
    Sladerix opened #389
  • Nov 18 14:23
    Sladerix labeled #389
  • Nov 17 10:20
    thunderbug1 commented #388
  • Nov 17 09:42
    thunderbug1 edited #388
  • Nov 17 09:42
    thunderbug1 labeled #388
  • Nov 17 09:42
    thunderbug1 opened #388
  • Nov 16 12:53
    tombuente commented #377
  • Nov 16 12:52
    tombuente commented #377
  • Nov 16 12:52
    tombuente commented #377
  • Nov 15 21:58
    franchyze923 commented #58
E-Kalla
@E-Kalla
actually , I want to this : https://marshmallow.readthedocs.io/en/stable/nesting.html#nesting-a-schema-within-itself
Is it possible without using marshmallow ?
Abdur-Rahmaan Janhangeer
@Abdur-rahmaanJ
@j5awry See https://aaronluna.dev/series/flask-api-tutorial/part-3/ "LINES 6, 14: The API will implement Bearer token authentication ..." and the comment below it

@Abdur-rahmaanJ If you don't mind me asking, is this an on-prem or cloud hosted? And is it possible to add authentication at other layers? It depends a lot on your setup, but something like using JWT with NGinx, or x509 based auth at Apache Webserver are other possibilities. But there's a lot of nuance there. I do think we need to figure out a better way of handling the pre-generated doc endpoint, and I think what flasgger is doing could be an interesting entry point. but it's going to take code change in flask-restx

Cloud-hosted, server-based auth is a great option also but see the above

1 reply
John Chittum
@j5awry
@E-Kalla : woof, self-reference. So, JSONSchema at a certain point started enabling more of that. I'd have to check on versioning. a lot of how the models are written and validated is based on JSONSchema v. 4. I'd have to look more closely at how to deal with something nested. But, unfortunately, restx models aren't as feature rich as Marshmallow
Henshal B
@henshalb
Hello, I have got a query.. How to add an additional GET into a class, may with a different name?
Henshal B
@henshalb
Just like an action decorator for django
John Chittum
@j5awry
hey all, we're cutting 0.4.0 release right now! flask and werkzeug both released 2.0.0. unfortunately, there are a few breaking changes we'll need to work through. You can pin flask and werkzeug yourself, but we're also pinning flask-restx for the moment till some upstream things fix, and we can make sure we've got any breaking changes accounted for
there are also some improvements and bugfixes. checkout the CHANGELOG.rst for quick hits
John Chittum
@j5awry
so i dropped by https://pypistats.org/packages/flask-restx thinking it'd show some interesting info -- our largest percentage of install is on 3.4 according to this
that's...worrisome since we've been talking about deprecating < 3.6. I'm wondering why there are so many 3.4 instals
alincmt
@ClimenteA
Hi, do you know how can I add @ns.doc (OpenApi) decorator with some default parameters in Namespace class?
I opened a question on stackoverflow (maybe others will need it): https://stackoverflow.com/questions/67530938/add-doc-decorators-on-namespace-instantiation-flask-restx
E-Kalla
@E-Kalla
Hello, I'm using marshmallow schema now , do you know the best way to documentate an API with marshmallow schema ?
I tried to keep @marshal_with(marshmallowschema)
But It didnt work, no error but swagger don't display anything.
I found https://apispec.readthedocs.io/en/latest/ is it the only solution ?
Thank you
John Chittum
@j5awry
honestly, if you're investing in marshmallow, apispec or moving to flask-smorest. smorest is the Marshmallow-Code version of flask-restx
E-Kalla
@E-Kalla
ok ;) and do you have some news about the deprecated Flask-RESTX request parse ? https://flask-restx.readthedocs.io/en/latest/parsing.html
John Chittum
@j5awry
nope. we keep saying "deprecated" because the original project had said so. But we haven't worked out anything different/better and regularly get people asking us to keep it
E-Kalla
@E-Kalla
ok thank you for reply !
Hamdi Burak Usul
@hbusul
Hello, we need a contributor to review pull request #341 . @j5awry was looking at the issue but we did not hear anything for a month. It would be really nice to use new werkzeug and flask with the flask-restx .
John Chittum
@j5awry
@hbusul sorry, it's been a very busy month. I've pulled in everything. I put up the changelog for the version. If anyone wants to give it a quick look before I merge and push the new version
Hamdi Burak Usul
@hbusul
@j5awry I can imagine, thanks for handling that :D . Our tests seems to do fine with the latest commit
E-Kalla
@E-Kalla
Hello ,
I have this issue for a while python-restx/flask-restx#314
I will try to take a look on the restx code but if you have an idea about where could this problem come from because it's really problematic.
If you have a polymorph field , you have to use marshmallow , then migrate all your api documentation on apispec, which is a very tedious work.
And even with apispec , swagger don't display the models correctly.
thank you
John Chittum
@j5awry
I've just run a release 0.5.0. it should end up in Pypi sometime~ish. I published the release on github, and bumped all the files appropriately
and the package.json should be a semver compliant thing now. i tried to hack on bumpr this morning, but since it appears to also be dead, i gave up
E-Kalla
@E-Kalla

Hey ,

I replied to the issue https://github.com/python-restx/flask-restx/issues/314#issuecomment-884753325
I think It can help a lot to resolve it

John Chittum
@j5awry

@E-Kalla thanks for really digging into the issue. I'd need to read a bit more to understand everything happening.

If you have an approach in mind, could you clearly state it in the issue? If it's to remove @cached_property i'm not sure the entire range of effects there, in particular with regards to benchmarking

serenanycvb
@serenanycvb:matrix.org
[m]

Hi, hope everyone is having a great Monday. I am currently setting up a POST method redirection using flask.redirect . For some reason, the redirection does not work and I was not able to get any useful logging even when I set FLASK_ENV=development. Here is the log I got:

127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -
[I 210816 16:49:57 _internal:122] 127.0.0.1 - - [16/Aug/2021 16:49:57] "POST /runs HTTP/1.1" 200 -

It seems this endpoint never got redirected.

Anyone has any insight on debugging this issue ?

Unfortunately, I am not able to provide any code here because the redirection works well when I tried to set up some dummy code, but it did not work with a big project that I am currently working on.

here is the log I got for dummy code that I set up:

127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos2/1 HTTP/1.1" 307 -
127.0.0.1 - - [16/Aug/2021 17:04:51] "POST /todos/ HTTP/1.1" 200 -

From this log, the endpoint actually got redirected.

John Chittum
@j5awry
without code, it's hard to help debug.
serenanycvb
@serenanycvb:matrix.org
[m]
I am able to reproduce the error now, it was due to marshal_with which seems changed returned redirection:
Here is the code:
import flask
from flask import Flask
from flask_restx import Model, Resource, fields, Namespace, abort, Api
from werkzeug.middleware.proxy_fix import ProxyFix
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app)
api = Api(app, version='1.0', title='TodoMVC API',
    description='A simple TodoMVC API',
)

ns = Namespace('todos', description='TODO operations')
ns2 = Namespace('todos2', description='TODO operations')

todo = Model('todo', {
    'id': fields.Integer(required=True, description='The task unique identifier'),
    'task': fields.String(required=True, description='The task details'),
    'description': fields.String(required=True, description='Put some description here')
})

response = Model('response', {
    'id': fields.Integer,
    'task': fields.String
})

ns.models[todo.name] = todo
ns.models[response.name] = response

todo2 = Model('todo2', {
    'task': fields.String(required=True, description='The task details'),
    'todo_description': fields.String(required=True, description='Put some description here')
})

response2 = Model('response2', {
    'id': fields.Integer,
    'task': fields.String
})

ns2.models[todo2.name] = todo2
ns2.models[response2.name] = response

api.add_namespace(ns)
api.add_namespace(ns2)

@ns2.route('/<int:id>')
@ns2.response(404, 'Todo not found')
class Todo(Resource):
    '''Show a single todo item and lets you delete them'''
    @ns2.doc('get_todo')
    def get(self, id):
        '''Fetch a given resource'''
        return "get todo 2"

    @ns2.expect(todo2)
    @ns2.marshal_with(response)
    def post(self, id):
        '''Update a task given its identifier'''
        if id == 1:
            redirection = flask.redirect(flask.url_for('todos_todo_list', _method='POST'), code=307)
            return redirection
        return {"id": "dummy id", "task": "some dummy task here"}


@ns.route('/')
class TodoList(Resource):
    '''Shows a list of all todos, and lets you POST to add new tasks'''
    @ns.doc('list_todos')
    def get(self):
        '''List all tasks'''
        return "get todo list"

    @ns.doc('create_todo')
    @ns2.expect(todo)
    @ns.marshal_with(response)
    def post(self):
        '''Create a new task'''
        payload = ns.payload
        return {"id": payload.get("id"), "task": payload.get("task")}


if __name__ == '__main__':
    app.run(debug=True)
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