コード日進月歩

しんくうの技術的な小話、メモ、つれづれ、など

OpenAPI3.0でバイナリ送付のエンドポイントを書く書き方

swaggerの書き方シリーズ。ユースケースとしては画像をアップロードするAPIなどの想定。

環境

openapi: 3.0.2

書き方

content:
  multipart/form-data:
    description: "画像登録するときのマルチパートフォーム情報"
    type: object
    properties:
      fileName:
        description: "ファイル名"
        type: string
        example: "example.png"
      image:
        description: "画像ファイル"
        type: string
        format: binary

という書き方でできる。 そうすると、Try it out でも画像ファイルの選択フォームが現れる

参考リンク