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

Swagger Codegen

7ff4e13a726b7e501a4b730e69b6c66c?s=47 wagyu298
March 03, 2017

Swagger Codegen

Swagger Codegen の使い方の簡単な説明です。

7ff4e13a726b7e501a4b730e69b6c66c?s=128

wagyu298

March 03, 2017
Tweet

Transcript

  1. Swagger Codegen @wagyu298

  2. 5-%3 w 4XBHHFSˠ3&45"1*ͷ࢓༷Λ:".-Ͱॻ͘΍ͭ w 4XBHHFS$PEFHFOˠ4XBHHFS:".-͔ΒίʔυΛ ੜ੒͢ΔϓϩάϥϜ w 4FSWFS4UVCͱ$MJFOU"1*Λੜ੒Ͱ͖Δ w 4FSWFS4UVC͸ແ͍ΑΓϚγϨϕϧɺ$MJFOU"1*͸ͦ

    ͷ··ӡ༻ʹ࢖͑Δ w .JDSPTFSWJDFͱ͔ΞϓϦ޲͚
  3. ࠃ಺ͷεϚϗͷ ࢖༻ঢ়گʹ͍ͭͯ

  4. ૯຿লฏ੒೥௨৴ར༻ಈ޲ௐࠪͷ݁Ռ

  5. ૯຿লฏ੒೥௨৴ར༻ಈ޲ௐࠪͷ݁Ռ

  6. ύιίϯͱ͔Φϫίϯ

  7. 4XBHHFS w 0QFO"1*ͷ͜ͱ w IUUQTXBHHFSJP w IUUQTXXXPQFOBQJTPSH w αϯϓϧIUUQQFUTUPSFTXBHHFSJPW TXBHHFSZBNM

    w 3&45"1*ఆٛϑΝΠϧΛ:".-Ͱهड़͠ɺωοτϫʔ Ϋӽ͠ʹ࢓༷Λ఻ൖͤͨ͞Γ͍ͨ͠ײ͡ͷ΍ͭ
  8. 0QFO*%Έͨ͘
 ແ͔ͬͨ͜ͱʹͳΓͦ͏ͳ
 ۭؾ͕ա෼ʹ͋Δ

  9. 9.-31$ʮ4XBHHFS͕΍ΒΕͨΑ͏ͩͳʜʯ 40"1ʮΫΫΫʜౕ͸࢛ఱԦͷதͰ΋࠷ऑʜʯ $03#"ʮਓؒ͝ͱ͖ʹෛ͚Δͱ͸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͹ IPNFCSFX͔ΒͷΠϯετʔϧͰ0,Ͱ͢ w IUUQTXBHHFSJPTXBHHFSDPEFHFO w

    IUUQTXBHHFSJPEPDT w IUUQTHJUIVCDPNTXBHHFSBQJTXBHHFSDPEFHFO
  16. ཁΔ΋ͷ w +BWB w Ϗϧυ͢ΔͳΒNWO NBWFO  w CSFXJOTUBMMNBWFOͰೖΓ·͢

  17. ཁΔ΋ͷ w 0QFO"1*Ͱ࢓༷Λهड़ͨ͠:".-ϑΝΠϧ w ࠓճ͸ެࣜͷαϯϓϧΛ࢖͍·͢

  18. :".-ϑΝΠϧΛऔಘ bash-3.2$ curl http://petstore.swagger.io/v2/swagger.yaml > swagger.yaml

  19. 4FSWFS4UVCͷ࡞੒ bash-3.2$ java -jar swagger-codegen-cli.jar generate -i swagger.yaml - l

    nodejs-server -o nodejs bash-3.2$ cd nodejs bash-3.2$ npm install bash-3.2$ node index.js Your server is listening on port 8080 (http://localhost:8080) Swagger-ui is available on http://localhost:8080/docs IUUQMPDBMIPTUWQFUͰΞΫηεͰ͖·͢
  20. J04$MJFOU"1*ͷ࡞੒ bash-3.2$ java -jar swagger-codegen-cli.jar generate -i swagger.yaml -l swift3

    -o PetShop -DprojectName=PetShop $PDPB1PETϥΠϒϥϦ1FU4IPQ"1*͕Ͱ͖·͢ "1*ݺͼग़͠͸"MBNPpSFͰ͢ "OESPJE͸WPMMFZͰ͢
  21. QPETQFD౳͕एׯݹ͍ͷͰ ͍͘͡Γ·͢ # Uncomment this line to define a global

    platform for your project # platform :ios, '9.0' target 'SwaggerExam' do # Comment this line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for SwaggerExam pod 'PetShopAPI', :path => '../PetShopAPI' target 'SwaggerExamTests' do inherit! :search_paths # Pods for testing end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '3.0' end end end end
  22. ʢ͕࣌ؒແ͍ͷͰʣ"1*Λݺ ͼग़ͯ͠ϩάදࣔ͠·͢ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?)

    -> Bool { // Override point for customization after application launch. PetShopAPI.basePath = "http://localhost:8080/v2" PetAPI.getPetById(petId: 12) { (pet, error) in if let error = error { print(error) return } guard let pet = pet else { return } print(pet.encodeToJSON()) } return true } *OGPQMJTUʹBQQUSBOTQPSUTFDVSJUZͷઃఆ͕ඞཁ
  23. 4FSWFS4UVCΛHPMBOHʹม ͑ͯΈ·͢ bash-3.2$ java -jar swagger-codegen-cli.jar generate -i swagger.yaml -l

    go-server -o go-server -DpackageName=petshop OPEFTFSWFSͱҟͳΓςετ༻ͷσʔλ͕ ؼͬͯ͜ͳ͍ͷͰΤϥʔʹͳΓ·͢
  24. ऴΘΓ