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

Make resource fields mandatory #120

Open
anvth opened this issue Jun 15, 2018 · 1 comment
Open

Make resource fields mandatory #120

anvth opened this issue Jun 15, 2018 · 1 comment

Comments

@anvth
Copy link

anvth commented Jun 15, 2018

I have the following model:

@swagger.model
class AuthModel:
    resource_fields = {
        'username': fields.Integer,
        'password':  fields.String
    }

In the generated spec, the model will have both the resource fields as optional. How do I make them mandatory?

@callynch
Copy link

callynch commented Aug 8, 2023

Very old question, but I discovered the answer to this myself today by looking through the source code and thought I'd share. To remove the 'optional' annotation which is automatically added to resource fields, you need to specify a required property in your class definition, which should contain a list of field names.

For example, to make the "username" field mandatory, you'd do the following:

@swagger.model
class AuthModel:
    resource_fields = {
        'username': fields.Integer,
        'password':  fields.String
    }
    required = ['username']

Or alternatively, to make all fields in your model mandatory:

@swagger.model
class AuthModel:
    resource_fields = {
        'username': fields.Integer,
        'password':  fields.String
    }
    required = list(resource_fields.keys())

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

No branches or pull requests

2 participants