Giter Club home page Giter Club logo

flask-api-examples's People

Contributors

greyli avatar jugmac00 avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

greyli

flask-api-examples's Issues

The design of the example application

I'm thinking of creating a pet store example with the following setup and endpoints.

Common Setup:

  • Flask-SQLAlchemy
  • In-memory SQLite
  • A Pet model.
    • id
    • name
    • category
    • age

Endpoints:

  • GET /
  • GET /pets/:pet_id
  • GET /pets
  • POST /pets
  • PATCH /pets/:pet_id
  • DELETE /pets/:pet_id

image

The example OpenAPI spec:
{
    "components": {
        "schemas": {
            "PetIn": {
                "properties": {
                    "category": {
                        "enum": [
                            "dog",
                            "cat"
                        ],
                        "type": "string"
                    },
                    "name": {
                        "maxLength": 10,
                        "minLength": 0,
                        "type": "string"
                    }
                },
                "required": [
                    "category",
                    "name"
                ],
                "type": "object"
            },
            "PetInUpdate": {
                "properties": {
                    "category": {
                        "enum": [
                            "dog",
                            "cat"
                        ],
                        "type": "string"
                    },
                    "name": {
                        "maxLength": 10,
                        "minLength": 0,
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "PetOut": {
                "properties": {
                    "category": {
                        "type": "string"
                    },
                    "id": {
                        "type": "integer"
                    },
                    "name": {
                        "type": "string"
                    }
                },
                "type": "object"
            },
            "ValidationError": {
                "properties": {
                    "detail": {
                        "properties": {
                            "<location>": {
                                "properties": {
                                    "<field_name>": {
                                        "items": {
                                            "type": "string"
                                        },
                                        "type": "array"
                                    }
                                },
                                "type": "object"
                            }
                        },
                        "type": "object"
                    },
                    "message": {
                        "type": "string"
                    },
                    "status_code": {
                        "type": "integer"
                    }
                },
                "type": "object"
            }
        }
    },
    "info": {
        "title": "APIFlask",
        "version": "0.1.0"
    },
    "openapi": "3.0.3",
    "paths": {
        "/": {
            "get": {
                "parameters": [],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {}
                            }
                        },
                        "description": "Successful response"
                    }
                },
                "summary": "Say Hello"
            }
        },
        "/pets": {
            "get": {
                "parameters": [],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "items": {
                                        "$ref": "#/components/schemas/PetOut"
                                    },
                                    "type": "array"
                                }
                            }
                        },
                        "description": "Successful response"
                    }
                },
                "summary": "Get Pets"
            },
            "post": {
                "parameters": [],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/PetIn"
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PetOut"
                                }
                            }
                        },
                        "description": "Successful response"
                    },
                    "400": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ValidationError"
                                }
                            }
                        },
                        "description": "Validation error"
                    }
                },
                "summary": "Create Pet"
            }
        },
        "/pets/{pet_id}": {
            "delete": {
                "parameters": [
                    {
                        "in": "path",
                        "name": "pet_id",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "204": {
                        "description": "Successful response"
                    }
                },
                "summary": "Delete Pet"
            },
            "get": {
                "parameters": [
                    {
                        "in": "path",
                        "name": "pet_id",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PetOut"
                                }
                            }
                        },
                        "description": "Successful response"
                    }
                },
                "summary": "Get Pet"
            },
            "patch": {
                "parameters": [
                    {
                        "in": "path",
                        "name": "pet_id",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/PetInUpdate"
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/PetOut"
                                }
                            }
                        },
                        "description": "Successful response"
                    },
                    "400": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/ValidationError"
                                }
                            }
                        },
                        "description": "Validation error"
                    }
                },
                "summary": "Update Pet"
            }
        }
    },
    "tags": []
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.