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

The design of the example application #1

Open
greyli opened this issue Jun 13, 2021 · 0 comments
Open

The design of the example application #1

greyli opened this issue Jun 13, 2021 · 0 comments

Comments

@greyli
Copy link
Member

greyli commented Jun 13, 2021

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": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant