Failures in oneOf, anyOf, etc, are actually in the referenced schema

オープン
#126 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
docker, openapi, python
領域
api, testing-qa

調査の方向性

Reproduce the issue with the provided OpenAPI YAML and the shown Docker command, then trace how validation handles oneOf and anyOf references. The fix is done when an invalid referenced Dog schema produces an error at components.schemas.Dog rather than at the containing oneOf or requestBody.

索引モデルが issue の本文から書いたものです。

説明

If a schema is invalid, it will cause a oneOf to fail instead of failing on its own. I discovered this while thinking optional was a valid thing.

The below is valid except I've added optional to Dog. The failure is now On instance['paths']['/pets']['patch']['requestBody'] instead of the expected ['components']['schemas']['Dog'].

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/Cat'
                  - $ref: '#/components/schemas/Dog'
components:
  schemas:
    Dog:
      type: object
      optional: [ "bark" ]
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
$ docker run -v $PWD/simple.yaml:/openapi.yaml --rm p1c2u/openapi-spec-validator /openapi.yaml
{'content': {'application/json': {'schema': {'oneOf': [{'$ref': '#/components/schemas/Cat', 'x-scope': ['file:///openapi.yaml']}, {'$ref':'#/components/schemas/Dog', 'x-scope': ['file:///openapi.yaml']}]}}}} is not valid under any of the given schemas

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^\\/']['patternProperties']['^(get|put|post|delete|options|head|patch|trace)$']['properties']['requestBody']:                             
    {'oneOf': [{'$ref': '#/definitions/RequestBody'},
               {'$ref': '#/definitions/Reference'}]}

On instance['paths']['/pets']['patch']['requestBody']:
    {'content': {'application/json': {'schema': {'oneOf': [{'$ref': '#/components/schemas/Cat',
                                                            'x-scope': ['file:///openapi.yaml']},
                                                           {'$ref': '#/components/schemas/Dog',
                                                            'x-scope': ['file:///openapi.yaml']}]}}}}
主要言語
Python
スター
409
フォーク
73
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-openapi/openapi-spec-validator のほかの issue

python-openapi/openapi-spec-validator の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。