Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposed ports is array when should be object #6

Closed
Rid opened this issue Feb 16, 2023 · 8 comments
Closed

Exposed ports is array when should be object #6

Rid opened this issue Feb 16, 2023 · 8 comments

Comments

@Rid
Copy link
Member

Rid commented Feb 16, 2023

Currently investigating this:

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

As it causes a Error ContainerCreateInternalServerErrorException: json: cannot unmarshal array into Go struct field ContainerConfigWrapper.ExposedPorts of type struct {} error because the generated json is:

"ExposedPorts":{"10012/tcp":[],"80/tcp":[]}

When it should be

"ExposedPorts":{"10012/tcp":[],"80/tcp":{}}

The swagger is

          "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"
          },

So I'm not sure why janephp isn't generating this as the same as the denormalizer?

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);

I'll open an issue with janephp if needed, just checking if you've already spotted this?

@Rid
Copy link
Member Author

Rid commented Feb 16, 2023

Opened an issue here janephp/janephp#700

@flavioheleno
Copy link
Member

hey @Rid thank you very much for your help all around! let's take the dust off of this project and make it work properly!
I'm currently looking at some alternatives for having minor patches to fix such issues in this repository (prior to tagging a version), while support from Jane is in the works (same goes for other issues).
What do you think?

@Rid
Copy link
Member Author

Rid commented Feb 16, 2023

@flavioheleno I have a version working locally, only #3 and this issue need to be patched manually in the generated code (although I haven't tested every API endpoint). Do you want me to make a PR with the needed client changes?

@flavioheleno
Copy link
Member

I'd like to have those changes as .patch files in a folder, so when we run the build step, they get applied before running the lint, so that they don't get lost between updates.
Can you start a PR with those patches on a dedicated folder while I work the automation?

@Rid
Copy link
Member Author

Rid commented Feb 16, 2023

@flavioheleno I've made a PR, I've also added automation via composer for applying the patches

@Rid
Copy link
Member Author

Rid commented Feb 16, 2023

Looking at the API reference we're going to need a few more patches, basically anywhere we return an object we need to initialise it with

$values = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);

As if the object is empty, it will return an empty array, this is the same for parent objects and nested.

I'll go through the API in a few days and add the patch where needed and update the patch set.

@Rid
Copy link
Member Author

Rid commented Feb 16, 2023

Is it possible for you to add me to the repository so I can commit directly?

@flavioheleno
Copy link
Member

that's weird, I thought Jane was already generating the proper code for that.

I'll add you as a contributor

@Rid Rid closed this as completed Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants