forked from chidambaranadig/openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
map set to list, add tests (OpenAPITools#16730)
- Loading branch information
Showing
8 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
samples/client/petstore/c/docs/model_with_set_propertes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# model_with_set_propertes_t | ||
|
||
## Properties | ||
Name | Type | Description | Notes | ||
------------ | ------------- | ------------- | ------------- | ||
**tag_set** | [**list_t**](tag.md) \* | | [optional] | ||
**string_set** | **list_t \*** | | [optional] | ||
|
||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) | ||
|
||
|
170 changes: 170 additions & 0 deletions
170
samples/client/petstore/c/model/model_with_set_propertes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include "model_with_set_propertes.h" | ||
|
||
|
||
|
||
model_with_set_propertes_t *model_with_set_propertes_create( | ||
list_t *tag_set, | ||
list_t *string_set | ||
) { | ||
model_with_set_propertes_t *model_with_set_propertes_local_var = malloc(sizeof(model_with_set_propertes_t)); | ||
if (!model_with_set_propertes_local_var) { | ||
return NULL; | ||
} | ||
model_with_set_propertes_local_var->tag_set = tag_set; | ||
model_with_set_propertes_local_var->string_set = string_set; | ||
|
||
return model_with_set_propertes_local_var; | ||
} | ||
|
||
|
||
void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes) { | ||
if(NULL == model_with_set_propertes){ | ||
return ; | ||
} | ||
listEntry_t *listEntry; | ||
if (model_with_set_propertes->tag_set) { | ||
list_ForEach(listEntry, model_with_set_propertes->tag_set) { | ||
tag_free(listEntry->data); | ||
} | ||
list_freeList(model_with_set_propertes->tag_set); | ||
model_with_set_propertes->tag_set = NULL; | ||
} | ||
if (model_with_set_propertes->string_set) { | ||
list_ForEach(listEntry, model_with_set_propertes->string_set) { | ||
free(listEntry->data); | ||
} | ||
list_freeList(model_with_set_propertes->string_set); | ||
model_with_set_propertes->string_set = NULL; | ||
} | ||
free(model_with_set_propertes); | ||
} | ||
|
||
cJSON *model_with_set_propertes_convertToJSON(model_with_set_propertes_t *model_with_set_propertes) { | ||
cJSON *item = cJSON_CreateObject(); | ||
|
||
// model_with_set_propertes->tag_set | ||
if(model_with_set_propertes->tag_set) { | ||
cJSON *tag_set = cJSON_AddArrayToObject(item, "tag_set"); | ||
if(tag_set == NULL) { | ||
goto fail; //nonprimitive container | ||
} | ||
|
||
listEntry_t *tag_setListEntry; | ||
if (model_with_set_propertes->tag_set) { | ||
list_ForEach(tag_setListEntry, model_with_set_propertes->tag_set) { | ||
cJSON *itemLocal = tag_convertToJSON(tag_setListEntry->data); | ||
if(itemLocal == NULL) { | ||
goto fail; | ||
} | ||
cJSON_AddItemToArray(tag_set, itemLocal); | ||
} | ||
} | ||
} | ||
|
||
|
||
// model_with_set_propertes->string_set | ||
if(model_with_set_propertes->string_set) { | ||
cJSON *string_set = cJSON_AddArrayToObject(item, "string_set"); | ||
if(string_set == NULL) { | ||
goto fail; //primitive container | ||
} | ||
|
||
listEntry_t *string_setListEntry; | ||
list_ForEach(string_setListEntry, model_with_set_propertes->string_set) { | ||
if(cJSON_AddStringToObject(string_set, "", (char*)string_setListEntry->data) == NULL) | ||
{ | ||
goto fail; | ||
} | ||
} | ||
} | ||
|
||
return item; | ||
fail: | ||
if (item) { | ||
cJSON_Delete(item); | ||
} | ||
return NULL; | ||
} | ||
|
||
model_with_set_propertes_t *model_with_set_propertes_parseFromJSON(cJSON *model_with_set_propertesJSON){ | ||
|
||
model_with_set_propertes_t *model_with_set_propertes_local_var = NULL; | ||
|
||
// define the local list for model_with_set_propertes->tag_set | ||
list_t *tag_setList = NULL; | ||
|
||
// define the local list for model_with_set_propertes->string_set | ||
list_t *string_setList = NULL; | ||
|
||
// model_with_set_propertes->tag_set | ||
cJSON *tag_set = cJSON_GetObjectItemCaseSensitive(model_with_set_propertesJSON, "tag_set"); | ||
if (tag_set) { | ||
cJSON *tag_set_local_nonprimitive = NULL; | ||
if(!cJSON_IsArray(tag_set)){ | ||
goto end; //nonprimitive container | ||
} | ||
|
||
tag_setList = list_createList(); | ||
|
||
cJSON_ArrayForEach(tag_set_local_nonprimitive,tag_set ) | ||
{ | ||
if(!cJSON_IsObject(tag_set_local_nonprimitive)){ | ||
goto end; | ||
} | ||
tag_t *tag_setItem = tag_parseFromJSON(tag_set_local_nonprimitive); | ||
|
||
list_addElement(tag_setList, tag_setItem); | ||
} | ||
} | ||
|
||
// model_with_set_propertes->string_set | ||
cJSON *string_set = cJSON_GetObjectItemCaseSensitive(model_with_set_propertesJSON, "string_set"); | ||
if (string_set) { | ||
cJSON *string_set_local = NULL; | ||
if(!cJSON_IsArray(string_set)) { | ||
goto end;//primitive container | ||
} | ||
string_setList = list_createList(); | ||
|
||
cJSON_ArrayForEach(string_set_local, string_set) | ||
{ | ||
if(!cJSON_IsString(string_set_local)) | ||
{ | ||
goto end; | ||
} | ||
list_addElement(string_setList , strdup(string_set_local->valuestring)); | ||
} | ||
} | ||
|
||
|
||
model_with_set_propertes_local_var = model_with_set_propertes_create ( | ||
tag_set ? tag_setList : NULL, | ||
string_set ? string_setList : NULL | ||
); | ||
|
||
return model_with_set_propertes_local_var; | ||
end: | ||
if (tag_setList) { | ||
listEntry_t *listEntry = NULL; | ||
list_ForEach(listEntry, tag_setList) { | ||
tag_free(listEntry->data); | ||
listEntry->data = NULL; | ||
} | ||
list_freeList(tag_setList); | ||
tag_setList = NULL; | ||
} | ||
if (string_setList) { | ||
listEntry_t *listEntry = NULL; | ||
list_ForEach(listEntry, string_setList) { | ||
free(listEntry->data); | ||
listEntry->data = NULL; | ||
} | ||
list_freeList(string_setList); | ||
string_setList = NULL; | ||
} | ||
return NULL; | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
samples/client/petstore/c/model/model_with_set_propertes.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* model_with_set_propertes.h | ||
* | ||
* to test set properties | ||
*/ | ||
|
||
#ifndef _model_with_set_propertes_H_ | ||
#define _model_with_set_propertes_H_ | ||
|
||
#include <string.h> | ||
#include "../external/cJSON.h" | ||
#include "../include/list.h" | ||
#include "../include/keyValuePair.h" | ||
#include "../include/binary.h" | ||
|
||
typedef struct model_with_set_propertes_t model_with_set_propertes_t; | ||
|
||
#include "tag.h" | ||
|
||
|
||
|
||
typedef struct model_with_set_propertes_t { | ||
list_t *tag_set; //nonprimitive container | ||
list_t *string_set; //primitive container | ||
|
||
} model_with_set_propertes_t; | ||
|
||
model_with_set_propertes_t *model_with_set_propertes_create( | ||
list_t *tag_set, | ||
list_t *string_set | ||
); | ||
|
||
void model_with_set_propertes_free(model_with_set_propertes_t *model_with_set_propertes); | ||
|
||
model_with_set_propertes_t *model_with_set_propertes_parseFromJSON(cJSON *model_with_set_propertesJSON); | ||
|
||
cJSON *model_with_set_propertes_convertToJSON(model_with_set_propertes_t *model_with_set_propertes); | ||
|
||
#endif /* _model_with_set_propertes_H_ */ | ||
|
60 changes: 60 additions & 0 deletions
60
samples/client/petstore/c/unit-test/test_model_with_set_propertes.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef model_with_set_propertes_TEST | ||
#define model_with_set_propertes_TEST | ||
|
||
// the following is to include only the main from the first c file | ||
#ifndef TEST_MAIN | ||
#define TEST_MAIN | ||
#define model_with_set_propertes_MAIN | ||
#endif // TEST_MAIN | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
#include "../external/cJSON.h" | ||
|
||
#include "../model/model_with_set_propertes.h" | ||
model_with_set_propertes_t* instantiate_model_with_set_propertes(int include_optional); | ||
|
||
|
||
|
||
model_with_set_propertes_t* instantiate_model_with_set_propertes(int include_optional) { | ||
model_with_set_propertes_t* model_with_set_propertes = NULL; | ||
if (include_optional) { | ||
model_with_set_propertes = model_with_set_propertes_create( | ||
list_createList(), | ||
list_createList() | ||
); | ||
} else { | ||
model_with_set_propertes = model_with_set_propertes_create( | ||
list_createList(), | ||
list_createList() | ||
); | ||
} | ||
|
||
return model_with_set_propertes; | ||
} | ||
|
||
|
||
#ifdef model_with_set_propertes_MAIN | ||
|
||
void test_model_with_set_propertes(int include_optional) { | ||
model_with_set_propertes_t* model_with_set_propertes_1 = instantiate_model_with_set_propertes(include_optional); | ||
|
||
cJSON* jsonmodel_with_set_propertes_1 = model_with_set_propertes_convertToJSON(model_with_set_propertes_1); | ||
printf("model_with_set_propertes :\n%s\n", cJSON_Print(jsonmodel_with_set_propertes_1)); | ||
model_with_set_propertes_t* model_with_set_propertes_2 = model_with_set_propertes_parseFromJSON(jsonmodel_with_set_propertes_1); | ||
cJSON* jsonmodel_with_set_propertes_2 = model_with_set_propertes_convertToJSON(model_with_set_propertes_2); | ||
printf("repeating model_with_set_propertes:\n%s\n", cJSON_Print(jsonmodel_with_set_propertes_2)); | ||
} | ||
|
||
int main() { | ||
test_model_with_set_propertes(1); | ||
test_model_with_set_propertes(0); | ||
|
||
printf("Hello world \n"); | ||
return 0; | ||
} | ||
|
||
#endif // model_with_set_propertes_MAIN | ||
#endif // model_with_set_propertes_TEST |