Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

allOf validation not working?

未关闭
#120 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
需要澄清
活跃度
停滞
技术栈
openapi, php
领域
api

调研方向

使用提供的 OpenAPI 文档以及 Cat schema 对 Pet 的 allOf 引用,重现针对 /pets 的 JSON PATCH 请求。跟踪 validator 如何解析 Pet 及其继承的 pet_type 属性,然后确定该请求是否被接受,或者验证为何拒绝该请求。issue 中没有指定项目文件或测试。

由索引模型根据 Issue 内容生成。

描述

good first issue hacktoberfest help wanted

Hi, I'm having issues getting an example spec using allOf to work. This is the spec, as provided by the OpenAPI docs:

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:

[
    'pet_type' => 'Cat',
    'age' => 3,
    'hunts' => true,
]

However, this only results in:

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.

主要语言
PHP
星标
500
派生
99
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

cebe/php-openapi 的其他 Issue

查看 cebe/php-openapi 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。