SlideShare a Scribd company logo
OpenAPIを利用したPythonWebアプリケーション開発
Kabuku Inc.
Software Engineer
@taxpon
taxpon
http://takuro.ws
- Python, TypeScript, Go, DevOps
- EuroPython 2017, 2016, PyConJP 2015, Blender Conf 2015
- Swagger Codegen technical committee (Python, TypeScript)
Takuro Wada
3
OpenAPIを利用したPythonWebアプリケーション開発
5
(https://www.openapis.org/about より一部改変引用)
‣
‣
‣
‣
‣
‣
‣
6
‣
‣
‣
‣
‣
‣
7
8
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
‣
9
10
11
‣
‣
‣
12
ちょっとややこしい…
13
OpenAPI
Specification
Swagger Core
Swagger Parser
Swagger Codegen
Swagger UI
Swagger Editor
3rd Party Tools
OpenAPI
Document
(YAML or JSON)
べんり!
‣
‣
‣
‣
15
‣
‣
‣
16
17
OpenAPIを利用したPythonWebアプリケーション開発
‣
‣
‣
‣
‣
‣
19
‣
‣
‣
20
‣
‣
21
COREツール
‣
‣
‣
22
COREツール
‣
23
OpenAPI
Doc
Generate
Swagger
Codegen
Input
Multiple languages
COREツール
‣
‣
‣
24
‣
‣
‣
‣
‣
‣
‣
25
‣
26
Book:
type: object
required: [id]
properties:
   id:
     type: integer
   title:
     type: string
   author:
     type: string
‣
27
import yaml
from bravado_core.spec import Spec
# 1
with open('openapi.yaml', 'r') as f:
raw_spec = yaml.load(f)
# 2
spec = Spec.from_dict(raw_spec)
# 3
book = raw_spec['definitions']['Book']
# 4
validate_schema_object(spec, book, target)
‣
28
validate_schema_object(spec, book, {})
Code
jsonschema.exceptions.ValidationError: 'id' is a required property
Failed validating 'required' in schema:
{'properties': {'author': {'type': 'string'},
'id': {'type': 'integer'},
'release_date': {'format': 'date', 'type': 'string'},
'title': {'type': 'string'}},
'required': ['id'],
'type': 'object',
'x-model': 'Book'}
On instance:
{}
Result
‣
29
validate_schema_object(spec, book, {"id": 1, "title": 1})
Code
jsonschema.exceptions.ValidationError: 1 is not of type 'string'
Failed validating 'type' in schema['properties']['title']:
{'type': 'string'}
On instance['title']:
1
Result
‣
‣
30
from bravado_core.unmarshal import unmarshal_schema_object
book_obj = unmarshal_schema_object(
  spec, book,
  {"id": 1,
"title": "Merchant of Venice",
“author": "William Shakespeare"})
print(book_obj)
Code
]変換対象のデータ
Book(author='William Shakespeare', id=1, title='Merchant of Venice')
Result
‣
31
Book:
type: object
required: [id]
properties:
   id:
     type: integer
   title:
     type: string
   author:
     type: string
   release_date:
     type: string
     format: date ]
‣
32
book_obj = unmarshal_schema_object(
  spec, book,
  {"id": 1,
"title": "Merchant of Venice",
"author": "William Shakespeare",
"release_date": "2017-07-11"})
print(book_obj)
Code
]変換対象のデータ
Book(author='William Shakespeare', id=1,
release_date=datetime.date(2017, 7, 11), title='Merchant of Venice')
Result
‣
‣
‣
‣
‣
33
‣
‣
34
Book = spec.definitions['Book']
book_obj = Book(id=1, title="Merchant of Venice",
s
release_date=date(2017, 7, 11))
book_dict = marshal_schema_object(spec, book, book_obj)
print(book_dict)
]“Book” object
Code
{'release_date': '2017-07-11', 'title': 'Merchant of Venice', 'id': 1,
'author': 'William Shakespeare'}
Result
‣
‣
‣
‣
‣
‣
35
OpenAPIを利用したPythonWebアプリケーション開発
‣
‣
‣
37
‣
‣
‣
38
Backend
ServerFrontend
API
Other
ServiceAPI
Kabuku Connect
Other
Service
OpenAPI OpenAPI
‣
‣
‣
39
Backend
ServerFrontend
API
Kabuku Connect
OpenAPI
Other
ServiceAPI
Other
Service
OpenAPI
Swagger codegen Swagger UI bravado-core
‣
40
BackendFrontend
API
Kabuku Connect
OpenAPI
Other
ServiceAPI
Other
Service
OpenAPI
Swagger codegen Swagger UI
‣
‣
‣
‣
‣
‣
‣
‣
41
‣
‣
‣
‣
‣
‣
42
OpenAPIを利用したPythonWebアプリケーション開発
‣
‣
‣
44
So Hot!!
‣
‣
‣
‣
‣
‣
45
‣
‣
‣
‣
46
‣
‣
‣
‣
‣
47
http://www.kabuku.co.jp/#jobs

More Related Content

PDF
Linux女子部 systemd徹底入門
PDF
Pythonの処理系はどのように実装され,どのように動いているのか? 我々はその実態を調査すべくアマゾンへと飛んだ.
PPTX
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
PDF
JIT のコードを読んでみた
PPTX
Java 9で進化する診断ツール
PDF
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
PDF
從線上售票看作業系統設計議題
PDF
Unified JVM Logging
Linux女子部 systemd徹底入門
Pythonの処理系はどのように実装され,どのように動いているのか? 我々はその実態を調査すべくアマゾンへと飛んだ.
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
JIT のコードを読んでみた
Java 9で進化する診断ツール
ツール比較しながら語る O/RマッパーとDBマイグレーションの実際のところ
從線上售票看作業系統設計議題
Unified JVM Logging

What's hot (20)

PDF
今日からできる!簡単 .NET 高速化 Tips
PDF
WebSocket / WebRTCの技術紹介
PPTX
PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~
PDF
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
PPTX
Metaspace
PPT
Glibc malloc internal
PDF
.NET Core 3.0時代のメモリ管理
PDF
ARM Trusted FirmwareのBL31を単体で使う!
PDF
Go入門
ODP
スレッドダンプの読み方
PPTX
Java Crash分析(2012-05-10)
PDF
最適なOpenJDKディストリビューションの選び方 #codetokyo19B3 #ccc_l5
PPTX
コンテナネットワーキング(CNI)最前線
PPTX
Rootlessコンテナ
PPTX
9/14にリリースされたばかりの新LTS版Java 17、ここ3年間のJavaの変化を知ろう!(Open Source Conference 2021 O...
PDF
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
PDF
C言語なWebSocketの遊び方。
PDF
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
PDF
JavaでWebサービスを作り続けるための戦略と戦術 JJUG-CCC-2018-Spring-g1
PDF
JavaScript難読化読経
今日からできる!簡単 .NET 高速化 Tips
WebSocket / WebRTCの技術紹介
PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~
CEDEC 2018 最速のC#の書き方 - C#大統一理論へ向けて性能的課題を払拭する
Metaspace
Glibc malloc internal
.NET Core 3.0時代のメモリ管理
ARM Trusted FirmwareのBL31を単体で使う!
Go入門
スレッドダンプの読み方
Java Crash分析(2012-05-10)
最適なOpenJDKディストリビューションの選び方 #codetokyo19B3 #ccc_l5
コンテナネットワーキング(CNI)最前線
Rootlessコンテナ
9/14にリリースされたばかりの新LTS版Java 17、ここ3年間のJavaの変化を知ろう!(Open Source Conference 2021 O...
Javaコードが速く実⾏される秘密 - JITコンパイラ⼊⾨(JJUG CCC 2020 Fall講演資料)
C言語なWebSocketの遊び方。
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
JavaでWebサービスを作り続けるための戦略と戦術 JJUG-CCC-2018-Spring-g1
JavaScript難読化読経
Ad

More from Takuro Wada (9)

PDF
20170830 euro python_2017_report
PDF
OpenAPI development with Python
PDF
株式会社カブク システム開発最前線
PDF
3D Modeling and Printing by Python
PDF
Blenderで作成したデータをMinecraftにぶっこむ
PDF
3Dプリント×Python ~コードからアプローチする3Dプリンティング~
PDF
3D Modeling by Python scripts
PDF
20151101 blender python_3dprint
PDF
3D Printing by Python scripts and Blender
20170830 euro python_2017_report
OpenAPI development with Python
株式会社カブク システム開発最前線
3D Modeling and Printing by Python
Blenderで作成したデータをMinecraftにぶっこむ
3Dプリント×Python ~コードからアプローチする3Dプリンティング~
3D Modeling by Python scripts
20151101 blender python_3dprint
3D Printing by Python scripts and Blender
Ad

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Well-logging-methods_new................
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPT
Mechanical Engineering MATERIALS Selection
PDF
Digital Logic Computer Design lecture notes
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
CH1 Production IntroductoryConcepts.pptx
OOP with Java - Java Introduction (Basics)
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Geodesy 1.pptx...............................................
Lecture Notes Electrical Wiring System Components
Arduino robotics embedded978-1-4302-3184-4.pdf
Internet of Things (IOT) - A guide to understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Model Code of Practice - Construction Work - 21102022 .pdf
Well-logging-methods_new................
CYBER-CRIMES AND SECURITY A guide to understanding
UNIT 4 Total Quality Management .pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Mechanical Engineering MATERIALS Selection
Digital Logic Computer Design lecture notes
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Foundation to blockchain - A guide to Blockchain Tech
CH1 Production IntroductoryConcepts.pptx

OpenAPIを利用したPythonWebアプリケーション開発