quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

Feature: Add typedef structs as an option (cJSON)

Open pseudotronics opened this issue 2 years ago • 1 comments

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.

pseudotronics avatar Jul 27 '23 12:07 pseudotronics

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

mundusnine avatar Sep 28 '23 12:09 mundusnine