Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C] better support for additional properties #4349

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ return 0;
{{/isContainer}}
{{/vars}}
) {
{{classname}}_t *{{classname}}_local_var = malloc(sizeof({{classname}}_t));
{{classname}}_t *{{classname}}_local_var = malloc(sizeof({{classname}}_t));
if (!{{classname}}_local_var) {
return NULL;
}
{{#vars}}
{{classname}}_local_var->{{{baseName}}} = {{{baseName}}};
{{/vars}}
{{#vars}}
{{classname}}_local_var->{{{baseName}}} = {{{baseName}}};
{{/vars}}

return {{classname}}_local_var;
return {{classname}}_local_var;
}


Expand Down Expand Up @@ -241,36 +241,36 @@ void {{classname}}_free({{classname}}_t *{{classname}}) {
{{#isContainer}}
{{#isListContainer}}
{{#isPrimitiveType}}
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
free(listEntry->data);
}
list_free({{classname}}->{{baseName}});
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
free(listEntry->data);
}
list_free({{classname}}->{{baseName}});
{{/isPrimitiveType}}
{{^isPrimitiveType}}
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
{{complexType}}_free(listEntry->data);
}
list_free({{classname}}->{{baseName}});
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
{{complexType}}_free(listEntry->data);
}
list_free({{classname}}->{{baseName}});
{{/isPrimitiveType}}
{{/isListContainer}}
{{#isMapContainer}}
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
keyValuePair_t *localMapKeyPair = (keyValuePair_t*) listEntry->data;
list_ForEach(listEntry, {{classname}}->{{baseName}}) {
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
free (localKeyValue->key);
free (localKeyValue->value);
}
list_free({{classname}}->{{baseName}});
}
list_free({{classname}}->{{baseName}});
{{/isMapContainer}}
{{/isContainer}}
{{/vars}}
free({{classname}});
free({{classname}});
}

cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
cJSON *item = cJSON_CreateObject();
{{#vars}}
cJSON *item = cJSON_CreateObject();
{{#vars}}

// {{{classname}}}->{{{baseName}}}
// {{{classname}}}->{{{baseName}}}
{{#required}}
{{^isEnum}}
if (!{{{classname}}}->{{{baseName}}}) {
Expand All @@ -279,8 +279,8 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{/isEnum}}
{{/required}}
{{^required}}{{^isEnum}}if({{{classname}}}->{{{baseName}}}) { {{/isEnum}}{{/required}}
{{^isContainer}}
{{#isPrimitiveType}}
{{^isContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{baseName}}}) == NULL) {
goto fail; //Numeric
Expand Down Expand Up @@ -328,8 +328,8 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
goto fail; //Date-Time
}
{{/isDateTime}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isModel}}
{{#isEnum}}
cJSON *{{{baseName}}}_enum_local_JSON = {{datatypeWithEnum}}_convertToJSON({{{classname}}}->{{{baseName}}});
Expand Down Expand Up @@ -372,17 +372,17 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
goto fail;
}
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isListContainer}}
{{#isPrimitiveType}}
cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
if({{{name}}} == NULL) {
goto fail; //primitive container
}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isListContainer}}
{{#isPrimitiveType}}
cJSON *{{{name}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
if({{{name}}} == NULL) {
goto fail; //primitive container
}

listEntry_t *{{{name}}}ListEntry;
listEntry_t *{{{name}}}ListEntry;
list_ForEach({{{name}}}ListEntry, {{{classname}}}->{{{baseName}}}) {
{{#items}}
{{#isString}}
Expand All @@ -399,8 +399,8 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{/isString}}
{{/items}}
}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{/isPrimitiveType}}
{{^isPrimitiveType}}
cJSON *{{{baseName}}} = cJSON_AddArrayToObject(item, "{{{baseName}}}");
if({{{baseName}}} == NULL) {
goto fail; //nonprimitive container
Expand All @@ -416,15 +416,15 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
cJSON_AddItemToArray({{{baseName}}}, itemLocal);
}
}
{{/isPrimitiveType}}
{{/isListContainer}}
{{#isMapContainer}}
cJSON *{{{baseName}}} = cJSON_AddObjectToObject(item, "{{{baseName}}}");
if({{{baseName}}} == NULL) {
goto fail; //primitive map container
}
{{/isPrimitiveType}}
{{/isListContainer}}
{{#isMapContainer}}
cJSON *{{{baseName}}} = cJSON_AddObjectToObject(item, "{{{baseName}}}");
if({{{baseName}}} == NULL) {
goto fail; //primitive map container
}
cJSON *localMapObject = cJSON_CreateObject(); //Memory free to be implemented in user code
listEntry_t *{{{baseName}}}ListEntry;
listEntry_t *{{{baseName}}}ListEntry;
if ({{{classname}}}->{{{baseName}}}) {
list_ForEach({{{baseName}}}ListEntry, {{{classname}}}->{{{baseName}}}) {
keyValuePair_t *localKeyValue = (keyValuePair_t*){{{baseName}}}ListEntry->data;
Expand All @@ -445,19 +445,19 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
cJSON_AddItemToObject({{{baseName}}},"", localMapObject);
}
}
{{/isMapContainer}}
{{/isContainer}}
{{^required}}
{{/isMapContainer}}
{{/isContainer}}
{{^required}}
{{^isEnum}} } {{/isEnum}}
{{/required}}
{{/required}}

{{/vars}}
return item;
return item;
fail:
if (item) {
if (item) {
cJSON_Delete(item);
}
return NULL;
return NULL;
}

{{classname}}_t *{{classname}}_parseFromJSON(cJSON *{{classname}}JSON){
Expand Down Expand Up @@ -526,8 +526,8 @@ fail:
char* decoded = base64decode({{{baseName}}}->valuestring, strlen({{{baseName}}}->valuestring));
decoded_str_{{{baseName}}}->data = malloc(strlen(decoded) - 1);
if (!decoded_str_{{{baseName}}}->data) {
goto end;
}
goto end;
}
michelealbano marked this conversation as resolved.
Show resolved Hide resolved
memcpy(decoded_str_{{{baseName}}}->data,decoded,(strlen(decoded)-1));
decoded_str_{{{baseName}}}->len = strlen(decoded) - 1;
{{/isBinary}}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/c/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.1-SNAPSHOT
4.2.2-SNAPSHOT
45 changes: 23 additions & 22 deletions samples/client/petstore/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,28 @@ install(TARGETS ${pkgName} DESTINATION ${CMAKE_INSTALL_PREFIX})
set(SRCS "")
set(HDRS "")

# This section shows how to use the above compiled libary to compile the source files
# set source files
set(SRCS
unit-tests/manual-PetAPI.c
unit-tests/manual-StoreAPI.c
unit-tests/manual-UserAPI.c
unit-tests/manual-order.c
unit-tests/manual-user.c)

#set header files
set(HDRS
)
## This section shows how to use the above compiled libary to compile the source files
## set source files
#set(SRCS
# unit-tests/manual-PetAPI.c
# unit-tests/manual-StoreAPI.c
# unit-tests/manual-UserAPI.c
# unit-tests/manual-order.c
# unit-tests/manual-user.c)

##set header files
#set(HDRS
#)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michelealbano seems like these will disable the integration tests for the C Petstore client. I could no longer find the following in the Travis log:

-- Build files have been written to: /home/travis/build/OpenAPITools/openapi-generator/samples/client/petstore/c
Scanning dependencies of target openapi_petstore
[  4%] Building C object CMakeFiles/openapi_petstore.dir/src/list.c.o
[  8%] Building C object CMakeFiles/openapi_petstore.dir/src/apiKey.c.o
[ 12%] Building C object CMakeFiles/openapi_petstore.dir/src/apiClient.c.o
[ 16%] Building C object CMakeFiles/openapi_petstore.dir/external/cJSON.c.o
[ 20%] Building C object CMakeFiles/openapi_petstore.dir/model/api_response.c.o
[ 25%] Building C object CMakeFiles/openapi_petstore.dir/model/category.c.o
[ 29%] Building C object CMakeFiles/openapi_petstore.dir/model/order.c.o
[ 33%] Building C object CMakeFiles/openapi_petstore.dir/model/pet.c.o
[ 37%] Building C object CMakeFiles/openapi_petstore.dir/model/tag.c.o
[ 41%] Building C object CMakeFiles/openapi_petstore.dir/model/user.c.o
[ 45%] Building C object CMakeFiles/openapi_petstore.dir/api/PetAPI.c.o
[ 50%] Building C object CMakeFiles/openapi_petstore.dir/api/StoreAPI.c.o
[ 54%] Building C object CMakeFiles/openapi_petstore.dir/api/UserAPI.c.o
[ 58%] Linking C shared library libopenapi_petstore.so
[ 58%] Built target openapi_petstore
Scanning dependencies of target unit-manual-PetAPI
[ 62%] Building C object CMakeFiles/unit-manual-PetAPI.dir/unit-tests/manual-PetAPI.c.o
[ 66%] Linking C executable unit-manual-PetAPI
[ 66%] Built target unit-manual-PetAPI
Scanning dependencies of target unit-manual-UserAPI
[ 70%] Building C object CMakeFiles/unit-manual-UserAPI.dir/unit-tests/manual-UserAPI.c.o
[ 75%] Linking C executable unit-manual-UserAPI
[ 75%] Built target unit-manual-UserAPI
Scanning dependencies of target unit-manual-StoreAPI
[ 79%] Building C object CMakeFiles/unit-manual-StoreAPI.dir/unit-tests/manual-StoreAPI.c.o
[ 83%] Linking C executable unit-manual-StoreAPI
[ 83%] Built target unit-manual-StoreAPI
Scanning dependencies of target unit-manual-user
[ 87%] Building C object CMakeFiles/unit-manual-user.dir/unit-tests/manual-user.c.o
[ 91%] Linking C executable unit-manual-user
[ 91%] Built target unit-manual-user
Scanning dependencies of target unit-manual-order
[ 95%] Building C object CMakeFiles/unit-manual-order.dir/unit-tests/manual-order.c.o
[100%] Linking C executable unit-manual-order
[100%] Built target unit-manual-order
Data is:{
	"id":	1234,
	"category":	{
		"id":	5,
		"name":	"Example Category"
	},
	"name":	"Example Pet",
	"photoUrls":	["http://www.github.com", "http://www.gitter.im"],
	"tags":	[{
			"id":	1,
			"name":	"beautiful code"
		}, {
			"id":	542353,
			"name":	"at least I tried"
		}],
	"status":	"available"
}
successful operation
Data is:{
	"id":	1234,
	"category":	{
		"id":	5,
		"name":	"Example Category"
	},
	"name":	"Rocky Handsome",
	"photoUrls":	["http://www.github.com", "http://www.gitter.im"],
	"tags":	[{
			"id":	1,
			"name":	"beautiful code"
		}, {
			"id":	542353,
			"name":	"at least I tried"
		}],
	"status":	"sold"
}
successful operation
User is: 
{
	"id":	1234,
	"username":	"example123",
	"firstName":	"Example1",
	"lastName":	"Example2Last",
	"email":	"example@example.com",
	"password":	"thisisexample!123",
	"phone":	"+123456789",
	"userStatus":	4
}
successful operation
Login User: logged in user session:1572762309163
successful operation
Placed order: 
{
	"id":	1234,
	"petId":	12345,
	"quantity":	50,
	"shipDate":	"2018-09-24T10:19:09.592+0000",
	"status":	"placed",
	"complete":	true
}
successful operation
Order received: 
{
	"id":	1234,
	"petId":	12345,
	"quantity":	50,
	"shipDate":	"2018-09-24T10:19:09.592+0000",
	"status":	"placed",
	"complete":	true
}
Order Deleted 
Order not found
successful operation
sold - 2
pending - 2
available - 9

Ref: https://travis-ci.org/OpenAPITools/openapi-generator/builds/606108932?utm_source=github_status&utm_medium=notification

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 I just run ./bin/c-petstore.sh after the changes by @zhemant
Should we meet on Slack to decide how it should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhemant I gave a look at the new c-petstore.sh, and I haven't the expertise to correct the issue raised by @wing328 . Can you help with solving it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michelealbano Sure, I think I already have an idea why this is happening. If you can talk on IM, then I can maybe tell you in details about how the working is. I had sent you text on gitter. I don't know if you use it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've filed #4457 with some minor enhancements, which should correct the skipped tests due to regenerating the CMakefile file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michelealbano can you please merge the latest master into this branch as I've merged #4457 into master?


# loop over all files in SRCS variable
foreach(SOURCE_FILE ${SRCS})
# Get only the file name from the file as add_executable doesnot support executable with slash("/")
get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
# Remove .c from the file name and set it as executable name
string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
# Add executable for every source file in SRCS
add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
# Link above created libary to executable and dependent libary curl
target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
endforeach(SOURCE_FILE ${SRCS})
## loop over all files in SRCS variable
#foreach(SOURCE_FILE ${SRCS})
# # Get only the file name from the file as add_executable doesnot support executable with slash("/")
# get_filename_component(FILE_NAME_ONLY ${SOURCE_FILE} NAME_WE)
# # Remove .c from the file name and set it as executable name
# string( REPLACE ".c" "" EXECUTABLE_FILE ${FILE_NAME_ONLY})
# # Add executable for every source file in SRCS
# add_executable(unit-${EXECUTABLE_FILE} ${SOURCE_FILE})
# # Link above created libary to executable and dependent libary curl
# target_link_libraries(unit-${EXECUTABLE_FILE} ${CURL_LIBRARIES} ${pkgName} )
#endforeach(SOURCE_FILE ${SRCS})
Loading