Last active
February 18, 2017 04:16
-
-
Save mursts/a91218bdd2b62ba6c62f13faea1b307e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
swagger: '2.0' | |
info: | |
title: Todo App | |
description: Todoを管理するAPI | |
version: "1.0.0" | |
basePath: /api | |
consumes: | |
- application/json | |
produces: | |
- application/json | |
paths: | |
/todo: | |
get: | |
summary: Todoを取得します | |
tags: | |
- Todo | |
responses: | |
200: | |
description: Todoのリスト | |
schema: | |
type: array | |
items: | |
$ref: '#/definitions/todo' | |
default: | |
description: エラー | |
schema: | |
$ref: '#/definitions/Error' | |
post: | |
summary: Todoを登録します | |
parameters: | |
- name: todo | |
in: body | |
description: 追加する内容 | |
required: true | |
schema: | |
$ref: '#/definitions/todo' | |
tags: | |
- Todo | |
responses: | |
200: | |
description: 登録成功 | |
schema: | |
items: | |
$ref: '#/definitions/todo' | |
default: | |
description: Unexpected error | |
schema: | |
$ref: '#/definitions/Error' | |
/todo/{Id}: | |
delete: | |
summary: Todoを削除します | |
parameters: | |
- name: Id | |
in: path | |
description: 削除するTodoのID | |
required: true | |
type: integer | |
tags: | |
- Todo | |
responses: | |
200: | |
description: 削除成功 | |
default: | |
description: Unexpected error | |
schema: | |
items: | |
$ref: '#/definitions/Error' | |
definitions: | |
todo: | |
type: object | |
required: | |
- description | |
properties: | |
id: | |
type: integer | |
format: int64 | |
description: | |
type: string | |
Error: | |
type: object | |
properties: | |
message: | |
type: string | |
fields: | |
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import connexion | |
from swagger_server.models.error import Error | |
from swagger_server.models.new_todo import NewTodo | |
from swagger_server.models.todo import Todo | |
from datetime import date, datetime | |
from typing import List, Dict | |
from six import iteritems | |
from ..util import deserialize_date, deserialize_datetime | |
def todo_get(): | |
""" | |
Todoを取得します | |
:rtype: List[Todo] | |
""" | |
return 'do some magic!' | |
def todo_id_delete(Id): | |
""" | |
Todoを削除します | |
:param Id: 削除するTodoのID | |
:type Id: int | |
:rtype: None | |
""" | |
return 'do some magic!' | |
def todo_post(todo): | |
""" | |
Todoを登録します | |
:param todo: 追加する内容 | |
:type todo: dict | bytes | |
:rtype: None | |
""" | |
if connexion.request.is_json: | |
todo = NewTodo.from_dict(connexion.request.get_json()) | |
return 'do some magic!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import connexion | |
from swagger_server.models.todo import Todo | |
from typing import List | |
import time | |
TODO = {} | |
def todo_get(): | |
""" | |
Todoを取得します | |
:rtype: List[Todo] | |
""" | |
return [todo for todo in TODO.values()] | |
def todo_id_delete(Id): | |
""" | |
Todoを削除します | |
:param Id: 削除するTodoのID | |
:type Id: int | |
:rtype: None | |
""" | |
todo = TODO.get(Id, None) | |
if todo is None: | |
return connexion.NoContent, 400 | |
del TODO[Id] | |
return | |
def todo_post(todo): | |
""" | |
Todoを登録します | |
:param todo: 追加する内容 | |
:type todo: dict | bytes | |
:rtype: None | |
""" | |
if connexion.request.is_json: | |
todo = Todo.from_dict(connexion.request.get_json()) | |
todo.todo_id = int(time.time()) | |
TODO.update({todo.todo_id: todo}) | |
return todo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment