Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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.

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.

3 participants