Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Empty additionalProperties object is generated as an array #700

@Rid

Description

@Rid

Jane version(s) affected: 7.4.1
Description
When the OpenAPI v3 spec is as so:

          "ExposedPorts": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {}
            },
            "description": "An object mapping ports to an empty object in the form:\n\n`{\"<port>/<tcp|udp|sctp>\": {}}`\n"
          },

Empty additionalProperties are generated as an array rather than an object in the normalizer, whereas the denormalizer correctly creates an object.

How to reproduce
See above.

Possible Solution
additionalProperties normalizer and denormalizer should be the same.

Additional context
Here is the generated code:

Normalizer:
https://github.com/beluga-php/docker-php-api/blob/0082dac1f074aa56abe82d6f18aebb5823559921/src/Normalizer/ContainersCreatePostBodyNormalizer.php#L245-L251

        if (null !== $object->getExposedPorts()) {
            $values = [];
            foreach ($object->getExposedPorts() as $key => $value) {
                $values[$key] = $this->normalizer->normalize($value, 'json', $context);
            }
            $data['ExposedPorts'] = $values;
        }

Denormalizer:
https://github.com/beluga-php/docker-php-api/blob/0082dac1f074aa56abe82d6f18aebb5823559921/src/Normalizer/ContainersCreatePostBodyNormalizer.php#L80-L85

        if (\array_key_exists('ExposedPorts', $data) && null !== $data['ExposedPorts']) {
            $values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
            foreach ($data['ExposedPorts'] as $key => $value) {
                $values[$key] = $this->denormalizer->denormalize($value, 'Docker\\API\\Model\\ContainerConfigExposedPortsItem', 'json', $context);
            }
            $object->setExposedPorts($values);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions