OpenAPITools / OpenAPITools/openapi-generator

PHP model field validation broken on oneOf

Open
#12,721 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description
 bar:
      properties:
        field:
          type: string
          enum: [a,b]
 ray:
      properties:
        field:
          type: string
          enum: [c,d]

MyObject:
      properties:
        foo:
          type: array
          items:
            oneOf:
              - $ref: '#/components/schemas/bar'
              - $ref: '#/components/schemas/ray'
              ```

ObjectSerializer::deserialize (src/Http/ObjectSerializer.php:478) fails:

getFieldAllowableValues & getOperatorAllowableValues do not combine all options and validation fails.

It instead only uses enum values from the last item (ray) for validation

##### openapi-generator version

Latest

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/Http/ObjectSerializer.php:478 and inspect getFieldAllowableValues and getOperatorAllowableValues during deserialization of the shown oneOf array schema. Reproduce validation with bar and ray, then verify that allowable enum values from both options are accepted rather than only ray's values.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, php
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.