python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.17k stars 336 forks source link

Can't specified api doc body for a different input #416

Open plenzjr opened 2 years ago

plenzjr commented 2 years ago

BEFORE LOGGING AN ISSUE

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