[openapi] Add support for nullable fields

Depending on the OpenAPI yaml files, fields can be marked as "nullable".
Which means that the field can be either present, not present, or null.

This feature is important for example in SmContextUpdateData structure,
where many fields are described similar as the following:
This IE shall be included for the modification .... For deleting the
field, it shall contain the Null value.
This commit is contained in:
Bostjan Meglic 2023-10-05 13:39:14 +02:00 committed by Sukchan Lee
parent 7ea37ef618
commit 50464d174e
154 changed files with 2773 additions and 0 deletions

View file

@ -5,12 +5,16 @@
#include "usage_threshold_rm.h"
OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_create(
bool is_duration_null,
bool is_duration,
int duration,
bool is_total_volume_null,
bool is_total_volume,
long total_volume,
bool is_downlink_volume_null,
bool is_downlink_volume,
long downlink_volume,
bool is_uplink_volume_null,
bool is_uplink_volume,
long uplink_volume
)
@ -18,12 +22,16 @@ OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_create(
OpenAPI_usage_threshold_rm_t *usage_threshold_rm_local_var = ogs_malloc(sizeof(OpenAPI_usage_threshold_rm_t));
ogs_assert(usage_threshold_rm_local_var);
usage_threshold_rm_local_var->is_duration_null = is_duration_null;
usage_threshold_rm_local_var->is_duration = is_duration;
usage_threshold_rm_local_var->duration = duration;
usage_threshold_rm_local_var->is_total_volume_null = is_total_volume_null;
usage_threshold_rm_local_var->is_total_volume = is_total_volume;
usage_threshold_rm_local_var->total_volume = total_volume;
usage_threshold_rm_local_var->is_downlink_volume_null = is_downlink_volume_null;
usage_threshold_rm_local_var->is_downlink_volume = is_downlink_volume;
usage_threshold_rm_local_var->downlink_volume = downlink_volume;
usage_threshold_rm_local_var->is_uplink_volume_null = is_uplink_volume_null;
usage_threshold_rm_local_var->is_uplink_volume = is_uplink_volume;
usage_threshold_rm_local_var->uplink_volume = uplink_volume;
@ -56,6 +64,11 @@ cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *us
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [duration]");
goto end;
}
} else if (usage_threshold_rm->is_duration_null) {
if (cJSON_AddNullToObject(item, "duration") == NULL) {
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [duration]");
goto end;
}
}
if (usage_threshold_rm->is_total_volume) {
@ -63,6 +76,11 @@ cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *us
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [total_volume]");
goto end;
}
} else if (usage_threshold_rm->is_total_volume_null) {
if (cJSON_AddNullToObject(item, "totalVolume") == NULL) {
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [total_volume]");
goto end;
}
}
if (usage_threshold_rm->is_downlink_volume) {
@ -70,6 +88,11 @@ cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *us
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [downlink_volume]");
goto end;
}
} else if (usage_threshold_rm->is_downlink_volume_null) {
if (cJSON_AddNullToObject(item, "downlinkVolume") == NULL) {
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [downlink_volume]");
goto end;
}
}
if (usage_threshold_rm->is_uplink_volume) {
@ -77,6 +100,11 @@ cJSON *OpenAPI_usage_threshold_rm_convertToJSON(OpenAPI_usage_threshold_rm_t *us
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [uplink_volume]");
goto end;
}
} else if (usage_threshold_rm->is_uplink_volume_null) {
if (cJSON_AddNullToObject(item, "uplinkVolume") == NULL) {
ogs_error("OpenAPI_usage_threshold_rm_convertToJSON() failed [uplink_volume]");
goto end;
}
}
end:
@ -93,43 +121,55 @@ OpenAPI_usage_threshold_rm_t *OpenAPI_usage_threshold_rm_parseFromJSON(cJSON *us
cJSON *uplink_volume = NULL;
duration = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "duration");
if (duration) {
if (!cJSON_IsNull(duration)) {
if (!cJSON_IsNumber(duration)) {
ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [duration]");
goto end;
}
}
}
total_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "totalVolume");
if (total_volume) {
if (!cJSON_IsNull(total_volume)) {
if (!cJSON_IsNumber(total_volume)) {
ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [total_volume]");
goto end;
}
}
}
downlink_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "downlinkVolume");
if (downlink_volume) {
if (!cJSON_IsNull(downlink_volume)) {
if (!cJSON_IsNumber(downlink_volume)) {
ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [downlink_volume]");
goto end;
}
}
}
uplink_volume = cJSON_GetObjectItemCaseSensitive(usage_threshold_rmJSON, "uplinkVolume");
if (uplink_volume) {
if (!cJSON_IsNull(uplink_volume)) {
if (!cJSON_IsNumber(uplink_volume)) {
ogs_error("OpenAPI_usage_threshold_rm_parseFromJSON() failed [uplink_volume]");
goto end;
}
}
}
usage_threshold_rm_local_var = OpenAPI_usage_threshold_rm_create (
duration && cJSON_IsNull(duration) ? true : false,
duration ? true : false,
duration ? duration->valuedouble : 0,
total_volume && cJSON_IsNull(total_volume) ? true : false,
total_volume ? true : false,
total_volume ? total_volume->valuedouble : 0,
downlink_volume && cJSON_IsNull(downlink_volume) ? true : false,
downlink_volume ? true : false,
downlink_volume ? downlink_volume->valuedouble : 0,
uplink_volume && cJSON_IsNull(uplink_volume) ? true : false,
uplink_volume ? true : false,
uplink_volume ? uplink_volume->valuedouble : 0
);