Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Enums not interpreted correcly #28

Open
Ancillius opened this issue Jan 27, 2020 · 6 comments
Open

Schema Enums not interpreted correcly #28

Ancillius opened this issue Jan 27, 2020 · 6 comments

Comments

@Ancillius
Copy link

Example schema:
"https://raw.githubusercontent.com/EDSM-NET/EDDN/master/schemas/commodity-v3.0.json"

Problem:
levelType ist defined as:

        "levelType": {
            "enum"          : [0, 1, 2, 3, ""],
            "description"   : "Note: A value of \"\" indicates that the commodity is not normally sold/purchased at this station, but is currently temporarily for sale/purchase"
        }
    }
    root: Commodity
    "src/resources/commodity-v3.0.json");

Now panics with:

  --> src/main.rs:24:1
   |
24 | / schemafy::schemafy!(
25 | |     root: Commodity
26 | |     "src/resources/commodity-v3.0.json");
   | |_________________________________________^
   |
   = help: message: Expected string for enum got `0`

I tried to fix that like that but did not succeed.

--- a/schemafy-0.5.0/src/lib.rs
+++ b/schemafy-0.5.0-bak/src/lib.rs
@@ -500,11 +500,16 @@ impl<'r> Expander<'r> {
                     Value::String(ref v) => {
                         let pascal_case_variant = v.to_pascal_case();
                         let variant_name =
+                        if v == "" {^M
+                            let v = syn::Ident::new("Empty", Span::call_site());^M
+                            quote!(#v)^M
+                        } else {^M
                             rename_keyword("", &pascal_case_variant).unwrap_or_else(|| {
                                 let v = syn::Ident::new(&pascal_case_variant, Span::call_site());
                                 quote!(#v)
-                            });
-                        Some(if pascal_case_variant == *v {
+                            })^M
+                        };^M
+                        Some(if *v != "" && pascal_case_variant == *v {^M
                             variant_name
                         } else {
                             quote! {
@@ -513,6 +518,14 @@ impl<'r> Expander<'r> {
                             }
                         })
                     }
+                    Value::Number(ref v) => {^M
+                        let variant_name = syn::Ident::new(&format!("No{}", v), Span::call_site());^M
+                        let original_name = format!("{}", v);^M
+                        Some(quote! {^M
+                            #[serde(rename = #original_name)]^M
+                            #variant_name^M
+                        })^M
+                    }^M
                     Value::Null => {
                         optional = true;
                         None

This compiles and generates a Commodity struct but not a correct one.

@Ancillius
Copy link
Author

A sample JSON to parse would be:
{"$schemaRef": "https://eddn.edcd.io/schemas/commodity/3", "header": {"gatewayTimestamp": "2020-01-27T15:38:22.269569Z", "softwareName": "E:D Market Connector [Windows]", "softwareVersion": "3.4.3.0", "uploaderID": "e32dfe8ecd3b4922299554c39dbd310c99117a8e"}, "message": {"commodities": [{"buyPrice": 0, "demand": 22867, "demandBracket": 3, "meanPrice": 3113, "name": "advancedcatalysers", "sellPrice": 3594, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 23523, "demandBracket": 3, "meanPrice": 1475, "name": "advancedmedicines", "sellPrice": 1798, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 112, "demandBracket": 3, "meanPrice": 3208, "name": "agronomictreatment", "sellPrice": 3590, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 1122, "demandBracket": 3, "meanPrice": 261541, "name": "alexandrite", "sellPrice": 238643, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 154110, "demandBracket": 3, "meanPrice": 323, "name": "algae", "sellPrice": 642, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 976115, "demandBracket": 2, "meanPrice": 473, "name": "aluminium", "sellPrice": 682, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 16885, "demandBracket": 2, "meanPrice": 1526, "name": "animalmeat", "sellPrice": 1901, "stock": 0, "stockBracket": 0}, {"buyPrice": 298, "demand": 1, "demandBracket": 0, "meanPrice": 473, "name": "atmosphericextractors", "sellPrice": 277, "stock": 53087, "stockBracket": 3}, {"buyPrice": 0, "demand": 25271, "demandBracket": 3, "meanPrice": 3863, "name": "autofabricators", "sellPrice": 4491, "stock": 0, "stockBracket": 0}, {"buyPrice": 223, "demand": 1, "demandBracket": 0, "meanPrice": 436, "name": "basicmedicines", "sellPrice": 201, "stock": 35295, "stockBracket": 3}, {"buyPrice": 0, "demand": 705675, "demandBracket": 3, "meanPrice": 261, "name": "bauxite", "sellPrice": 693, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 73575, "demandBracket": 2, "meanPrice": 404, "name": "beer", "sellPrice": 415, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 1122, "demandBracket": 3, "meanPrice": 191191, "name": "benitoite", "sellPrice": 167822, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 168170, "demandBracket": 3, "meanPrice": 2517, "name": "bertrandite", "sellPrice": 3225, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 67582, "demandBracket": 2, "meanPrice": 8137, "name": "beryllium", "sellPrice": 9054, "stock": 0, "stockBracket": 0}, {"buyPrice": 44, "demand": 1, "demandBracket": 0, "meanPrice": 343, "name": "biowaste", "sellPrice": 27, "stock": 12089, "stockBracket": 3}, {"buyPrice": 862, "demand": 1, "demandBracket": 0, "meanPrice": 1199, "name": "buildingfabricators", "sellPrice": 822, "stock": 332618, "stockBracket": 3}, {"buyPrice": 0, "demand": 570632, "demandBracket": 3, "meanPrice": 393, "name": "ceramiccomposites", "sellPrice": 733, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 23649, "demandBracket": 3, "meanPrice": 672, "name": "chemicalwaste", "sellPrice": 676, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 24474, "demandBracket": 2, "meanPrice": 459, "name": "clothing", "sellPrice": 814, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 35261, "demandBracket": 3, "meanPrice": 5984, "name": "cmmcomposite", "sellPrice": 6763, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 95203, "demandBracket": 2, "meanPrice": 755, "name": "cobalt", "sellPrice": 1087, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 5425, "demandBracket": 2, "meanPrice": 1505, "name": "coffee", "sellPrice": 1790, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 266582, "demandBracket": 3, "meanPrice": 1473, "name": "coltan", "sellPrice": 2056, "stock": 0, "stockBracket": 0}, {"buyPrice": 400, "demand": 1, "demandBracket": 0, "meanPrice": 691, "name": "computercomponents", "sellPrice": 373, "stock": 4114, "stockBracket": 3}, {"buyPrice": 0, "demand": 272682, "demandBracket": 3, "meanPrice": 659, "name": "conductivefabrics", "sellPrice": 1035, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 8364, "demandBracket": 3, "meanPrice": 6810, "name": "consumertechnology", "sellPrice": 7627, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 119886, "demandBracket": 3, "meanPrice": 1886, "name": "coolinghoses", "sellPrice": 1879, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 681694, "demandBracket": 2, "meanPrice": 612, "name": "copper", "sellPrice": 995, "stock": 0, "stockBracket": 0}, {"buyPrice": 1797, "demand": 1, "demandBracket": 0, "meanPrice": 2101, "name": "cropharvesters", "sellPrice": 1742, "stock": 37611, "stockBracket": 3}, {"buyPrice": 0, "demand": 28077, "demandBracket": 3, "meanPrice": 2330, "name": "cryolite", "sellPrice": 2904, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 808, "demandBracket": 3, "meanPrice": 16964, "name": "damagedescapepod", "sellPrice": 17170, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 7191, "demandBracket": 2, "meanPrice": 659, "name": "domesticappliances", "sellPrice": 949, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 14105, "demandBracket": 3, "meanPrice": 2438, "name": "emergencypowercells", "sellPrice": 2904, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 17190, "demandBracket": 3, "meanPrice": 1992, "name": "exhaustmanifold", "sellPrice": 2374, "stock": 0, "stockBracket": 0}, {"buyPrice": 211, "demand": 1, "demandBracket": 0, "meanPrice": 419, "name": "explosives", "sellPrice": 190, "stock": 71012, "stockBracket": 3}, {"buyPrice": 0, "demand": 53313, "demandBracket": 3, "meanPrice": 642, "name": "fish", "sellPrice": 945, "stock": 0, "stockBracket": 0}, {"buyPrice": 52, "demand": 1, "demandBracket": 0, "meanPrice": 225, "name": "foodcartridges", "sellPrice": 34, "stock": 355074, "stockBracket": 3}, {"buyPrice": 0, "demand": 7305, "demandBracket": 1, "meanPrice": 530, "name": "fruitandvegetables", "sellPrice": 343, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 30972, "demandBracket": 3, "meanPrice": 1959, "name": "gallite", "sellPrice": 2620, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 96966, "demandBracket": 2, "meanPrice": 5068, "name": "gallium", "sellPrice": 5911, "stock": 0, "stockBracket": 0}, {"buyPrice": 1456, "demand": 1, "demandBracket": 0, "meanPrice": 1857, "name": "geologicalequipment", "sellPrice": 1411, "stock": 4702, "stockBracket": 3}, {"buyPrice": 0, "demand": 116359, "demandBracket": 3, "meanPrice": 9848, "name": "gold", "sellPrice": 10995, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 200877, "demandBracket": 3, "meanPrice": 1052, "name": "goslarite", "sellPrice": 1463, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 69738, "demandBracket": 2, "meanPrice": 434, "name": "grain", "sellPrice": 411, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 1122, "demandBracket": 3, "meanPrice": 249621, "name": "grandidierite", "sellPrice": 220239, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 357869, "demandBracket": 3, "meanPrice": 572, "name": "hazardousenvironmentsuits", "sellPrice": 823, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 88863, "demandBracket": 3, "meanPrice": 467, "name": "heliostaticfurnaces", "sellPrice": 740, "stock": 0, "stockBracket": 0}, {"buyPrice": 1456, "demand": 1, "demandBracket": 0, "meanPrice": 1728, "name": "hnshockmount", "sellPrice": 1411, "stock": 44075, "stockBracket": 3}, {"buyPrice": 0, "demand": 220, "demandBracket": 3, "meanPrice": 34603, "name": "hostage", "sellPrice": 34453, "stock": 0, "stockBracket": 0}, {"buyPrice": 85, "demand": 1, "demandBracket": 0, "meanPrice": 108, "name": "hydrogenfuel", "sellPrice": 80, "stock": 248552, "stockBracket": 3}, {"buyPrice": 0, "demand": 439840, "demandBracket": 3, "meanPrice": 1209, "name": "hydrogenperoxide", "sellPrice": 1184, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 186116, "demandBracket": 3, "meanPrice": 2232, "name": "indite", "sellPrice": 2904, "stock": 0, "stockBracket": 0}, {"buyPrice": 5070, "demand": 1, "demandBracket": 0, "meanPrice": 5650, "name": "indium", "sellPrice": 4986, "stock": 100947, "stockBracket": 2}, {"buyPrice": 0, "demand": 22332, "demandBracket": 3, "meanPrice": 10692, "name": "insulatingmembrane", "sellPrice": 11715, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 660228, "demandBracket": 3, "meanPrice": 426, "name": "leather", "sellPrice": 709, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 273529, "demandBracket": 3, "meanPrice": 710, "name": "lepidolite", "sellPrice": 1184, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 309701, "demandBracket": 3, "meanPrice": 434, "name": "liquidoxygen", "sellPrice": 739, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 2860, "demandBracket": 2, "meanPrice": 791, "name": "liquor", "sellPrice": 1252, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 244470, "demandBracket": 2, "meanPrice": 1697, "name": "lithium", "sellPrice": 2195, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 50364, "demandBracket": 3, "meanPrice": 5672, "name": "lithiumhydroxide", "sellPrice": 5658, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 7739, "demandBracket": 3, "meanPrice": 295246, "name": "lowtemperaturediamond", "sellPrice": 249949, "stock": 0, "stockBracket": 0}, {"buyPrice": 3594, "demand": 1, "demandBracket": 0, "meanPrice": 3978, "name": "marinesupplies", "sellPrice": 3490, "stock": 22919, "stockBracket": 3}, {"buyPrice": 0, "demand": 130252, "demandBracket": 3, "meanPrice": 955, "name": "methaneclathrate", "sellPrice": 927, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 9404, "demandBracket": 3, "meanPrice": 5624, "name": "microcontrollers", "sellPrice": 6370, "stock": 0, "stockBracket": 0}, {"buyPrice": 617, "demand": 1, "demandBracket": 0, "meanPrice": 901, "name": "militarygradefabrics", "sellPrice": 587, "stock": 4342, "stockBracket": 3}, {"buyPrice": 455, "demand": 1, "demandBracket": 0, "meanPrice": 728, "name": "mineralextractors", "sellPrice": 431, "stock": 111069, "stockBracket": 3}, {"buyPrice": 0, "demand": 237748, "demandBracket": 2, "meanPrice": 396, "name": "mineraloil", "sellPrice": 637, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 435, "demandBracket": 3, "meanPrice": 228014, "name": "monazite", "sellPrice": 216570, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 1122, "demandBracket": 3, "meanPrice": 244579, "name": "musgravite", "sellPrice": 220631, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 299793, "demandBracket": 3, "meanPrice": 679, "name": "naturalfabrics", "sellPrice": 926, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 614, "demandBracket": 1, "meanPrice": 1924, "name": "nonlethalweapons", "sellPrice": 1803, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 220, "demandBracket": 3, "meanPrice": 30358, "name": "occupiedcryopod", "sellPrice": 30206, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 435, "demandBracket": 3, "meanPrice": 181820, "name": "opal", "sellPrice": 155583, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 81099, "demandBracket": 3, "meanPrice": 17138, "name": "osmium", "sellPrice": 17170, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 2303, "demandBracket": 3, "meanPrice": 87461, "name": "painite", "sellPrice": 76754, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 94615, "demandBracket": 3, "meanPrice": 12954, "name": "palladium", "sellPrice": 14190, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 4393, "demandBracket": 3, "meanPrice": 6834, "name": "performanceenhancers", "sellPrice": 7627, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 220, "demandBracket": 3, "meanPrice": 9540, "name": "personaleffects", "sellPrice": 9452, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 7053, "demandBracket": 3, "meanPrice": 42494, "name": "platinum", "sellPrice": 42560, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 859768, "demandBracket": 2, "meanPrice": 308, "name": "polymers", "sellPrice": 547, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 58848, "demandBracket": 2, "meanPrice": 628, "name": "powergenerators", "sellPrice": 1092, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 71109, "demandBracket": 3, "meanPrice": 8620, "name": "praseodymium", "sellPrice": 8618, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 4764, "demandBracket": 3, "meanPrice": 6803, "name": "progenitorcells", "sellPrice": 7627, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 172222, "demandBracket": 3, "meanPrice": 1664, "name": "pyrophyllite", "sellPrice": 2156, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 2463, "demandBracket": 2, "meanPrice": 2216, "name": "reactivearmour", "sellPrice": 2243, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 86257, "demandBracket": 3, "meanPrice": 6056, "name": "resonatingseparators", "sellPrice": 6763, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 906, "demandBracket": 3, "meanPrice": 200164, "name": "rhodplumsite", "sellPrice": 189484, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 65425, "demandBracket": 3, "meanPrice": 2038, "name": "robotics", "sellPrice": 2494, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 480774, "demandBracket": 3, "meanPrice": 448, "name": "rutile", "sellPrice": 887, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 45251, "demandBracket": 3, "meanPrice": 15121, "name": "samarium", "sellPrice": 15119, "stock": 0, "stockBracket": 0}, {"buyPrice": 128, "demand": 1, "demandBracket": 0, "meanPrice": 253, "name": "scrap", "sellPrice": 106, "stock": 105155, "stockBracket": 3}, {"buyPrice": 0, "demand": 775143, "demandBracket": 3, "meanPrice": 1095, "name": "semiconductors", "sellPrice": 1519, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 1122, "demandBracket": 3, "meanPrice": 218580, "name": "serendibite", "sellPrice": 192701, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 204509, "demandBracket": 3, "meanPrice": 4769, "name": "silver", "sellPrice": 5612, "stock": 0, "stockBracket": 0}, {"buyPrice": 748, "demand": 1, "demandBracket": 0, "meanPrice": 1079, "name": "skimercomponents", "sellPrice": 712, "stock": 4898, "stockBracket": 3}, {"buyPrice": 0, "demand": 23508, "demandBracket": 2, "meanPrice": 6477, "name": "superconductors", "sellPrice": 7493, "stock": 0, "stockBracket": 0}, {"buyPrice": 400, "demand": 1, "demandBracket": 0, "meanPrice": 663, "name": "surfacestabilisers", "sellPrice": 373, "stock": 60495, "stockBracket": 3}, {"buyPrice": 400, "demand": 1, "demandBracket": 0, "meanPrice": 647, "name": "survivalequipment", "sellPrice": 373, "stock": 2351, "stockBracket": 3}, {"buyPrice": 0, "demand": 800413, "demandBracket": 3, "meanPrice": 360, "name": "syntheticfabrics", "sellPrice": 712, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 15594, "demandBracket": 3, "meanPrice": 487, "name": "syntheticmeat", "sellPrice": 797, "stock": 0, "stockBracket": 0}, {"buyPrice": 3316, "demand": 1, "demandBracket": 0, "meanPrice": 3947, "name": "tantalum", "sellPrice": 3220, "stock": 137301, "stockBracket": 2}, {"buyPrice": 0, "demand": 15741, "demandBracket": 2, "meanPrice": 1693, "name": "tea", "sellPrice": 2088, "stock": 0, "stockBracket": 0}, {"buyPrice": 211, "demand": 1, "demandBracket": 0, "meanPrice": 447, "name": "thermalcoolingunits", "sellPrice": 190, "stock": 108131, "stockBracket": 3}, {"buyPrice": 0, "demand": 349662, "demandBracket": 2, "meanPrice": 1115, "name": "titanium", "sellPrice": 1514, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 57312, "demandBracket": 3, "meanPrice": 990, "name": "uraninite", "sellPrice": 1522, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 162197, "demandBracket": 2, "meanPrice": 2757, "name": "uranium", "sellPrice": 3329, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 220, "demandBracket": 3, "meanPrice": 20533, "name": "usscargoblackbox", "sellPrice": 20408, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 132060, "demandBracket": 2, "meanPrice": 268, "name": "water", "sellPrice": 619, "stock": 0, "stockBracket": 0}, {"buyPrice": 211, "demand": 1, "demandBracket": 0, "meanPrice": 411, "name": "waterpurifiers", "sellPrice": 190, "stock": 544222, "stockBracket": 3}, {"buyPrice": 0, "demand": 35206, "demandBracket": 2, "meanPrice": 484, "name": "wine", "sellPrice": 454, "stock": 0, "stockBracket": 0}, {"buyPrice": 0, "demand": 2194, "demandBracket": 3, "meanPrice": 9031, "name": "wreckagecomponents", "sellPrice": 9161, "stock": 0, "stockBracket": 0}], "economies": [{"name": "Industrial", "proportion": 0.67}, {"name": "Refinery", "proportion": 0.33}], "marketId": 3228922368, "prohibited": ["BasicNarcotics", "BattleWeapons", "BootlegLiquor", "CombatStabilisers", "ImperialSlaves", "Landmines", "NerveAgents", "PersonalWeapons", "Slaves", "Tobacco"], "stationName": "McNair Gateway", "systemName": "Luyten's Star", "timestamp": "2020-01-27T15:38:19Z"}}

@Ancillius
Copy link
Author

Oh and to be said, this project is awesome. Thanks for your work!

@Marwes
Copy link
Owner

Marwes commented Jan 28, 2020

If the enum only contained numbers we could have just generated the enum with the attribute from https://github.com/dtolnay/serde-repr . But since there are both integers and strings that won't work, and neither will annotating the number variants with #[serde(with = "...")] I think.

This probably requires us to generate a fully custom implementation of Serialize/Deserialize to handle all cases :/

A simpler but more manual approach could be to let users specify a set of types for which schemafy should skip generating any Serialize/Deserialize implementation. Allowing users to manually write implementations for the cases that schemafy fails to handle.

@Ancillius
Copy link
Author

That would absolutely be a solution. Can this be done already?

@Marwes
Copy link
Owner

Marwes commented Jan 28, 2020

No, none of these approaches are implemented atm though any would be acceptable. I am not actively working on this crate either so if it is something you need I am afraid you will need to implement it yourself (or use something else).

@Ancillius
Copy link
Author

I see, if I succeed (I am very new to rust, so it is unlikely) I will create a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants