cebe / cebe/php-openapi

allOf validation not working?

オープン
#120 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
good first issue hacktoberfest help wanted
主要言語
PHP
スター
500
フォーク
99
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi, I'm having issues getting an example spec using `allOf` to work. This is the spec, as provided by the [OpenAPI docs](https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/):

```yml
openapi: 3.0.0
info:
title: AllOf.v1
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/pets:
patch:
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: pet_type
responses:
'200':
description: Updated
components:
schemas:
Pet:
type: object
required:
- pet_type
properties:
pet_type:
type: string
Dog: # "Dog" is a value for the pet_type property (the discriminator value)
allOf: # Combines the main `Pet` schema with `Dog`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Dog`
properties:
bark:
type: boolean
breed:
type: string
enum: [ Dingo, Husky, Retriever, Shepherd ]
Cat: # "Cat" is a value for the pet_type property (the discriminator value)
allOf: # Combines the main `Pet` schema with `Cat`-specific properties
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Cat`
properties:
hunts:
type: boolean
age:
type: integer
```
My test attempts to send a JSON `PATCH` request to the `/pets` endpoint, using:
```php
[
'pet_type' => 'Cat',
'age' => 3,
'hunts' => true,
]
```
However, this only results in:
```sh
Request body did not match provided JSON schema.
```
Digging in a bit more, it appears that the validator doesn't see the `pet_type` property it should be inheriting from the `Pet` component.

Any experience with this, or ideas? Thanks in advance.

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

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

提供された OpenAPI ドキュメントと、`Pet` を参照する `Cat` スキーマの `allOf` を使用して、`/pets` に対する JSON PATCH リクエストを再現します。validator が `Pet` と、そこから継承された `pet_type` プロパティをどのように解決するかを追跡し、そのうえでリクエストが受け入れられるか、またはバリデーションが拒否する理由を明らかにします。issue にはプロジェクトファイルやテストの名前はありません。

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

評価

技術スタック
openapi, php
領域
api
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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