Skip to content

Validation with body which is intended for plain-text#317

Open
Vlczech wants to merge 2 commits into0b01001001:masterfrom
Vlczech:body_plain_text
Open

Validation with body which is intended for plain-text#317
Vlczech wants to merge 2 commits into0b01001001:masterfrom
Vlczech:body_plain_text

Conversation

@Vlczech
Copy link
Contributor

@Vlczech Vlczech commented Jun 27, 2023

No description provided.

Comment on lines +94 to +97
if hasattr(func, "body"):
content_items["text/plain"] = {
"schema": {"$ref": f"#/components/schemas/{func.body}"}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will the BaseModel look like? Can you provide an example? If possible, can you add some tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kemingy It is intended for text inputs like CSV etc. BaseModel is used to describe data in this model and it can be like this:

class FooBarPostBodyData(BaseModel):
    """
    CSV body for example for some import
    """
    __root__: str = Field(description="Data in CSV format - it consists of columns name, surname, ..., ..., ... .")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kemingy : ?

Copy link
Member

@kemingy kemingy Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response.

I feel that if we need to create a special argument for each MIME type, there will be endless arguments. By the way, they all belong to the request body. I wonder if we can add an attribute to the request model, for example, spec_mime_type or something else. This should be able to handle this kind of feature. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some old discussions here #176

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it could be useful to process on one place for multiple mime-types.

@ttekampe
Copy link
Contributor

ttekampe commented Nov 3, 2023

nice feature, I would also be interested in plain text / csv or also binary bodies.
So far the validator function has json and form arguments and I agree that adding one arg for every content type does not seem nice. So the way to go would be to add a body arg (probably deprecate jsonand form) and the body arg should be a class that specifies the content type and a model if necessary?

@kemingy
Copy link
Member

kemingy commented Nov 6, 2023

nice feature, I would also be interested in plain text / csv or also binary bodies. So far the validator function has json and form arguments and I agree that adding one arg for every content type does not seem nice. So the way to go would be to add a body arg (probably deprecate jsonand form) and the body arg should be a class that specifies the content type and a model if necessary?

Yes. I think we can add the body and then gradually deprecate json and form in the future.

@iongion
Copy link

iongion commented Nov 22, 2024

Still any plans on integrating this ?

There is this fork https://github.com/turner-townsend/flask-pydantic-spec which took this approach in its design.

My api supports application/bson as input format, along with application/json, that json seems unnatural.

@kemingy
Copy link
Member

kemingy commented Nov 24, 2024

Still any plans on integrating this ?

There is this fork https://github.com/turner-townsend/flask-pydantic-spec which took this approach in its design.

My api supports application/bson as input format, along with application/json, that json seems unnatural.

Yes. I plan to support all kinds of MIME, which might introduce some breaking changes in v2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants