Skip to content

Commit

Permalink
[C][Client] Remove broken intToStr() macro, update samples
Browse files Browse the repository at this point in the history
Note: this does not fix anything else; for example all numerical
types, including float and double, are still incorrectly cast to
to long int before string conversion.
  • Loading branch information
imaami committed Jan 1, 2025
1 parent 8f4cfa3 commit 6608bcd
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)

{{#operations}}
{{#operation}}
Expand Down Expand Up @@ -140,7 +135,7 @@ end:
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");

char localVarBuff_{{paramName}}[256];
intToStr(localVarBuff_{{paramName}}, {{paramName}});
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long){{paramName}});

localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});

Expand All @@ -153,7 +148,7 @@ end:
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");

char localVarBuff_{{paramName}}[256];
intToStr(localVarBuff_{{paramName}}, *{{paramName}});
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long)*{{paramName}});

localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});

Expand All @@ -166,9 +161,7 @@ end:
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");

char localVarBuff_{{paramName}}[256];
intToStr(localVarBuff_{{paramName}}, {{paramName}});

localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", (long){{paramName}});

{{/isFloat}}
{{#isLong}}
Expand All @@ -179,7 +172,7 @@ end:
snprintf(localVarToReplace_{{paramName}}, sizeOfPathParams_{{paramName}}, "{%s}", "{{baseName}}");

char localVarBuff_{{paramName}}[256];
intToStr(localVarBuff_{{paramName}}, {{paramName}});
snprintf(localVarBuff_{{paramName}}, sizeof localVarBuff_{{paramName}}, "%ld", {{paramName}});

localVarPath = strReplace(localVarPath, localVarToReplace_{{paramName}}, localVarBuff_{{paramName}});

Expand Down
5 changes: 0 additions & 5 deletions samples/client/others/c/bearerAuth/api/DefaultAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)


// Returns private information.
Expand Down
15 changes: 5 additions & 10 deletions samples/client/petstore/c-useJsonUnformatted/api/PetAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)

// Functions for enum STATUS for PetAPI_findPetsByStatus

Expand Down Expand Up @@ -159,7 +154,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -501,7 +496,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -658,7 +653,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -965,7 +960,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -1078,7 +1073,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata,
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down
7 changes: 1 addition & 6 deletions samples/client/petstore/c-useJsonUnformatted/api/StoreAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)

// Functions for enum RATING for StoreAPI_sendRating

Expand Down Expand Up @@ -245,7 +240,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId)
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId");

char localVarBuff_orderId[256];
intToStr(localVarBuff_orderId, orderId);
snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId);

localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId);

Expand Down
5 changes: 0 additions & 5 deletions samples/client/petstore/c-useJsonUnformatted/api/UserAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)


// Create user
Expand Down
15 changes: 5 additions & 10 deletions samples/client/petstore/c/api/PetAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)

// Functions for enum STATUS for PetAPI_findPetsByStatus

Expand Down Expand Up @@ -159,7 +154,7 @@ PetAPI_deletePet(apiClient_t *apiClient, long petId, char *api_key)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -501,7 +496,7 @@ PetAPI_getPetById(apiClient_t *apiClient, long petId)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -658,7 +653,7 @@ PetAPI_isPetAvailable(apiClient_t *apiClient, long petId)
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -965,7 +960,7 @@ PetAPI_updatePetWithForm(apiClient_t *apiClient, long petId, char *name, char *s
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down Expand Up @@ -1078,7 +1073,7 @@ PetAPI_uploadFile(apiClient_t *apiClient, long petId, char *additionalMetadata,
snprintf(localVarToReplace_petId, sizeOfPathParams_petId, "{%s}", "petId");

char localVarBuff_petId[256];
intToStr(localVarBuff_petId, petId);
snprintf(localVarBuff_petId, sizeof localVarBuff_petId, "%ld", petId);

localVarPath = strReplace(localVarPath, localVarToReplace_petId, localVarBuff_petId);

Expand Down
7 changes: 1 addition & 6 deletions samples/client/petstore/c/api/StoreAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)

// Functions for enum RATING for StoreAPI_sendRating

Expand Down Expand Up @@ -245,7 +240,7 @@ StoreAPI_getOrderById(apiClient_t *apiClient, long orderId)
snprintf(localVarToReplace_orderId, sizeOfPathParams_orderId, "{%s}", "orderId");

char localVarBuff_orderId[256];
intToStr(localVarBuff_orderId, orderId);
snprintf(localVarBuff_orderId, sizeof localVarBuff_orderId, "%ld", orderId);

localVarPath = strReplace(localVarPath, localVarToReplace_orderId, localVarBuff_orderId);

Expand Down
5 changes: 0 additions & 5 deletions samples/client/petstore/c/api/UserAPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

#define MAX_NUMBER_LENGTH 16
#define MAX_BUFFER_LENGTH 4096
#define intToStr(dst, src) \
do {\
char dst[256];\
snprintf(dst, 256, "%ld", (long int)(src));\
}while(0)


// Create user
Expand Down

0 comments on commit 6608bcd

Please sign in to comment.