diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java index 2a72897b278..292af33947f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CLibcurlClientCodegen.java @@ -426,7 +426,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf } } else if (ModelUtils.isStringSchema(p)) { if (p.getDefault() != null) { - return "'" + escapeText((String) p.getDefault()) + "'"; + return "'" + escapeText(String.valueOf(p.getDefault())) + "'"; } } @@ -444,7 +444,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf } // correct "'"s into "'"s after toString() if (ModelUtils.isStringSchema(schema) && schema.getDefault() != null) { - example = (String) schema.getDefault(); + example = String.valueOf(schema.getDefault()); } if (StringUtils.isNotBlank(example) && !"null".equals(example)) { if (ModelUtils.isStringSchema(schema)) { diff --git a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml index 82276427b6f..0a8f3fda813 100644 --- a/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/2_0/c/petstore.yaml @@ -722,3 +722,7 @@ definitions: another_property: type: integer format: int32 + uuid_property: + type: string + format: uuid + default: 1111-2222-3333-4444 diff --git a/samples/client/petstore/c/docs/MappedModel.md b/samples/client/petstore/c/docs/MappedModel.md index 88489745e67..534d7a4cce3 100644 --- a/samples/client/petstore/c/docs/MappedModel.md +++ b/samples/client/petstore/c/docs/MappedModel.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **another_property** | **int** | | [optional] +**uuid_property** | **char \*** | | [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) diff --git a/samples/client/petstore/c/model/mapped_model.c b/samples/client/petstore/c/model/mapped_model.c index 4c70c720bfc..2213fb7d129 100644 --- a/samples/client/petstore/c/model/mapped_model.c +++ b/samples/client/petstore/c/model/mapped_model.c @@ -6,13 +6,15 @@ MappedModel_t *MappedModel_create( - int another_property + int another_property, + char *uuid_property ) { MappedModel_t *MappedModel_local_var = malloc(sizeof(MappedModel_t)); if (!MappedModel_local_var) { return NULL; } MappedModel_local_var->another_property = another_property; + MappedModel_local_var->uuid_property = uuid_property; return MappedModel_local_var; } @@ -23,6 +25,10 @@ void MappedModel_free(MappedModel_t *MappedModel) { return ; } listEntry_t *listEntry; + if (MappedModel->uuid_property) { + free(MappedModel->uuid_property); + MappedModel->uuid_property = NULL; + } free(MappedModel); } @@ -36,6 +42,14 @@ cJSON *MappedModel_convertToJSON(MappedModel_t *MappedModel) { } } + + // MappedModel->uuid_property + if(MappedModel->uuid_property) { + if(cJSON_AddStringToObject(item, "uuid_property", MappedModel->uuid_property) == NULL) { + goto fail; //String + } + } + return item; fail: if (item) { @@ -57,9 +71,19 @@ MappedModel_t *MappedModel_parseFromJSON(cJSON *MappedModelJSON){ } } + // MappedModel->uuid_property + cJSON *uuid_property = cJSON_GetObjectItemCaseSensitive(MappedModelJSON, "uuid_property"); + if (uuid_property) { + if(!cJSON_IsString(uuid_property) && !cJSON_IsNull(uuid_property)) + { + goto end; //String + } + } + MappedModel_local_var = MappedModel_create ( - another_property ? another_property->valuedouble : 0 + another_property ? another_property->valuedouble : 0, + uuid_property && !cJSON_IsNull(uuid_property) ? strdup(uuid_property->valuestring) : NULL ); return MappedModel_local_var; diff --git a/samples/client/petstore/c/model/mapped_model.h b/samples/client/petstore/c/model/mapped_model.h index 244aab44cbc..36c7c8994c7 100644 --- a/samples/client/petstore/c/model/mapped_model.h +++ b/samples/client/petstore/c/model/mapped_model.h @@ -20,11 +20,13 @@ typedef struct MappedModel_t MappedModel_t; typedef struct MappedModel_t { int another_property; //numeric + char *uuid_property; // string } MappedModel_t; MappedModel_t *MappedModel_create( - int another_property + int another_property, + char *uuid_property ); void MappedModel_free(MappedModel_t *MappedModel);