forked from loafle/openapi-generator-original
fix cast exception with uuid default (c) (#16449)
This commit is contained in:
parent
a0350c6533
commit
e73143d777
@ -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)) {
|
||||
|
@ -722,3 +722,7 @@ definitions:
|
||||
another_property:
|
||||
type: integer
|
||||
format: int32
|
||||
uuid_property:
|
||||
type: string
|
||||
format: uuid
|
||||
default: 1111-2222-3333-4444
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user