forked from loafle/openapi-generator-original
Tests for recent C fixes (#20200)
* [C] Add test schemas for the recent changes The recent commit 47665aaa97cb ("Fix a few issues with the C generator (part 1 version 2) (#14434)") didn't include any test schemas. Add them now, as requested: https://github.com/OpenAPITools/openapi-generator/pull/14434#issuecomment-2497497110 * Update samples * Fix sample update with missing files * More fixes for sample updates
This commit is contained in:
parent
f8ca36b97e
commit
037cb12f34
@ -75,6 +75,24 @@ paths:
|
||||
- petstore_auth:
|
||||
- 'write:pets'
|
||||
- 'read:pets'
|
||||
/pet/specialty:
|
||||
get:
|
||||
tags:
|
||||
- pet
|
||||
summary: Specialty of the shop
|
||||
description: Returns the kind of pet the store specializes in
|
||||
operationId: specialtyPet
|
||||
produces:
|
||||
- application/xml
|
||||
- application/json
|
||||
parameters: []
|
||||
responses:
|
||||
'200':
|
||||
description: successful operation
|
||||
schema:
|
||||
$ref: '#/definitions/Preference'
|
||||
security:
|
||||
- api_key: []
|
||||
/pet/findByStatus:
|
||||
get:
|
||||
tags:
|
||||
@ -626,6 +644,17 @@ definitions:
|
||||
type: string
|
||||
xml:
|
||||
name: Category
|
||||
Preference:
|
||||
title: Pet preference
|
||||
description: A user's preference in pets
|
||||
type: string
|
||||
enum:
|
||||
- cats
|
||||
- dogs
|
||||
- birds
|
||||
- fish
|
||||
- snakes
|
||||
- other
|
||||
User:
|
||||
title: a User
|
||||
description: A User who is purchasing from the pet store
|
||||
@ -650,6 +679,12 @@ definitions:
|
||||
type: integer
|
||||
format: int32
|
||||
description: User Status
|
||||
extra:
|
||||
type: object
|
||||
nullable: true
|
||||
additionalProperties: true
|
||||
preference:
|
||||
$ref: '#/definitions/Preference'
|
||||
xml:
|
||||
name: User
|
||||
Tag:
|
||||
|
@ -16,6 +16,7 @@ docs/category.md
|
||||
docs/model_with_set_propertes.md
|
||||
docs/order.md
|
||||
docs/pet.md
|
||||
docs/preference.md
|
||||
docs/tag.md
|
||||
docs/user.md
|
||||
external/cJSON.c
|
||||
@ -41,6 +42,8 @@ model/order.c
|
||||
model/order.h
|
||||
model/pet.c
|
||||
model/pet.h
|
||||
model/preference.c
|
||||
model/preference.h
|
||||
model/tag.c
|
||||
model/tag.h
|
||||
model/user.c
|
||||
|
@ -60,6 +60,7 @@ set(SRCS
|
||||
model/model_with_set_propertes.c
|
||||
model/order.c
|
||||
model/pet.c
|
||||
model/preference.c
|
||||
model/tag.c
|
||||
model/user.c
|
||||
api/PetAPI.c
|
||||
@ -82,6 +83,7 @@ set(HDRS
|
||||
model/model_with_set_propertes.h
|
||||
model/order.h
|
||||
model/pet.h
|
||||
model/preference.h
|
||||
model/tag.h
|
||||
model/user.h
|
||||
api/PetAPI.h
|
||||
|
@ -70,6 +70,7 @@ Category | Method | HTTP request | Description
|
||||
*PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
*PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
*PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID
|
||||
*PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop
|
||||
*PetAPI* | [**PetAPI_updatePet**](docs/PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet
|
||||
*PetAPI* | [**PetAPI_updatePetWithForm**](docs/PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
*PetAPI* | [**PetAPI_uploadFile**](docs/PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
@ -96,6 +97,7 @@ Category | Method | HTTP request | Description
|
||||
- [model_with_set_propertes_t](docs/model_with_set_propertes.md)
|
||||
- [order_t](docs/order.md)
|
||||
- [pet_t](docs/pet.md)
|
||||
- [preference_t](docs/preference.md)
|
||||
- [tag_t](docs/tag.md)
|
||||
- [user_t](docs/user.md)
|
||||
|
||||
|
@ -460,6 +460,70 @@ end:
|
||||
|
||||
}
|
||||
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
openapi_petstore_preference__e
|
||||
PetAPI_specialtyPet(apiClient_t *apiClient)
|
||||
{
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
list_t *localVarHeaderType = list_createList();
|
||||
list_t *localVarContentType = NULL;
|
||||
char *localVarBodyParameters = NULL;
|
||||
|
||||
// create the path
|
||||
long sizeOfPath = strlen("/pet/specialty")+1;
|
||||
char *localVarPath = malloc(sizeOfPath);
|
||||
snprintf(localVarPath, sizeOfPath, "/pet/specialty");
|
||||
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType,"application/xml"); //produces
|
||||
list_addElement(localVarHeaderType,"application/json"); //produces
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
localVarHeaderParameters,
|
||||
localVarFormParameters,
|
||||
localVarHeaderType,
|
||||
localVarContentType,
|
||||
localVarBodyParameters,
|
||||
"GET");
|
||||
|
||||
// uncomment below to debug the error response
|
||||
//if (apiClient->response_code == 200) {
|
||||
// printf("%s\n","successful operation");
|
||||
//}
|
||||
//nonprimitive not container
|
||||
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON);
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
if(elementToReturn == 0) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
//return type
|
||||
if (apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
list_freeList(localVarHeaderType);
|
||||
|
||||
free(localVarPath);
|
||||
return elementToReturn;
|
||||
end:
|
||||
free(localVarPath);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../include/binary.h"
|
||||
#include "../model/api_response.h"
|
||||
#include "../model/pet.h"
|
||||
#include "../model/preference.h"
|
||||
|
||||
// Enum STATUS for PetAPI_findPetsByStatus
|
||||
typedef enum { openapi_petstore_findPetsByStatus_STATUS_NULL = 0, openapi_petstore_findPetsByStatus_STATUS_available, openapi_petstore_findPetsByStatus_STATUS_pending, openapi_petstore_findPetsByStatus_STATUS_sold } openapi_petstore_findPetsByStatus_status_e;
|
||||
@ -48,6 +49,14 @@ pet_t*
|
||||
PetAPI_getPetById(apiClient_t *apiClient, long petId);
|
||||
|
||||
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
openapi_petstore_preference__e
|
||||
PetAPI_specialtyPet(apiClient_t *apiClient);
|
||||
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void
|
||||
|
@ -9,6 +9,7 @@ Method | HTTP request | Description
|
||||
[**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
[**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
[**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID
|
||||
[**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop
|
||||
[**PetAPI_updatePet**](PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet
|
||||
[**PetAPI_updatePetWithForm**](PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
[**PetAPI_uploadFile**](PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
@ -153,6 +154,36 @@ Name | Type | Description | Notes
|
||||
[pet_t](pet.md) *
|
||||
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **PetAPI_specialtyPet**
|
||||
```c
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
preference_t* PetAPI_specialtyPet(apiClient_t *apiClient);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**apiClient** | **apiClient_t \*** | context containing the client configuration |
|
||||
|
||||
### Return type
|
||||
|
||||
[preference_t](preference.md) *
|
||||
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
@ -0,0 +1,9 @@
|
||||
# preference_t
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -11,6 +11,8 @@ Name | Type | Description | Notes
|
||||
**password** | **char \*** | | [optional]
|
||||
**phone** | **char \*** | | [optional]
|
||||
**user_status** | **int** | User Status | [optional]
|
||||
**extra** | **list_t*** | | [optional]
|
||||
**preference** | **preference_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)
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "preference.h"
|
||||
|
||||
|
||||
char* preference_preference_ToString(openapi_petstore_preference__e preference) {
|
||||
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
||||
return preferenceArray[preference];
|
||||
}
|
||||
|
||||
openapi_petstore_preference__e preference_preference_FromString(char* preference) {
|
||||
int stringToReturn = 0;
|
||||
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
||||
size_t sizeofArray = sizeof(preferenceArray) / sizeof(preferenceArray[0]);
|
||||
while(stringToReturn < sizeofArray) {
|
||||
if(strcmp(preference, preferenceArray[stringToReturn]) == 0) {
|
||||
return stringToReturn;
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *preference_convertToJSON(openapi_petstore_preference__e preference) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
if(cJSON_AddStringToObject(item, "preference", preference_preference_ToString(preference)) == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON) {
|
||||
openapi_petstore_preference__e *preference = NULL;
|
||||
openapi_petstore_preference__e preferenceVariable;
|
||||
cJSON *preferenceVar = cJSON_GetObjectItemCaseSensitive(preferenceJSON, "preference");
|
||||
if(!cJSON_IsString(preferenceVar) || (preferenceVar->valuestring == NULL)){
|
||||
goto end;
|
||||
}
|
||||
preferenceVariable = preference_preference_FromString(preferenceVar->valuestring);
|
||||
return preferenceVariable;
|
||||
end:
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* preference.h
|
||||
*
|
||||
* A user's preference in pets
|
||||
*/
|
||||
|
||||
#ifndef _preference_H_
|
||||
#define _preference_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../include/binary.h"
|
||||
|
||||
typedef struct preference_t preference_t;
|
||||
|
||||
|
||||
// Enum for preference
|
||||
|
||||
typedef enum { openapi_petstore_preference__NULL = 0, openapi_petstore_preference__cats, openapi_petstore_preference__dogs, openapi_petstore_preference__birds, openapi_petstore_preference__fish, openapi_petstore_preference__snakes, openapi_petstore_preference__other } openapi_petstore_preference__e;
|
||||
|
||||
char* preference_preference_ToString(openapi_petstore_preference__e preference);
|
||||
|
||||
openapi_petstore_preference__e preference_preference_FromString(char* preference);
|
||||
|
||||
cJSON *preference_convertToJSON(openapi_petstore_preference__e preference);
|
||||
|
||||
openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON);
|
||||
|
||||
#endif /* _preference_H_ */
|
||||
|
@ -13,7 +13,9 @@ user_t *user_create(
|
||||
char *email,
|
||||
char *password,
|
||||
char *phone,
|
||||
int user_status
|
||||
int user_status,
|
||||
list_t* extra,
|
||||
openapi_petstore_preference__e preference
|
||||
) {
|
||||
user_t *user_local_var = malloc(sizeof(user_t));
|
||||
if (!user_local_var) {
|
||||
@ -27,6 +29,8 @@ user_t *user_create(
|
||||
user_local_var->password = password;
|
||||
user_local_var->phone = phone;
|
||||
user_local_var->user_status = user_status;
|
||||
user_local_var->extra = extra;
|
||||
user_local_var->preference = preference;
|
||||
|
||||
return user_local_var;
|
||||
}
|
||||
@ -61,6 +65,16 @@ void user_free(user_t *user) {
|
||||
free(user->phone);
|
||||
user->phone = NULL;
|
||||
}
|
||||
if (user->extra) {
|
||||
list_ForEach(listEntry, user->extra) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
|
||||
free (localKeyValue->key);
|
||||
free (localKeyValue->value);
|
||||
keyValuePair_free(localKeyValue);
|
||||
}
|
||||
list_freeList(user->extra);
|
||||
user->extra = NULL;
|
||||
}
|
||||
free(user);
|
||||
}
|
||||
|
||||
@ -130,6 +144,35 @@ cJSON *user_convertToJSON(user_t *user) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->extra
|
||||
if(user->extra) {
|
||||
cJSON *extra = cJSON_AddObjectToObject(item, "extra");
|
||||
if(extra == NULL) {
|
||||
goto fail; //primitive map container
|
||||
}
|
||||
cJSON *localMapObject = extra;
|
||||
listEntry_t *extraListEntry;
|
||||
if (user->extra) {
|
||||
list_ForEach(extraListEntry, user->extra) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*)extraListEntry->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->preference
|
||||
if(user->preference != openapi_petstore_preference__NULL) {
|
||||
cJSON *preference_local_JSON = preference_convertToJSON(user->preference);
|
||||
if(preference_local_JSON == NULL) {
|
||||
goto fail; // custom
|
||||
}
|
||||
cJSON_AddItemToObject(item, "preference", preference_local_JSON);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
if (item) {
|
||||
@ -142,6 +185,12 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
|
||||
user_t *user_local_var = NULL;
|
||||
|
||||
// define the local map for user->extra
|
||||
list_t *extraList = NULL;
|
||||
|
||||
// define the local variable for user->preference
|
||||
openapi_petstore_preference__e preference_local_nonprim = 0;
|
||||
|
||||
// user->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id");
|
||||
if (id) {
|
||||
@ -214,6 +263,32 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
}
|
||||
}
|
||||
|
||||
// user->extra
|
||||
cJSON *extra = cJSON_GetObjectItemCaseSensitive(userJSON, "extra");
|
||||
if (extra) {
|
||||
cJSON *extra_local_map = NULL;
|
||||
if(!cJSON_IsObject(extra) && !cJSON_IsNull(extra))
|
||||
{
|
||||
goto end;//primitive map container
|
||||
}
|
||||
if(cJSON_IsObject(extra))
|
||||
{
|
||||
extraList = list_createList();
|
||||
keyValuePair_t *localMapKeyPair;
|
||||
cJSON_ArrayForEach(extra_local_map, extra)
|
||||
{
|
||||
cJSON *localMapObject = extra_local_map;
|
||||
list_addElement(extraList , localMapKeyPair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// user->preference
|
||||
cJSON *preference = cJSON_GetObjectItemCaseSensitive(userJSON, "preference");
|
||||
if (preference) {
|
||||
preference_local_nonprim = preference_parseFromJSON(preference); //custom
|
||||
}
|
||||
|
||||
|
||||
user_local_var = user_create (
|
||||
id ? id->valuedouble : 0,
|
||||
@ -223,11 +298,28 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
email && !cJSON_IsNull(email) ? strdup(email->valuestring) : NULL,
|
||||
password && !cJSON_IsNull(password) ? strdup(password->valuestring) : NULL,
|
||||
phone && !cJSON_IsNull(phone) ? strdup(phone->valuestring) : NULL,
|
||||
user_status ? user_status->valuedouble : 0
|
||||
user_status ? user_status->valuedouble : 0,
|
||||
extra ? extraList : NULL,
|
||||
preference ? preference_local_nonprim : 0
|
||||
);
|
||||
|
||||
return user_local_var;
|
||||
end:
|
||||
if (extraList) {
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, extraList) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
|
||||
free(localKeyValue->key);
|
||||
localKeyValue->key = NULL;
|
||||
keyValuePair_free(localKeyValue);
|
||||
localKeyValue = NULL;
|
||||
}
|
||||
list_freeList(extraList);
|
||||
extraList = NULL;
|
||||
}
|
||||
if (preference_local_nonprim) {
|
||||
preference_local_nonprim = 0;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
typedef struct user_t user_t;
|
||||
|
||||
#include "any_type.h"
|
||||
#include "preference.h"
|
||||
|
||||
|
||||
|
||||
@ -27,6 +29,8 @@ typedef struct user_t {
|
||||
char *password; // string
|
||||
char *phone; // string
|
||||
int user_status; //numeric
|
||||
list_t* extra; //map
|
||||
openapi_petstore_preference__e preference; //referenced enum
|
||||
|
||||
} user_t;
|
||||
|
||||
@ -38,7 +42,9 @@ user_t *user_create(
|
||||
char *email,
|
||||
char *password,
|
||||
char *phone,
|
||||
int user_status
|
||||
int user_status,
|
||||
list_t* extra,
|
||||
openapi_petstore_preference__e preference
|
||||
);
|
||||
|
||||
void user_free(user_t *user);
|
||||
|
@ -0,0 +1,56 @@
|
||||
#ifndef preference_TEST
|
||||
#define preference_TEST
|
||||
|
||||
// the following is to include only the main from the first c file
|
||||
#ifndef TEST_MAIN
|
||||
#define TEST_MAIN
|
||||
#define preference_MAIN
|
||||
#endif // TEST_MAIN
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "../external/cJSON.h"
|
||||
|
||||
#include "../model/preference.h"
|
||||
preference_t* instantiate_preference(int include_optional);
|
||||
|
||||
|
||||
|
||||
preference_t* instantiate_preference(int include_optional) {
|
||||
preference_t* preference = NULL;
|
||||
if (include_optional) {
|
||||
preference = preference_create(
|
||||
);
|
||||
} else {
|
||||
preference = preference_create(
|
||||
);
|
||||
}
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
|
||||
#ifdef preference_MAIN
|
||||
|
||||
void test_preference(int include_optional) {
|
||||
preference_t* preference_1 = instantiate_preference(include_optional);
|
||||
|
||||
cJSON* jsonpreference_1 = preference_convertToJSON(preference_1);
|
||||
printf("preference :\n%s\n", cJSON_PrintUnformatted(jsonpreference_1));
|
||||
preference_t* preference_2 = preference_parseFromJSON(jsonpreference_1);
|
||||
cJSON* jsonpreference_2 = preference_convertToJSON(preference_2);
|
||||
printf("repeating preference:\n%s\n", cJSON_PrintUnformatted(jsonpreference_2));
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_preference(1);
|
||||
test_preference(0);
|
||||
|
||||
printf("Hello world \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // preference_MAIN
|
||||
#endif // preference_TEST
|
@ -15,6 +15,7 @@ docs/category.md
|
||||
docs/model_with_set_propertes.md
|
||||
docs/order.md
|
||||
docs/pet.md
|
||||
docs/preference.md
|
||||
docs/tag.md
|
||||
docs/user.md
|
||||
external/cJSON.c
|
||||
@ -40,6 +41,8 @@ model/order.c
|
||||
model/order.h
|
||||
model/pet.c
|
||||
model/pet.h
|
||||
model/preference.c
|
||||
model/preference.h
|
||||
model/tag.c
|
||||
model/tag.h
|
||||
model/user.c
|
||||
|
@ -70,6 +70,7 @@ Category | Method | HTTP request | Description
|
||||
*PetAPI* | [**PetAPI_findPetsByStatus**](docs/PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
*PetAPI* | [**PetAPI_findPetsByTags**](docs/PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
*PetAPI* | [**PetAPI_getPetById**](docs/PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID
|
||||
*PetAPI* | [**PetAPI_specialtyPet**](docs/PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop
|
||||
*PetAPI* | [**PetAPI_updatePet**](docs/PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet
|
||||
*PetAPI* | [**PetAPI_updatePetWithForm**](docs/PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
*PetAPI* | [**PetAPI_uploadFile**](docs/PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
@ -96,6 +97,7 @@ Category | Method | HTTP request | Description
|
||||
- [model_with_set_propertes_t](docs/model_with_set_propertes.md)
|
||||
- [order_t](docs/order.md)
|
||||
- [pet_t](docs/pet.md)
|
||||
- [preference_t](docs/preference.md)
|
||||
- [tag_t](docs/tag.md)
|
||||
- [user_t](docs/user.md)
|
||||
|
||||
|
@ -460,6 +460,70 @@ end:
|
||||
|
||||
}
|
||||
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
openapi_petstore_preference__e
|
||||
PetAPI_specialtyPet(apiClient_t *apiClient)
|
||||
{
|
||||
list_t *localVarQueryParameters = NULL;
|
||||
list_t *localVarHeaderParameters = NULL;
|
||||
list_t *localVarFormParameters = NULL;
|
||||
list_t *localVarHeaderType = list_createList();
|
||||
list_t *localVarContentType = NULL;
|
||||
char *localVarBodyParameters = NULL;
|
||||
|
||||
// create the path
|
||||
long sizeOfPath = strlen("/pet/specialty")+1;
|
||||
char *localVarPath = malloc(sizeOfPath);
|
||||
snprintf(localVarPath, sizeOfPath, "/pet/specialty");
|
||||
|
||||
|
||||
|
||||
list_addElement(localVarHeaderType,"application/xml"); //produces
|
||||
list_addElement(localVarHeaderType,"application/json"); //produces
|
||||
apiClient_invoke(apiClient,
|
||||
localVarPath,
|
||||
localVarQueryParameters,
|
||||
localVarHeaderParameters,
|
||||
localVarFormParameters,
|
||||
localVarHeaderType,
|
||||
localVarContentType,
|
||||
localVarBodyParameters,
|
||||
"GET");
|
||||
|
||||
// uncomment below to debug the error response
|
||||
//if (apiClient->response_code == 200) {
|
||||
// printf("%s\n","successful operation");
|
||||
//}
|
||||
//nonprimitive not container
|
||||
cJSON *PetAPIlocalVarJSON = cJSON_Parse(apiClient->dataReceived);
|
||||
openapi_petstore_preference__e elementToReturn = preference_parseFromJSON(PetAPIlocalVarJSON);
|
||||
cJSON_Delete(PetAPIlocalVarJSON);
|
||||
if(elementToReturn == 0) {
|
||||
// return 0;
|
||||
}
|
||||
|
||||
//return type
|
||||
if (apiClient->dataReceived) {
|
||||
free(apiClient->dataReceived);
|
||||
apiClient->dataReceived = NULL;
|
||||
apiClient->dataReceivedLen = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
list_freeList(localVarHeaderType);
|
||||
|
||||
free(localVarPath);
|
||||
return elementToReturn;
|
||||
end:
|
||||
free(localVarPath);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../include/binary.h"
|
||||
#include "../model/api_response.h"
|
||||
#include "../model/pet.h"
|
||||
#include "../model/preference.h"
|
||||
|
||||
// Enum STATUS for PetAPI_findPetsByStatus
|
||||
typedef enum { openapi_petstore_findPetsByStatus_STATUS_NULL = 0, openapi_petstore_findPetsByStatus_STATUS_available, openapi_petstore_findPetsByStatus_STATUS_pending, openapi_petstore_findPetsByStatus_STATUS_sold } openapi_petstore_findPetsByStatus_status_e;
|
||||
@ -48,6 +49,14 @@ pet_t*
|
||||
PetAPI_getPetById(apiClient_t *apiClient, long petId);
|
||||
|
||||
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
openapi_petstore_preference__e
|
||||
PetAPI_specialtyPet(apiClient_t *apiClient);
|
||||
|
||||
|
||||
// Update an existing pet
|
||||
//
|
||||
void
|
||||
|
@ -9,6 +9,7 @@ Method | HTTP request | Description
|
||||
[**PetAPI_findPetsByStatus**](PetAPI.md#PetAPI_findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status
|
||||
[**PetAPI_findPetsByTags**](PetAPI.md#PetAPI_findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags
|
||||
[**PetAPI_getPetById**](PetAPI.md#PetAPI_getPetById) | **GET** /pet/{petId} | Find pet by ID
|
||||
[**PetAPI_specialtyPet**](PetAPI.md#PetAPI_specialtyPet) | **GET** /pet/specialty | Specialty of the shop
|
||||
[**PetAPI_updatePet**](PetAPI.md#PetAPI_updatePet) | **PUT** /pet | Update an existing pet
|
||||
[**PetAPI_updatePetWithForm**](PetAPI.md#PetAPI_updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data
|
||||
[**PetAPI_uploadFile**](PetAPI.md#PetAPI_uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image
|
||||
@ -153,6 +154,36 @@ Name | Type | Description | Notes
|
||||
[pet_t](pet.md) *
|
||||
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
||||
### HTTP request headers
|
||||
|
||||
- **Content-Type**: Not defined
|
||||
- **Accept**: application/xml, application/json
|
||||
|
||||
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
||||
|
||||
# **PetAPI_specialtyPet**
|
||||
```c
|
||||
// Specialty of the shop
|
||||
//
|
||||
// Returns the kind of pet the store specializes in
|
||||
//
|
||||
preference_t* PetAPI_specialtyPet(apiClient_t *apiClient);
|
||||
```
|
||||
|
||||
### Parameters
|
||||
Name | Type | Description | Notes
|
||||
------------- | ------------- | ------------- | -------------
|
||||
**apiClient** | **apiClient_t \*** | context containing the client configuration |
|
||||
|
||||
### Return type
|
||||
|
||||
[preference_t](preference.md) *
|
||||
|
||||
|
||||
### Authorization
|
||||
|
||||
[api_key](../README.md#api_key)
|
||||
|
9
samples/client/petstore/c/docs/preference.md
Normal file
9
samples/client/petstore/c/docs/preference.md
Normal file
@ -0,0 +1,9 @@
|
||||
# preference_t
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
@ -11,6 +11,8 @@ Name | Type | Description | Notes
|
||||
**password** | **char \*** | | [optional]
|
||||
**phone** | **char \*** | | [optional]
|
||||
**user_status** | **int** | User Status | [optional]
|
||||
**extra** | **list_t*** | | [optional]
|
||||
**preference** | **preference_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)
|
||||
|
||||
|
47
samples/client/petstore/c/model/preference.c
Normal file
47
samples/client/petstore/c/model/preference.c
Normal file
@ -0,0 +1,47 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "preference.h"
|
||||
|
||||
|
||||
char* preference_preference_ToString(openapi_petstore_preference__e preference) {
|
||||
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
||||
return preferenceArray[preference];
|
||||
}
|
||||
|
||||
openapi_petstore_preference__e preference_preference_FromString(char* preference) {
|
||||
int stringToReturn = 0;
|
||||
char *preferenceArray[] = { "NULL", "cats", "dogs", "birds", "fish", "snakes", "other" };
|
||||
size_t sizeofArray = sizeof(preferenceArray) / sizeof(preferenceArray[0]);
|
||||
while(stringToReturn < sizeofArray) {
|
||||
if(strcmp(preference, preferenceArray[stringToReturn]) == 0) {
|
||||
return stringToReturn;
|
||||
}
|
||||
stringToReturn++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
cJSON *preference_convertToJSON(openapi_petstore_preference__e preference) {
|
||||
cJSON *item = cJSON_CreateObject();
|
||||
if(cJSON_AddStringToObject(item, "preference", preference_preference_ToString(preference)) == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
return item;
|
||||
fail:
|
||||
cJSON_Delete(item);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON) {
|
||||
openapi_petstore_preference__e *preference = NULL;
|
||||
openapi_petstore_preference__e preferenceVariable;
|
||||
cJSON *preferenceVar = cJSON_GetObjectItemCaseSensitive(preferenceJSON, "preference");
|
||||
if(!cJSON_IsString(preferenceVar) || (preferenceVar->valuestring == NULL)){
|
||||
goto end;
|
||||
}
|
||||
preferenceVariable = preference_preference_FromString(preferenceVar->valuestring);
|
||||
return preferenceVariable;
|
||||
end:
|
||||
return 0;
|
||||
}
|
32
samples/client/petstore/c/model/preference.h
Normal file
32
samples/client/petstore/c/model/preference.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* preference.h
|
||||
*
|
||||
* A user's preference in pets
|
||||
*/
|
||||
|
||||
#ifndef _preference_H_
|
||||
#define _preference_H_
|
||||
|
||||
#include <string.h>
|
||||
#include "../external/cJSON.h"
|
||||
#include "../include/list.h"
|
||||
#include "../include/keyValuePair.h"
|
||||
#include "../include/binary.h"
|
||||
|
||||
typedef struct preference_t preference_t;
|
||||
|
||||
|
||||
// Enum for preference
|
||||
|
||||
typedef enum { openapi_petstore_preference__NULL = 0, openapi_petstore_preference__cats, openapi_petstore_preference__dogs, openapi_petstore_preference__birds, openapi_petstore_preference__fish, openapi_petstore_preference__snakes, openapi_petstore_preference__other } openapi_petstore_preference__e;
|
||||
|
||||
char* preference_preference_ToString(openapi_petstore_preference__e preference);
|
||||
|
||||
openapi_petstore_preference__e preference_preference_FromString(char* preference);
|
||||
|
||||
cJSON *preference_convertToJSON(openapi_petstore_preference__e preference);
|
||||
|
||||
openapi_petstore_preference__e preference_parseFromJSON(cJSON *preferenceJSON);
|
||||
|
||||
#endif /* _preference_H_ */
|
||||
|
@ -13,7 +13,9 @@ user_t *user_create(
|
||||
char *email,
|
||||
char *password,
|
||||
char *phone,
|
||||
int user_status
|
||||
int user_status,
|
||||
list_t* extra,
|
||||
openapi_petstore_preference__e preference
|
||||
) {
|
||||
user_t *user_local_var = malloc(sizeof(user_t));
|
||||
if (!user_local_var) {
|
||||
@ -27,6 +29,8 @@ user_t *user_create(
|
||||
user_local_var->password = password;
|
||||
user_local_var->phone = phone;
|
||||
user_local_var->user_status = user_status;
|
||||
user_local_var->extra = extra;
|
||||
user_local_var->preference = preference;
|
||||
|
||||
return user_local_var;
|
||||
}
|
||||
@ -61,6 +65,16 @@ void user_free(user_t *user) {
|
||||
free(user->phone);
|
||||
user->phone = NULL;
|
||||
}
|
||||
if (user->extra) {
|
||||
list_ForEach(listEntry, user->extra) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
|
||||
free (localKeyValue->key);
|
||||
free (localKeyValue->value);
|
||||
keyValuePair_free(localKeyValue);
|
||||
}
|
||||
list_freeList(user->extra);
|
||||
user->extra = NULL;
|
||||
}
|
||||
free(user);
|
||||
}
|
||||
|
||||
@ -130,6 +144,35 @@ cJSON *user_convertToJSON(user_t *user) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->extra
|
||||
if(user->extra) {
|
||||
cJSON *extra = cJSON_AddObjectToObject(item, "extra");
|
||||
if(extra == NULL) {
|
||||
goto fail; //primitive map container
|
||||
}
|
||||
cJSON *localMapObject = extra;
|
||||
listEntry_t *extraListEntry;
|
||||
if (user->extra) {
|
||||
list_ForEach(extraListEntry, user->extra) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*)extraListEntry->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// user->preference
|
||||
if(user->preference != openapi_petstore_preference__NULL) {
|
||||
cJSON *preference_local_JSON = preference_convertToJSON(user->preference);
|
||||
if(preference_local_JSON == NULL) {
|
||||
goto fail; // custom
|
||||
}
|
||||
cJSON_AddItemToObject(item, "preference", preference_local_JSON);
|
||||
if(item->child == NULL) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
return item;
|
||||
fail:
|
||||
if (item) {
|
||||
@ -142,6 +185,12 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
|
||||
user_t *user_local_var = NULL;
|
||||
|
||||
// define the local map for user->extra
|
||||
list_t *extraList = NULL;
|
||||
|
||||
// define the local variable for user->preference
|
||||
openapi_petstore_preference__e preference_local_nonprim = 0;
|
||||
|
||||
// user->id
|
||||
cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id");
|
||||
if (id) {
|
||||
@ -214,6 +263,32 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
}
|
||||
}
|
||||
|
||||
// user->extra
|
||||
cJSON *extra = cJSON_GetObjectItemCaseSensitive(userJSON, "extra");
|
||||
if (extra) {
|
||||
cJSON *extra_local_map = NULL;
|
||||
if(!cJSON_IsObject(extra) && !cJSON_IsNull(extra))
|
||||
{
|
||||
goto end;//primitive map container
|
||||
}
|
||||
if(cJSON_IsObject(extra))
|
||||
{
|
||||
extraList = list_createList();
|
||||
keyValuePair_t *localMapKeyPair;
|
||||
cJSON_ArrayForEach(extra_local_map, extra)
|
||||
{
|
||||
cJSON *localMapObject = extra_local_map;
|
||||
list_addElement(extraList , localMapKeyPair);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// user->preference
|
||||
cJSON *preference = cJSON_GetObjectItemCaseSensitive(userJSON, "preference");
|
||||
if (preference) {
|
||||
preference_local_nonprim = preference_parseFromJSON(preference); //custom
|
||||
}
|
||||
|
||||
|
||||
user_local_var = user_create (
|
||||
id ? id->valuedouble : 0,
|
||||
@ -223,11 +298,28 @@ user_t *user_parseFromJSON(cJSON *userJSON){
|
||||
email && !cJSON_IsNull(email) ? strdup(email->valuestring) : NULL,
|
||||
password && !cJSON_IsNull(password) ? strdup(password->valuestring) : NULL,
|
||||
phone && !cJSON_IsNull(phone) ? strdup(phone->valuestring) : NULL,
|
||||
user_status ? user_status->valuedouble : 0
|
||||
user_status ? user_status->valuedouble : 0,
|
||||
extra ? extraList : NULL,
|
||||
preference ? preference_local_nonprim : 0
|
||||
);
|
||||
|
||||
return user_local_var;
|
||||
end:
|
||||
if (extraList) {
|
||||
listEntry_t *listEntry = NULL;
|
||||
list_ForEach(listEntry, extraList) {
|
||||
keyValuePair_t *localKeyValue = (keyValuePair_t*) listEntry->data;
|
||||
free(localKeyValue->key);
|
||||
localKeyValue->key = NULL;
|
||||
keyValuePair_free(localKeyValue);
|
||||
localKeyValue = NULL;
|
||||
}
|
||||
list_freeList(extraList);
|
||||
extraList = NULL;
|
||||
}
|
||||
if (preference_local_nonprim) {
|
||||
preference_local_nonprim = 0;
|
||||
}
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
typedef struct user_t user_t;
|
||||
|
||||
#include "any_type.h"
|
||||
#include "preference.h"
|
||||
|
||||
|
||||
|
||||
@ -27,6 +29,8 @@ typedef struct user_t {
|
||||
char *password; // string
|
||||
char *phone; // string
|
||||
int user_status; //numeric
|
||||
list_t* extra; //map
|
||||
openapi_petstore_preference__e preference; //referenced enum
|
||||
|
||||
} user_t;
|
||||
|
||||
@ -38,7 +42,9 @@ user_t *user_create(
|
||||
char *email,
|
||||
char *password,
|
||||
char *phone,
|
||||
int user_status
|
||||
int user_status,
|
||||
list_t* extra,
|
||||
openapi_petstore_preference__e preference
|
||||
);
|
||||
|
||||
void user_free(user_t *user);
|
||||
|
56
samples/client/petstore/c/unit-test/test_preference.c
Normal file
56
samples/client/petstore/c/unit-test/test_preference.c
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef preference_TEST
|
||||
#define preference_TEST
|
||||
|
||||
// the following is to include only the main from the first c file
|
||||
#ifndef TEST_MAIN
|
||||
#define TEST_MAIN
|
||||
#define preference_MAIN
|
||||
#endif // TEST_MAIN
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "../external/cJSON.h"
|
||||
|
||||
#include "../model/preference.h"
|
||||
preference_t* instantiate_preference(int include_optional);
|
||||
|
||||
|
||||
|
||||
preference_t* instantiate_preference(int include_optional) {
|
||||
preference_t* preference = NULL;
|
||||
if (include_optional) {
|
||||
preference = preference_create(
|
||||
);
|
||||
} else {
|
||||
preference = preference_create(
|
||||
);
|
||||
}
|
||||
|
||||
return preference;
|
||||
}
|
||||
|
||||
|
||||
#ifdef preference_MAIN
|
||||
|
||||
void test_preference(int include_optional) {
|
||||
preference_t* preference_1 = instantiate_preference(include_optional);
|
||||
|
||||
cJSON* jsonpreference_1 = preference_convertToJSON(preference_1);
|
||||
printf("preference :\n%s\n", cJSON_Print(jsonpreference_1));
|
||||
preference_t* preference_2 = preference_parseFromJSON(jsonpreference_1);
|
||||
cJSON* jsonpreference_2 = preference_convertToJSON(preference_2);
|
||||
printf("repeating preference:\n%s\n", cJSON_Print(jsonpreference_2));
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_preference(1);
|
||||
test_preference(0);
|
||||
|
||||
printf("Hello world \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif // preference_MAIN
|
||||
#endif // preference_TEST
|
Loading…
x
Reference in New Issue
Block a user