quicktype
quicktype copied to clipboard
Feature: Add typedef structs as an option (cJSON)
Struct definitions are restrictive and a PITA.
There should be a flag to change the code generation to use typedefs instead of structs. I may try to tackle adding this in myself, but I am not much of a typescript programmer.
So:
struct DemoAppState {
bool * green_led;
bool * red_led;
bool * user_button;
};
and
struct DemoAppState * cJSON_ParseDemoAppState(const char * s);
struct DemoAppState * cJSON_GetDemoAppStateValue(const cJSON * j);
cJSON * cJSON_CreateDemoAppState(const struct DemoAppState * x);
char * cJSON_PrintDemoAppState(const struct DemoAppState * x);
void cJSON_DeleteDemoAppState(struct DemoAppState * x);
would become:
typedef struct {
bool * green_led;
bool * red_led;
bool * user_button;
} DemoAppState;
and
DemoAppState * cJSON_ParseDemoAppState(const char * s);
DemoAppState * cJSON_GetDemoAppStateValue(const cJSON * j);
cJSON * cJSON_CreateDemoAppState(const DemoAppState * x);
char * cJSON_PrintDemoAppState(const DemoAppState * x);
void cJSON_DeleteDemoAppState(DemoAppState * x);
All other references would need to be updated within the body of the functions also.
This can be closed as doing --typedef-alias add-typedef was implemented by you ;)
https://github.com/glideapps/quicktype/blob/9b570a73a896306778940c793c0037a38815304a/packages/quicktype-core/src/language/CJSON.ts#L85