예제 #1
0
def get_request_with_json_schema_query_args(
        arg1=Query(StringField(min_length=3, max_length=10)),
        arg2=Query(NumberField(gte=0, lte=10, multiple_of=1)),
        arg3=Query(BooleanField(default_value=False)),
):
    '''
Currently, we have 5 basic JSON schema fields

* StringField
* NumberField
* BooleanField
* ObjectField
* ArrayField

Below we'll first demo how to use StringField, NumberField & BooleanField

```python
from django_openapi import Query
from django_openapi.schema import StringField, NumberField, BooleanField

@api.get('/get_request_with_json_schema_query_args')
def get_request_with_json_schema_query_args(
    arg1=Query(StringField(min_length=3, max_length=10)),
    arg2=Query(NumberField(gte=0, lte=10, multiple_of=1)),
    arg3=Query(BooleanField(default_value=False)),
):
    return dict(arg1=arg1, arg2=arg2, arg3=arg3)
```
    '''
    return dict(arg1=arg1, arg2=arg2, arg3=arg3)
예제 #2
0
def post_request_with_json_schema_form_args(
        arg1=Form(StringField(min_length=3, max_length=10)),
        arg2=Form(NumberField(gte=0, lte=10, multiple_of=1)),
        arg3=Form(BooleanField(default_value=False)),
):
    '''
Now we use the same JSON schema field definitions, but in Form() format.

```python
from django_openapi import Form
from django_openapi.schema import StringField, NumberField, BooleanField

@api.post('/post_request_with_json_schema_form_args')
def post_request_with_json_schema_form_args(
    arg1=Form(StringField(min_length=3, max_length=10)),
    arg2=Form(NumberField(gte=0, lte=10, multiple_of=1)),
    arg3=Form(BooleanField(default_value=False)),
):
    return dict(arg1=arg1, arg2=arg2, arg3=arg3)
```
    '''
    return dict(arg1=arg1, arg2=arg2, arg3=arg3)
예제 #3
0
def post_request_file_upload(
    upload_file=UploadFile(),
    md5_hash=Form(
        StringField(required=False, description='md5 of uploaded file')),
):
    '''
Now let's try building an endpoint for user file upload.

```python
from hashlib import md5
from django_openapi import UploadFile, Form
from django_openapi.schema import StringField, NumberField, BooleanField

@api.post('/post_request_file_upload')
def post_request_file_upload(
    upload_file = UploadFile(),
    md5_hash = Form(StringField(required=False, description='md5 of uploaded file'))
):
    return {
        'submitted_md5': md5_hash,
        'file': {
            'name': upload_file.name,
            'size': upload_file.size,
            'md5': md5(upload_file.read()).hexdigest,
        },
    }
```
    '''
    return {
        'submitted_md5': md5_hash,
        'file': {
            'name': upload_file.name,
            'size': upload_file.size,
            'md5': md5(upload_file.read()).hexdigest(),
        },
    }
예제 #4
0
class HelloPayload(BaseModel):
    word = StringField(default_value='world', min_length=3)
예제 #5
0
class IntroResponse2(BaseModel):
    arg1 = StringField(min_length=3, max_length=10)
    arg2 = NumberField(gte=0, lte=10, multiple_of=1)
    arg3 = BooleanField(default_value=False)
예제 #6
0
class IntroResponse1(BaseModel):
    arg1 = StringField()
    arg2 = StringField()
예제 #7
0
class SamplePayload(BaseModel):
    arg1 = StringField(min_length=3, max_length=10)
    arg2 = NumberField(gte=0, lte=10, multiple_of=1)
    arg3 = BooleanField(default_value=False)
예제 #8
0
class CreateUserModel(BaseModel):
    first_name = StringField(min_length=5, max_length=50)
    last_name = StringField(min_length=5, max_length=50)