swagger-api / swagger-api/swagger-codegen
PHP Client doesn't seem to support anyOf with discriminator
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have the below spec and the generated php client doesn't seem to handle the combination of anyOf and discriminator. I see a property DISCRIMINATOR in the generated models but they're all null.
Swagger-codegen version
3.0.18, not sure if it's a regression
Swagger declaration file content or url
openapi: 3.0.0
info:
title: Foo
version: '1.0'
paths:
/api/v1/object:
get:
operationId: get-object
responses:
'200':
description: example
content:
application/json:
schema:
$ref: '#/components/schemas/ExampleResponse'
components:
schemas:
ObjectFoo:
type: object
required:
- value
- type
properties:
value:
type: integer
type:
type: string
ObjectBar:
type: object
required:
- type
properties:
value:
type: boolean
type:
type: string
ExampleResponse:
properties:
objects:
type: array
items:
anyOf:
- $ref: '#/components/schemas/ObjectFoo'
- $ref: '#/components/schemas/ObjectBar'
discriminator:
propertyName: type
Command line used for generation
I used brew to install codegen, command below:
swagger-codegen generate -i ./swagger-smol.yml -l php --config ./swagger-codegen/php-config.json -o ~/workspace/foo-client --git-user-id=foo --git-repo-id=foo
Steps to reproduce
Populate swagger-smol.yml with the above snippet and run the command above.
Related issues/PRs
I didn't find anything exactly like this but there are similar issues:
https://github.com/swagger-api/swagger-codegen/issues/4622
https://github.com/swagger-api/swagger-codegen/pull/3475
https://github.com/swagger-api/swagger-codegen/issues/4226
https://github.com/swagger-api/swagger-codegen/issues/4346
https://github.com/swagger-api/swagger-codegen/issues/3904
Suggest a fix/enhancement
Not sure...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the command against swagger-smol.yml with php-config.json and inspect the generated PHP models, especially their DISCRIMINATOR properties and handling of the ExampleResponse objects. Compare the generated result with the anyOf and discriminator declarations; done means the PHP client correctly distinguishes ObjectFoo and ObjectBar during response handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100