Core: Swagger UI always adds `"additionalProp1": {}` to the example value

Created on 5 Dec 2020  路  8Comments  路  Source: api-platform/core

API Platform version(s) affected: 2.6.0 alpha

Description

image

How to reproduce
Just install the distribution. It does that on any class mapped with API Resource.

Possible Solution

We have no occurrences of additionalProp1 in our code base, but they are occurences in Swagger UI's code base. It maybe caused by our generated JSON Schema (https://github.com/api-platform/core/blob/master/src/JsonSchema/SchemaFactory.php) or by a bug in Swagger UI.

Most helpful comment

FYI I am getting this issue too, but with version api-platform/core (v2.5.8)
It was not occurring with v2.5.7

All 8 comments

FYI I am getting this issue too, but with version api-platform/core (v2.5.8)
It was not occurring with v2.5.7

I could not find documentation on why this was added but every schema now has additionalProperties set to true so it would make sense for the GUI to add something. See: https://github.com/api-platform/core/commit/cf6942327854c7cc3ac7363b26426b6352023d81

We got rid of it by setting allow_extra_attributes within the normalizationContext.

/**
 * @ApiResource(
 *     normalizationContext={
 *          "allow_extra_attributes"=false
 *     },
 *     collectionOperations={},
 *     itemOperations={}
 * )
 */

Having this same problem on api-platform/core (v2.5.8). I guess allow_extra_attribute should be set to false globally or something?Don't even know why this was added.

Closed by #3888.

Hi team! I'm still getting the error, api-platform v2.5.8, I just double-check with a fresh new installation and it is still there the additionalProp1 ... any solution to this?? Cheers!

Please use the dev version (for now): "api-platform/core": "2.5.x-dev"

I have the same problem, it is somewhat annoying when providing the documentation of my api to external clients, reading the thread I did not understand which is the correct solution to address, if "allow_extra_attributes" = false which becomes something tedious and repetitive of do or use the dev version which I don't think is advisable for a project that adds new functionalities while it is already in production.

@juanpablomorenomartin the fix is to upgrade to the 2.5-dev (which is very stable), as pointed out by @alanpoulain, or to wait for the next tag (probably beginning of January).

Was this page helpful?
0 / 5 - 0 ratings