Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1K
Views
Cómo usar Marshmallow Schema en Flask-restx Swagger UI automáticamente

Estoy tratando de crear servicios web tranquilos con matraz-restx y malvavisco.

Estoy usando malvavisco para las validaciones de solicitud y respuesta.

Dado que la documentación de la API de Flas-restx no es compatible con los esquemas de malvavisco en la interfaz de usuario de Swagger, quiero agregarla mediante el decorador de documentos.

Código del controlador:

 @ns.route('/') class Test(Resource): @ns.doc(params={'test': 'test'}) def get(self): _input_schema = MySchema() errors = _input_schema.validate(request.args) if errors: return Response(str(errors), status=400) other_things()

Código de esquema:

 class MySchema(Schema): title = fields.Str() id = fields.Integer() slug = fields.Str()

Estoy tratando de agregar automáticamente parámetros del esquema a documentos api como ese

 @ns.doc(params=MySchema.ReturnAFieldDict())

Y dará algo así

 @ns.doc(params={"title":"A string", "id": "Int value with min and max", "slug":"A str"})

¿Hay alguna forma de hacer eso?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Una forma que encontré para obtener documentación es usar el decorador @api.expect(schema).

over 4 years ago · Santiago Trujillo Report

0

Puede usar api.marshal_with para documentar las respuestas

 from flask_restx.fields import Integer, String test_get = api.model( "TestGet", { "name": String(required=True), "age": Integer(required=True), }, ) @api.marshal_with(schema.test_get, code=200) def get(self): return {"name": "test", "age": 123}

marshal_with asigna el diccionario u objeto devuelto y asigna el campo según el esquema. Aquí, en este caso, el diccionario devuelto se asignará al esquema test_get donde el nombre será "prueba" y la edad será 123.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!