Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
Kabuku Inc.
Software Engineer
@taxpon
taxpon
http://takuro.ws
- Python, TypeScript, Go, DevOps
- EuroPython 2017, 2016, Py...
3
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
Docume...
‣
‣
‣
‣
15
‣
‣
‣
16
17
‣
‣
‣
‣
‣
‣
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:
     t...
‣
27
import yaml
from bravado_core.spec import Spec
# 1
with open('openapi.yaml', 'r') as f:
raw_spec = yaml.load(f)
# 2
s...
‣
28
validate_schema_object(spec, book, {})
Code
jsonschema.exceptions.ValidationError: 'id' is a required property
Failed...
‣
29
validate_schema_object(spec, book, {"id": 1, "title": 1})
Code
jsonschema.exceptions.ValidationError: 1 is not of typ...
‣
‣
30
from bravado_core.unmarshal import unmarshal_schema_object
book_obj = unmarshal_schema_object(
  spec, book,
  {"id...
‣
31
Book:
type: object
required: [id]
properties:
   id:
     type: integer
   title:
     type: string
   author:
     t...
‣
32
book_obj = unmarshal_schema_object(
  spec, book,
  {"id": 1,
"title": "Merchant of Venice",
"author": "William Shake...
‣
‣
‣
‣
‣
33
‣
‣
34
Book = spec.definitions['Book']
book_obj = Book(id=1, title="Merchant of Venice",
s
release_date=date(2017, 7, 11))...
‣
‣
‣
‣
‣
‣
35
‣
‣
‣
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 bra...
40
BackendFrontend
API
Kabuku Connect
OpenAPI
Other
ServiceAPI
Other
Service
OpenAPI
Swagger codegen Swagger UI
‣
‣
‣
‣
‣
‣
‣
‣
41
‣
‣
‣
‣
‣
‣
42
‣
‣
‣
44
So Hot!!
‣
‣
‣
‣
‣
‣
45
‣
‣
‣
‣
46
‣
‣
‣
‣
‣
47
http://www.kabuku.co.jp/#jobs
OpenAPIを利用したPythonWebアプリケーション開発
OpenAPIを利用したPythonWebアプリケーション開発
OpenAPIを利用したPythonWebアプリケーション開発
OpenAPIを利用したPythonWebアプリケーション開発
OpenAPIを利用したPythonWebアプリケーション開発
Próxima SlideShare
Cargando en…5
×

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

5.449 visualizaciones

Publicado el

PyConJP2017で発表した資料です。OpenAPIについては株式会社カブクのブログでも紹介しているので、ぜひご覧ください。(https://www.kabuku.co.jp/developers/open-api-introduction, https://www.kabuku.co.jp/developers/introduction-of-bravado-core)

Publicado en: Ingeniería
  • Sé el primero en comentar

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

  1. 1. 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
  2. 2. 3
  3. 3. 5 (https://www.openapis.org/about より一部改変引用)
  4. 4. ‣ ‣ ‣ ‣ ‣ ‣ ‣ 6
  5. 5. ‣ ‣ ‣ ‣ ‣ ‣ 7
  6. 6. 8 ‣ ‣ ‣ ‣ ‣
  7. 7. ‣ ‣ ‣ ‣ ‣ ‣ 9
  8. 8. 10
  9. 9. 11
  10. 10. ‣ ‣ ‣ 12 ちょっとややこしい…
  11. 11. 13
  12. 12. OpenAPI Specification Swagger Core Swagger Parser Swagger Codegen Swagger UI Swagger Editor 3rd Party Tools OpenAPI Document (YAML or JSON) べんり!
  13. 13. ‣ ‣ ‣ ‣ 15 ‣ ‣ ‣
  14. 14. 16
  15. 15. 17
  16. 16. ‣ ‣ ‣ ‣ ‣ ‣ 19
  17. 17. ‣ ‣ ‣ 20
  18. 18. ‣ ‣ 21 COREツール
  19. 19. ‣ ‣ ‣ 22 COREツール
  20. 20. ‣ 23 OpenAPI Doc Generate Swagger Codegen Input Multiple languages COREツール
  21. 21. ‣ ‣ ‣ 24
  22. 22. ‣ ‣ ‣ ‣ ‣ ‣ ‣ 25
  23. 23. ‣ 26 Book: type: object required: [id] properties:    id:      type: integer    title:      type: string    author:      type: string
  24. 24. ‣ 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)
  25. 25. ‣ 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
  26. 26. ‣ 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
  27. 27. ‣ ‣ 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
  28. 28. ‣ 31 Book: type: object required: [id] properties:    id:      type: integer    title:      type: string    author:      type: string    release_date:      type: string      format: date ]
  29. 29. ‣ 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
  30. 30. ‣ ‣ ‣ ‣ ‣ 33
  31. 31. ‣ ‣ 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
  32. 32. ‣ ‣ ‣ ‣ ‣ ‣ 35
  33. 33. ‣ ‣ ‣ 37
  34. 34. ‣ ‣ ‣ 38 Backend ServerFrontend API Other ServiceAPI Kabuku Connect Other Service OpenAPI OpenAPI ‣ ‣ ‣
  35. 35. 39 Backend ServerFrontend API Kabuku Connect OpenAPI Other ServiceAPI Other Service OpenAPI Swagger codegen Swagger UI bravado-core ‣
  36. 36. 40 BackendFrontend API Kabuku Connect OpenAPI Other ServiceAPI Other Service OpenAPI Swagger codegen Swagger UI ‣
  37. 37. ‣ ‣ ‣ ‣ ‣ ‣ ‣ 41
  38. 38. ‣ ‣ ‣ ‣ ‣ ‣ 42
  39. 39. ‣ ‣ ‣ 44 So Hot!!
  40. 40. ‣ ‣ ‣ ‣ ‣ ‣ 45
  41. 41. ‣ ‣ ‣ ‣ 46
  42. 42. ‣ ‣ ‣ ‣ ‣ 47 http://www.kabuku.co.jp/#jobs

×