@@ -408,12 +408,12 @@ impl ToJson for Target {
408
408
}
409
409
}
410
410
411
- #[ derive( serde_derive:: Deserialize ) ]
411
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
412
412
struct LinkSelfContainedComponentsWrapper {
413
413
components : Vec < LinkSelfContainedComponents > ,
414
414
}
415
415
416
- #[ derive( serde_derive:: Deserialize ) ]
416
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
417
417
#[ serde( untagged) ]
418
418
enum TargetFamiliesJson {
419
419
Array ( StaticCow < [ StaticCow < str > ] > ) ,
@@ -429,6 +429,18 @@ impl FromStr for EndianWrapper {
429
429
}
430
430
}
431
431
crate :: json:: serde_deserialize_from_str!( EndianWrapper ) ;
432
+ impl schemars:: JsonSchema for EndianWrapper {
433
+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
434
+ "Endian" . into ( )
435
+ }
436
+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
437
+ schemars:: json_schema! ( {
438
+ "type" : "string" ,
439
+ "enum" : [ "big" , "little" ]
440
+ } )
441
+ . into ( )
442
+ }
443
+ }
432
444
433
445
/// `ExternAbi` is in `rustc_abi`, which doesn't have access to the macro and serde.
434
446
struct ExternAbiWrapper ( rustc_abi:: ExternAbi ) ;
@@ -441,16 +453,30 @@ impl FromStr for ExternAbiWrapper {
441
453
}
442
454
}
443
455
crate :: json:: serde_deserialize_from_str!( ExternAbiWrapper ) ;
456
+ impl schemars:: JsonSchema for ExternAbiWrapper {
457
+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
458
+ "ExternAbi" . into ( )
459
+ }
460
+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
461
+ let all =
462
+ rustc_abi:: ExternAbi :: ALL_VARIANTS . iter ( ) . map ( |abi| abi. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
463
+ schemars:: json_schema! ( {
464
+ "type" : "string" ,
465
+ "enum" : all,
466
+ } )
467
+ . into ( )
468
+ }
469
+ }
444
470
445
- #[ derive( serde_derive:: Deserialize ) ]
471
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
446
472
struct TargetSpecJsonMetadata {
447
473
description : Option < StaticCow < str > > ,
448
474
tier : Option < u64 > ,
449
475
host_tools : Option < bool > ,
450
476
std : Option < bool > ,
451
477
}
452
478
453
- #[ derive( serde_derive:: Deserialize ) ]
479
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
454
480
#[ serde( rename_all = "kebab-case" ) ]
455
481
// Ensure that all unexpected fields get turned into errors.
456
482
// This helps users stay up to date when the schema changes instead of silently
@@ -593,3 +619,7 @@ struct TargetSpecJson {
593
619
supports_xray : Option < bool > ,
594
620
entry_abi : Option < ExternAbiWrapper > ,
595
621
}
622
+
623
+ pub fn json_schema ( ) -> schemars:: Schema {
624
+ schemars:: schema_for!( TargetSpecJson )
625
+ }
0 commit comments