glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
12.37k stars 1.08k forks source link

Need to declare arrays typedef/prototypes/functions #1984

Closed joelguittet closed 2 years ago

joelguittet commented 2 years ago

Hello,

I'm currently working on cJSON (https://github.com/DaveGamble/cJSON) generator. For this I need to have the list of arrays to generate typedef/prototypes/functions. I need to have the name of the array and the type of the items.

Today I'm using this code snippet to generate enum or classes, providing the types and names:

this.forEachEnum("leading-and-interposing", (enumType: EnumType, enumName: Name) =>
    //CODE
);
this.forEachObject("leading-and-interposing", (classType: ClassType, className: Name) =>
    //CODE
);

This is mainly retrieving code snippets from the C++ language generator.

Question is: is it possible to have similar code snippet to have the list of arrays ? I need to declare them before they are used in parent class. I also need to generate specific functions to manage them.

Thanks,

Joel

schani commented 2 years ago

You can use forEachType and then use matchTypeExhaustive to process the arrays.

joelguittet commented 2 years ago

Hello Mark, Thanks for the advice, I have found a solution. Joel