5G-MAG / rt-common-shared

Tools common to various projects
Other
3 stars 7 forks source link

Move openapi-generator C templates from 5GMS AF into common area #31

Closed davidjwbbc closed 8 months ago

davidjwbbc commented 8 months ago

The 5GMS Application Function (rt-5gms-application-function) contains a set of templates for converting the OpenAPI YAML APIs into C structures and enums along with relevant functions to aid in manipulation of these structures or enums.

The work on the Data Collection library and AF will also need to use these templates.

This PR covers the rt-common-shared side of the move of the openapi-generator templates from the 5GMS AF to the rt-common-shared repository for reuse.

This move also includes an enhancement to the conversion of enum types as detailed in the table below.

What Old Behaviour New Behaviour
Enumeration values Use format: {enum_name}_{VALUE_NAME} Use format: {enum_name}_VAL_{VALUE_NAME}
The {enum_name}_FromString() function Returns the value {enum_name}_NULL for unrecognised strings or the NULL pointer Returns the value {enum_name}_NULL if the string was a NULL pointer, and returns -1 for unrecognised strings
The {enum_name}_ToString() function Returns:
  • "{value}" if the value is {enum_name}_{value} (including NULL)
  • "Unknown" if the value is past the end of the enum value range
  • Performs an out of bounds array lookup if a negative value is passed in, possibly causing a SEGFAULT
Returns:
  • "" if the value is {enum_name}_NULL
  • "{value}" if the value is {enum_name}_VAL_{value}
  • "" if the value is outside the enum value range
davidjwbbc commented 8 months ago

The addition of the "_VAL" into the values of enums is to cope with the DataAggregationFunctionType enum which contains a "NULL" value in the enum which would clash with the default NULL value added by the openapi-generator template. The new template gives:

typedef enum {
    dcaf_api_data_aggregation_function_type_NULL = 0,
    dcaf_api_data_aggregation_function_type_VAL_NULL,
    dcaf_api_data_aggregation_function_type_VAL_COUNT,
    dcaf_api_data_aggregation_function_type_VAL_MEAN,
    dcaf_api_data_aggregation_function_type_VAL_MAXIMUM,
    dcaf_api_data_aggregation_function_type_VAL_MINIMUM,
    dcaf_api_data_aggregation_function_type_VAL_SUM
} dcaf_api_data_aggregation_function_type_e;

This now have a different value for the "NULL" value and the NULL value.

rjb1000 commented 8 months ago

Sorry. Coming a bit late to the party.

@davidjwbbc: I think these templates should live at the top level of the repository rather than under 5gms/ since they are shared with projects that aren't necessarily to do with 5G Media Streaming.

rjb1000 commented 8 months ago

We should promote this move on Friday's call to ensure that everyone is aware.