LoginSignup
1
0

More than 5 years have passed since last update.

swagger スタブのresponseが空になる問題調査メモ

Posted at

swaggerの書き方によっては、スタブのレスポンスでデータが出力されないことがありました。

①$ref参照の中で、さらに$refを参照。

get:
  .....
responses:
"200":
  schema:
    $ref: "#/definitions/sampleAList"

definitions:
  sampleAList:
    type: object
    properties:
      resultAList:
        type: array
        items:
          type: object
          properties:
            aaaCd:
              type: string
            bbbCd:
              type: string
      resultBList: 
        $ref: "#/definitions/sampleBList"

  sampleBList:
    type: object
        ~~~   

⇒この場合、resultBListが空となる。
別のところで使用していても、毎回省略せずすべて書く必要がある。

②出力されない書き方例:$ref参照のtypeがarray。

get:
  .....
responses:
"200":
  schema:
    $ref: "#/definitions/sampleAList"

definitions:
  sampleAList:
      type: array
      items:
        properties:
         aaaCd:
           type: string
         bbbCd:
           type: string

⇒この場合、responseのbodyは空となる。
(設計書の表示としては問題ない)
sampleAListをtype: objectにするとスタブが生成される。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0