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

【codegen は難しくない】Swagger から JavaScript ( TypeScr...

wakamsha
March 09, 2018

【codegen は難しくない】Swagger から JavaScript ( TypeScript ) コードを自動生成してコーディングを効率化しよう

2018年3月8日『UIT#2 怠けるために努力を惜しまない プロのフロントエンドエンジニアたち』と
2018年3月9日『Gotanda.js #10』にて発表した資料です。

- https://uit.connpass.com/event/79891/
- https://gotandajs.connpass.com/event/79724/

#uit_2
#gotandajs

wakamsha

March 09, 2018
Tweet

More Decks by wakamsha

Other Decks in Technology

Transcript

  1. ϘΠϥʔϓϨʔτ w ϘΠϥʔϓϨʔτఆܕతͳίʔυ w ΞϓϦέʔγϣϯ։ൃΛ͍ͯ͠Δͱ͠͹͠͹ૺ۰͕ͪ͠ w XFCΞϓϦέʔγϣϯ։ൃͩͱ 3&45 "1*ΫϥΠΞϯτ ૄ௨෦෼

     w 5ZQF4DSJQUͳΒ"1*ϦΫΤετϨεϙϯεΦϒδΣΫτͷܕఆٛϑΝΠϧ w ͜ΕΒ͸ΞϓϦέʔγϣϯن໛ʹൺྫͯ͠૿͍͑ͯ͘
  2. openapi: 3.0.1 paths: /pets: get: summary: Get pet list operationId:

    pets/index tags: - pets responses: $ref: '#/components/responses/PetsIndex' post: summary: Create new pet operationId: Pets/create tags: - pets requestBody: $ref: '#/components/requestBodies/PetsCreate' responses: $ref: '#/components/responses/PetsCreate' components: schemas: Pet: type: object required: - id - name properties: id: type: integer format: int32 Swagger Spec
  3. responses: $ref: '#/components/responses/PetsIndex' post: summary: Create new pet operationId: Pets/create

    tags: - pets requestBody: $ref: '#/components/requestBodies/PetsCreate' responses: $ref: '#/components/responses/PetsCreate' components: schemas: Pet: type: object required: - id - name properties: id: type: integer format: int32 name: type: string responses: PetsIndex: '200': content: application/json: schema: $ref: '#/components/schemas/PetsResponse' PetsCreate: Swagger Spec
  4. - name properties: id: type: integer format: int32 name: type:

    string responses: PetsIndex: '200': content: application/json: schema: $ref: '#/components/schemas/PetsResponse' PetsCreate: '201': content: application/json: schema: $ref: '#/components/schemas/AnyContent' requestBodies: PetsCreate: required: true content: application/json: schema: $ref: '#/components/schemas/PetsCreate' Swagger Spec
  5. { name: "Pet", properties: [ { name: "id", type: "number",

    description: "id of pet", optional: false } ], description: "Pet" } TS TS YAML JSON
  6. { name: "Pet", properties: [ { name: "id", type: "number",

    description: "id of pet", optional: false } ], description: "Pet" } TS TS YAML JSON 4XBHHFS6*͔Β4QFDϑΝΠϧΛμ΢ϯϩʔυ +40/ϑΝΠϧͳΒͦͷ·· :".-ͳΒ+40/΁ஔ׵͢Ε͹0,
  7. { name: "Pet", properties: [ { name: "id", type: "number",

    description: "id of pet", optional: false } ], description: "Pet" } TS TS YAML JSON 4QFD͔Βཉ͍͠஋Λநग़ͯ͠੔ܗ جຊతʹObject.keysؔ਺Λ࢖͍·͘Δ -PEBTIKT΍3BNEBKTͷΑ͏ͳίϨΫγϣϯૢ࡞ܥϥΠϒϥϦΛ࢖͏ͷ͕ ͓͢͢Ί
  8. { name: "Pet", properties: [ { name: "id", type: "number",

    description: "id of pet", optional: false } ], description: "Pet" } TS TS YAML JSON ੔ܗͨ͠஋͔Β※.js (※.ts) ϑΝΠϧΛੜ੒ ஋ΛNVTUBDIFςϯϓϨʔτʹྲྀ͠ࠐΉ͚ͩ /PEFKTͷ'JMF4USFBN"1*Λ࢖ͬͯϑΝΠϧੜ੒