flask-restx icon indicating copy to clipboard operation
flask-restx copied to clipboard

Can't specified api doc body for a different input

Open plenzjr opened this issue 3 years ago • 0 comments

***** BEFORE LOGGING AN ISSUE *****

  • Is this something you can debug and fix? Send a pull request! Bug fixes and documentation fixes are welcome.
  • Please check if a similar issue already exists or has been closed before. Seriously, nobody here is getting paid. Help us out and take five minutes to make sure you aren't submitting a duplicate.
  • Please review the guidelines for contributing

Code

address_ns = Namespace(name="address", validate=True)
fields = {
    "street": String(attribute="street"),
    "number": String(attribute="number"),
    "zip_code": String(attribute="zip_code"),
    "user_id": Integer(attribute="user_id"),
    "cep_id": Integer(attribute="cep_id"),
}

fields["cep"] = Nested(cep_model)
fields["user"] = Nested(user_model)

model_with_netsted_fields = Model('Address',  fields)

class AddressPostFields(Raw):
    def format(self, value):
        return {
            "street": value.street,
            "number": value.number,
            "zip_code": value.zip_code,
            "user_id": value.user_id,
            "cep_id": value.cep_id,
        }

@address_ns.route("", endpoint="address_create")
class AddressResource(Resource):

    @address_ns.response(HTTPStatus.OK, "Retrieved unit list.")
    @address_ns.doc(model=model_with_netsted_fields)
    def get(self):
        return '{}'

    @address_ns.response(int(HTTPStatus.CREATED), "Added new unit.")
    @address_ns.doc(model=model_with_netsted_fields, body=AddressPostFields)
    def post(self):
        return '{}'

Expected Behavior

Specify a 'model' for input methods and another 'model' for output

Actual Behavior

with the code above, i'm not allowed to add a body on post. if I change the body param for model_with_netsted_fields, swagger shows all fields with the nested ones , but it should be omitted with AddressPostFields

I'm following the restx docs but couldn't get it work...

Environment

  • Python 3.8.10
  • Flask 2.0.2
  • Werkzeug 2.0.3
  • Flask-RESTX 0.5.1

plenzjr avatar Feb 25 '22 14:02 plenzjr