Skip to content

Support set multiple examples for request/response body#23

Merged
greyli merged 2 commits intomasterfrom
improve-data-example
Apr 19, 2021
Merged

Support set multiple examples for request/response body#23
greyli merged 2 commits intomasterfrom
improve-data-example

Conversation

@greyli
Copy link
Copy Markdown
Member

@greyli greyli commented Apr 19, 2021

Add a new examples for @input and @output decorators to pass multiple example values for request/response body:

pet_examples = {
    'example foo': {
        'summary': 'an example of foo',
        'value': {'name': 'foo', 'id': 1}
    },
    'example bar': {
        'summary': 'an example of bar',
        'value': {'name': 'bar', 'id': 2}
    },
}

@app.get('/pets/<int:pet_id>')
@output(PetOutSchema, examples=pet_examples)
def get_pet(pet_id):
    if pet_id > len(pets) - 1:
        abort_json(404)
    return pets[pet_id]

Checklist:

  • Add tests
  • Update changelog

@greyli greyli merged commit 17ff637 into master Apr 19, 2021
@greyli greyli deleted the improve-data-example branch April 19, 2021 08:47
@victorcrimea
Copy link
Copy Markdown

Is it possible to set example per response code? like it is possible in openapi

    200: {
        "description": "Successfull logout",
        "content": {
            "application/json": {
                "schema": LogoutResponseSchema
            }
        }
    },
    400: {
        "description": "Database error",
        "content": {
            "application/json": {
                "schema": AdoziGenericErrorSchema,
                "examples": {
                    "foo": {
                        "summary": "database error",
                        "value": {
                            "error": "Database error.",
                            "error_code": 1001
                        }
                        
                    }
                }
            }
        }
    },
    401: {
        "description": "Not authorized",
        "content": {
            "application/json": {
                "schema": AdoziGenericErrorSchema,
                "examples": {
                    "foo": {
                        "summary": "not authorized",
                        "value": {
                            "error": "Not authorized",
                            "error_code": 1001
                        }
                        
                    }
                }
            }
        }
    }

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.

2 participants