kubernetes-client / c

Official C client library for Kubernetes
Apache License 2.0
141 stars 45 forks source link

Incompatibility of function names between v1_service_port.h and v1_service_port.c? #122

Closed petitlapin closed 1 year ago

petitlapin commented 2 years ago

Hi,

It seems the conversion from/to string differ in functions names: https://github.com/kubernetes-client/c/blob/7291d0a3c3e4802a19bce56e45d94b27150d8f5f/kubernetes/model/v1_service_port.h:

char* v1_service_port_protocol_ToString(kubernetes_v1_service_port_PROTOCOL_e protocol);
kubernetes_v1_service_port_PROTOCOL_e v1_service_port_protocol_FromString(char* protocol);

https://github.com/kubernetes-client/c/blob/7291d0a3c3e4802a19bce56e45d94b27150d8f5f/kubernetes/model/v1_service_port.c:

char* protocolv1_service_port_ToString(kubernetes_v1_service_port_PROTOCOL_e protocol) { ... }
kubernetes_v1_service_port_PROTOCOL_e protocolv1_service_port_FromString(char* protocol){ ... }

There is a protocol in the .c file that is not placed at the same place in the .h

If it's not generated code, I can do a PR to fix it to v1_service_port_protocol_FromString and v1_service_port_protocol_ToString if needed

ityuhui commented 2 years ago

Thank you for reporting this issue ! This code is generated by the template file https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/C-libcurl/model-body.mustache But the template fails to generate the string and enum data type.

I'll take a look at this issue. But the priority is not high because the functions protocolv1_service_port_ToString and protocolv1_service_port_FromString are called correctly.

Welcome to investigation and contribution !

petitlapin commented 2 years ago

Thank you!

I'll take a look at this issue. But the priority is not high because the functions protocolv1_service_port_ToString and protocolv1_service_port_FromString are called correctly.

The issue is when we want to call these functions from another executable (if the function is supposed to be public): if we call: v1_service_port_protocol_FromString declared in the .h, the linker will complain because the implementation does not exist. And if we call protocolv1_service_port_FromString, as there is no declaration of this function (except in the .c we don't include), it does not compile.

For now, I've workarounded it by duplicating the function so it's not blocking too.

ityuhui commented 2 years ago

Your workaround is OK. These two functions can be called externally, although they are intended to be used internally.

ityuhui commented 1 year ago

This issue is gone because the data type of io.k8s.api.core.v1.ServicePort/protocol is changed to string in the Kubernetes v1.24 API Spec