Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenAPIでAPI GatewayのモックAPIを作り、コード不要のAPIテストツール D...

boiyama
October 02, 2017

OpenAPIでAPI GatewayのモックAPIを作り、コード不要のAPIテストツール Dreddでテスト

We Are JavaScripters! @12th
https://wajs.connpass.com/event/66223/
用の資料です

boiyama

October 02, 2017
Tweet

More Decks by boiyama

Other Decks in Programming

Transcript

  1. O p e n A P I Ͱ A P

    I G a t e w a y ͷ Ϟ ο Ϋ A P I Λ ࡞ Γ ɺ ί ʔ υ ෆ ཁ ͷ A P I ςε τπ ʔϧ D re d d Ͱ ςε τ 2 0 1 7 . 1 0 . 2 We A re J a v a S c r i p t e r s ! # 1 2 @ M i c ro s o f t
  2. YA M A M O T O ’s P ro

    f i l e • @boiyaa
 (Twitter: @boiyaaaaaa) • ถFacebookΤϯδχΞ • ͷఋΛ࣋ͭߴଔΤϯδχΞ • ύʔιϧϓϩηεˍςΫϊϩ δʔ (PPT)
  3. ͜Μͳߏ੒Ͱࢼͯ͠Έͨ s w a g g e r. j s

    o n A m a z o n A P I G a t e w a y APIఆ͔ٛΒ
 ϞοΫAPI࡞੒ APIఆٛͰ
 ςετ
  4. S w a g g e r Ͱ A P

    I G a t e w a y Λ ࡞ Δ ͱΓ͋͑ͣී௨ʹॻ͍ͯΠϯϙʔτ͢Ε͹ɺ
 Ϧιʔεͱϝιου͸࡞ΒΕΔ͕ɺ
 APIͱͯ͠ಈ͔͢ʹ͸ઃఆ͕଍Γͳ͍ ↓ ϝιουఆٛʹAPI Gateway֦ு࢓༷ͷ
 x-amazon-apigateway-integrationΛ௥Ճ͢Δ
  5. s w a g g e r. j s o

    n " / a r t i c l e s " : { " g e t " : { " t a g s " : [ " A r t i c l e " ] , " s u m m a r y " : " L i s t a r t i c l e s " , " r e s p o n s e s " : { " 2 0 0 " : { " d e s c r i p t i o n " : " s u c c e s s f u l o p e r a t i o n " , " s c h e m a " : { " t y p e " : " a r r a y " , " i t e m s " : { " $ r e f " : " # / d e f i n i t i o n s / A r t i c l e " } } } } , " x - a m a z o n - a p i g a t e w a y - i n t e g r a t i o n " : { " t y p e " : " m o c k " , " r e q u e s t T e m p l a t e s " : { " a p p l i c a t i o n / j s o n " : " { \ " s t a t u s C o d e \ " : 2 0 0 } " } , " r e s p o n s e s " : { " d e f a u l t " : { " s t a t u s C o d e " : " 2 0 0 " , " r e s p o n s e T e m p l a t e s " : { " a p p l i c a t i o n / j s o n " : " [ { \ " i d \ " : 1 , \ " t i t l e \ " : \ " a r t i c l e 1 \ " } ] " } } } } } , ී௨ͷఆٛ API Gateway༻ ͷఆٛ
  6. Ϟ ο Ϋ A P I Λ ୟ ͍ͯ Έ

    Δ $ c u r l - i h t t p s : / / a p i . e x a m p l e . c o m / a r t i c l e s H T T P / 1 . 1 2 0 0 O K C o n t e n t - T y p e : a p p l i c a t i o n / j s o n C o n t e n t - L e n g t h : 3 4 C o n n e c t i o n : k e e p - a l i v e D a t e : S u n , 0 1 O c t 2 0 1 7 2 2 : 3 1 : 4 3 G M T x - a m z n - R e q u e s t I d : X - C a c h e : M i s s f r o m c l o u d f r o n t V i a : 1 . 1 X - A m z - C f - I d : [ { " i d " : 1 , " t i t l e " : " a r t i c l e 1 " } ]
  7. D re d d Λ Π ϯε τ ʔϧ ͢

    Δ $ n p m i n s t a l l - g d r e d d D re d d ͸ C o ff e e S c r i p t ੡ ※ ຊ ೔ ། Ұ ͷ J S ཁ ૉ
  8. D re d d Λ ࣮ ߦ ͢ Δ $

    d r e d d s w a g g e r . j s o n h t t p s : / / a p i . e x a m p l e . c o m i n f o : B e g i n n i n g D r e d d t e s t i n g . . . p a s s : G E T ( 2 0 0 ) / a r t i c l e s d u r a t i o n : 1 4 3 m s c o m p l e t e : 1 p a s s i n g , 0 f a i l i n g , 0 e r r o r s , 0 s k i p p e d , 1 t o t a l c o m p l e t e : T e s t s t o o k 1 4 3 m s
  9. A P I G a t e w a y

    ͸ 2 0 4 Ͱ ΋ C o n t e n t - Ty p e Λ ฦ ͢ 
 σ ϑ Υϧ τ ͷ a p p l i c a t i o n / j s o n ͷ · · ͩ ͱ J S O N ύʔε Τϥ ʔ ͕ ى ͖ Δ $ d r e d d s w a g g e r . j s o n h t t p s : / / a p i . e x a m p l e . c o m f a i l : b o d y : R e a l b o d y " C o n t e n t - T y p e " h e a d e r i s " a p p l i c a t i o n / j s o n " b u t b o d y i s n o t a p a r s a b l e J S O N . P a r s e e r r o r o n l i n e 1 : ^ E x p e c t i n g ' S T R I N G ' , ' N U M B E R ' , ' N U L L ' , ' T R U E ' , ' F A L S E ' , ' { ' , ' [ ' , g o t ' E O F '
  10. υ Ω ϡ ϝ ϯ τ ͷ ํ ๏ Ͱ

    C o n t e n t - Ty p e Λ t e x t / p l a i n ʹ ม ߋ ͢ Δ ͱ ɻ ɻ " p r o d u c e s " : [ " t e x t / p l a i n " ] , " r e s p o n s e s " : { " 2 0 4 " : { " d e s c r i p t i o n " : " s u c c e s s f u l o p e r a t i o n " , " s c h e m a " : { " $ r e f " : " # / d e f i n i t i o n s / E m p t y " } } } , " x - a m a z o n - a p i g a t e w a y - i n t e g r a t i o n " : { " t y p e " : " m o c k " , " r e q u e s t T e m p l a t e s " : { " a p p l i c a t i o n / j s o n " : " { \ " s t a t u s C o d e \ " : 2 0 4 } " } , " r e s p o n s e s " : { " d e f a u l t " : { " s t a t u s C o d e " : " 2 0 4 " , " r e s p o n s e T e m p l a t e s " : { " t e x t / p l a i n " : " " } } } }
  11. D re d d ͸ s c h e m

    a ͕ ઃ ఆ ͞ Εͯ ͍ Δ ͱ a p p l i c a t i o n / j s o n Ͱ ͳ ͍ ͱ ςε τ Ͱ ͖ ͳ ͍ $ d r e d d s w a g g e r . j s o n h t t p s : / / a p i . e x a m p l e . c o m f a i l : b o d y : C a n ' t v a l i d a t e r e a l m e d i a t y p e ' t e x t / p l a i n ' a g a i n s t e x p e c t e d m e d i a t y p e ' a p p l i c a t i o n / s c h e m a + j s o n ' .
  12. ϔο μ Ϛ ο ϐ ϯ ά Ͱ t e

    x t / p l a i n ʹ ม ߋ ͢ Δ ɻ " r e s p o n s e s " : { " 2 0 4 " : { " d e s c r i p t i o n " : " s u c c e s s f u l o p e r a t i o n " , " h e a d e r s " : { " C o n t e n t - T y p e " : { " t y p e " : " s t r i n g " , " x - e x a m p l e " : " t e x t / p l a i n " } } } } , " x - a m a z o n - a p i g a t e w a y - i n t e g r a t i o n " : { " t y p e " : " m o c k " , " r e q u e s t T e m p l a t e s " : { " a p p l i c a t i o n / j s o n " : " { \ " s t a t u s C o d e \ " : 2 0 4 } " } , " r e s p o n s e s " : { " d e f a u l t " : { " s t a t u s C o d e " : " 2 0 4 " , " r e s p o n s e P a r a m e t e r s " : { " m e t h o d . r e s p o n s e . h e a d e r . C o n t e n t - T y p e " : " ' t e x t / p l a i n ' " } , " r e s p o n s e T e m p l a t e s " : { " t e x t / p l a i n " : " " } } } }
  13. Α ͏ ΍ ͘ ௨ Δ $ d r e

    d d s w a g g e r . j s o n h t t p s : / / a p i . e x a m p l e . c o m i n f o : B e g i n n i n g D r e d d t e s t i n g . . . p a s s : G E T ( 2 0 0 ) / a r t i c l e s d u r a t i o n : 1 4 3 m s p a s s : P O S T ( 2 0 0 ) / a r t i c l e s d u r a t i o n : 6 3 m s p a s s : O P T I O N S ( 2 0 4 ) / a r t i c l e s d u r a t i o n : 1 1 9 m s p a s s : D E L E T E ( 2 0 4 ) / a r t i c l e s / 1 d u r a t i o n : 5 6 m s c o m p l e t e : 4 p a s s i n g , 0 f a i l i n g , 0 e r r o r s , 0 s k i p p e d , 4 t o t a l c o m p l e t e : T e s t s t o o k 3 8 9 m s