@@ -11,7 +11,7 @@ use log::{debug, info};
1111use output:: OutputSpace ;
1212use proc_macro2:: TokenStream ;
1313use quote:: { format_ident, quote, ToTokens } ;
14- use schemars:: schema:: { Metadata , RootSchema , Schema } ;
14+ use schemars:: schema:: { InstanceType , Metadata , RootSchema , Schema } ;
1515use thiserror:: Error ;
1616use type_entry:: {
1717 StructPropertyState , TypeEntry , TypeEntryDetails , TypeEntryNative , TypeEntryNewtype ,
@@ -1212,6 +1212,63 @@ impl TypeNewtype<'_> {
12121212 }
12131213}
12141214
1215+ /// A re-ordering of JSON schema instance types that puts integer values before
1216+ /// number values.
1217+ ///
1218+ /// This is used for untagged enum generation to ensure that integer values
1219+ /// are matched before number values.
1220+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
1221+ pub enum ReorderedInstanceType {
1222+ /// The JSON schema instance type `null`.
1223+ Null ,
1224+
1225+ /// The JSON schema instance type `boolean`.
1226+ Boolean ,
1227+
1228+ /// The JSON schema instance type `integer`.
1229+ Integer ,
1230+
1231+ /// The JSON schema instance type `number`.
1232+ Number ,
1233+
1234+ /// The JSON schema instance type `string`.
1235+ String ,
1236+
1237+ /// The JSON schema instance type `array`.
1238+ Array ,
1239+
1240+ /// The JSON schema instance type `object`.
1241+ Object ,
1242+ }
1243+
1244+ impl From < InstanceType > for ReorderedInstanceType {
1245+ fn from ( instance_type : InstanceType ) -> Self {
1246+ match instance_type {
1247+ InstanceType :: Null => Self :: Null ,
1248+ InstanceType :: Boolean => Self :: Boolean ,
1249+ InstanceType :: Object => Self :: Object ,
1250+ InstanceType :: Array => Self :: Array ,
1251+ InstanceType :: Integer => Self :: Integer ,
1252+ InstanceType :: Number => Self :: Number ,
1253+ InstanceType :: String => Self :: String ,
1254+ }
1255+ }
1256+ }
1257+
1258+ impl From < ReorderedInstanceType > for InstanceType {
1259+ fn from ( instance_type : ReorderedInstanceType ) -> Self {
1260+ match instance_type {
1261+ ReorderedInstanceType :: Null => Self :: Null ,
1262+ ReorderedInstanceType :: Boolean => Self :: Boolean ,
1263+ ReorderedInstanceType :: Object => Self :: Object ,
1264+ ReorderedInstanceType :: Array => Self :: Array ,
1265+ ReorderedInstanceType :: Integer => Self :: Integer ,
1266+ ReorderedInstanceType :: Number => Self :: Number ,
1267+ ReorderedInstanceType :: String => Self :: String ,
1268+ }
1269+ }
1270+ }
1271+
12151272#[ cfg( test) ]
12161273mod tests {
12171274 use schema:: Schema ;
0 commit comments