forked from loafle/openapi-generator-original
map set to list, add tests (#16730)
This commit is contained in:
parent
050e463872
commit
893154d766
@ -289,6 +289,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
|
|||||||
typeMapping.put("UUID", "char");
|
typeMapping.put("UUID", "char");
|
||||||
typeMapping.put("URI", "char");
|
typeMapping.put("URI", "char");
|
||||||
typeMapping.put("array", "list");
|
typeMapping.put("array", "list");
|
||||||
|
typeMapping.put("set", "list");
|
||||||
typeMapping.put("map", "list_t*");
|
typeMapping.put("map", "list_t*");
|
||||||
typeMapping.put("date-time", "char");
|
typeMapping.put("date-time", "char");
|
||||||
|
|
||||||
|
@ -726,3 +726,17 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
format: uuid
|
format: uuid
|
||||||
default: 1111-2222-3333-4444
|
default: 1111-2222-3333-4444
|
||||||
|
model_with_set_propertes:
|
||||||
|
description: to test set properties
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tag_set:
|
||||||
|
type: array
|
||||||
|
uniqueItems: true
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/Tag'
|
||||||
|
string_set:
|
||||||
|
type: array
|
||||||
|
uniqueItems: true
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
@ -12,6 +12,7 @@ docs/StoreAPI.md
|
|||||||
docs/UserAPI.md
|
docs/UserAPI.md
|
||||||
docs/api_response.md
|
docs/api_response.md
|
||||||
docs/category.md
|
docs/category.md
|
||||||
|
docs/model_with_set_propertes.md
|
||||||
docs/order.md
|
docs/order.md
|
||||||
docs/pet.md
|
docs/pet.md
|
||||||
docs/tag.md
|
docs/tag.md
|
||||||
@ -30,6 +31,8 @@ model/category.c
|
|||||||
model/category.h
|
model/category.h
|
||||||
model/mapped_model.c
|
model/mapped_model.c
|
||||||
model/mapped_model.h
|
model/mapped_model.h
|
||||||
|
model/model_with_set_propertes.c
|
||||||
|
model/model_with_set_propertes.h
|
||||||
model/object.c
|
model/object.c
|
||||||
model/object.h
|
model/object.h
|
||||||
model/order.c
|
model/order.c
|
||||||
|
@ -92,6 +92,7 @@ Category | Method | HTTP request | Description
|
|||||||
- [MappedModel_t](docs/MappedModel.md)
|
- [MappedModel_t](docs/MappedModel.md)
|
||||||
- [api_response_t](docs/api_response.md)
|
- [api_response_t](docs/api_response.md)
|
||||||
- [category_t](docs/category.md)
|
- [category_t](docs/category.md)
|
||||||
|
- [model_with_set_propertes_t](docs/model_with_set_propertes.md)
|
||||||
- [order_t](docs/order.md)
|
- [order_t](docs/order.md)
|
||||||
- [pet_t](docs/pet.md)
|
- [pet_t](docs/pet.md)
|
||||||
- [tag_t](docs/tag.md)
|
- [tag_t](docs/tag.md)
|
||||||
|
11
samples/client/petstore/c/docs/model_with_set_propertes.md
Normal file
11
samples/client/petstore/c/docs/model_with_set_propertes.md
Normal file
@ -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
samples/client/petstore/c/model/model_with_set_propertes.c
Normal file
170
samples/client/petstore/c/model/model_with_set_propertes.c
Normal file
@ -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
samples/client/petstore/c/model/model_with_set_propertes.h
Normal file
40
samples/client/petstore/c/model/model_with_set_propertes.h
Normal file
@ -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_ */
|
||||||
|
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user