swagger-api / swagger-api/swagger-codegen
[PHP] additionalProperties in referenced model ignored
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
If I use a reference in a response object for a property, additionalProperties are ignored.
It works fine, when I include it directly.
When I explicitly define some additional properties, those are extracted as well (in both approaches), just the additional Properties are not
Swagger-codegen version
2.3.1
Swagger declaration file content or url
Not working as expected
swagger: '2.0'
info:
title: test
version: 1.0.0
paths:
/response.json:
get:
operationId: listOperations
responses:
'200':
description: just a test
schema:
type: object
additionalProperties:
$ref: "#/definitions/some_definition"
definitions:
some_definition:
description: Some values
additionalProperties: {}
type: object
Working as expected:
swagger: '2.0'
info:
title: test
version: 1.0.0
paths:
/response.json:
get:
operationId: listOperations
responses:
'200':
description: just a test
schema:
type: object
additionalProperties:
description: Some values
additionalProperties: {}
type: object
Response JSON:
{
"hello": {
"world": "and all",
"description": "a bar test"
},
"lala": {
"anotherone": "and all"
}
}
Command line used for generation
`swagger-codegen generate -i http://localhost/swagger.yaml -l php
Steps to reproduce
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$apiInstance = new Swagger\Client\Api\DefaultApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
);
$result = $apiInstance->listOperations();
print_r($result);
Should return an Array with all values (or a model with all values), does return Swagger\Client\Model\SomeDefinition with just the explicitly defined properties (if such are defined)
Suggest a fix/enhancement
I don't know where/why that happened and if it's intended behaviour or not. If you need more information, I'm happy to provide those.
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 supplied Swagger YAML through swagger-codegen generate with the php language and inspect the generated SomeDefinition response model. Trace how additionalProperties is handled when its schema is a $ref versus an inline object. Done means the generated PHP client preserves arbitrary properties from the referenced model, not only explicitly defined ones.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100