@@ -415,12 +415,12 @@ impl ToJson for Target {
415
415
}
416
416
}
417
417
418
- #[ derive( serde_derive:: Deserialize ) ]
418
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
419
419
struct LinkSelfContainedComponentsWrapper {
420
420
components : Vec < LinkSelfContainedComponents > ,
421
421
}
422
422
423
- #[ derive( serde_derive:: Deserialize ) ]
423
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
424
424
#[ serde( untagged) ]
425
425
enum TargetFamiliesJson {
426
426
Array ( StaticCow < [ StaticCow < str > ] > ) ,
@@ -436,6 +436,18 @@ impl FromStr for EndianWrapper {
436
436
}
437
437
}
438
438
crate :: json:: serde_deserialize_from_str!( EndianWrapper ) ;
439
+ impl schemars:: JsonSchema for EndianWrapper {
440
+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
441
+ "Endian" . into ( )
442
+ }
443
+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
444
+ schemars:: json_schema! ( {
445
+ "type" : "string" ,
446
+ "enum" : [ "big" , "little" ]
447
+ } )
448
+ . into ( )
449
+ }
450
+ }
439
451
440
452
/// `ExternAbi` is in `rustc_abi`, which doesn't have access to the macro and serde.
441
453
struct ExternAbiWrapper ( rustc_abi:: ExternAbi ) ;
@@ -448,16 +460,30 @@ impl FromStr for ExternAbiWrapper {
448
460
}
449
461
}
450
462
crate :: json:: serde_deserialize_from_str!( ExternAbiWrapper ) ;
463
+ impl schemars:: JsonSchema for ExternAbiWrapper {
464
+ fn schema_name ( ) -> std:: borrow:: Cow < ' static , str > {
465
+ "ExternAbi" . into ( )
466
+ }
467
+ fn json_schema ( _: & mut schemars:: SchemaGenerator ) -> schemars:: Schema {
468
+ let all =
469
+ rustc_abi:: ExternAbi :: ALL_VARIANTS . iter ( ) . map ( |abi| abi. as_str ( ) ) . collect :: < Vec < _ > > ( ) ;
470
+ schemars:: json_schema! ( {
471
+ "type" : "string" ,
472
+ "enum" : all,
473
+ } )
474
+ . into ( )
475
+ }
476
+ }
451
477
452
- #[ derive( serde_derive:: Deserialize ) ]
478
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
453
479
struct TargetSpecJsonMetadata {
454
480
description : Option < StaticCow < str > > ,
455
481
tier : Option < u64 > ,
456
482
host_tools : Option < bool > ,
457
483
std : Option < bool > ,
458
484
}
459
485
460
- #[ derive( serde_derive:: Deserialize ) ]
486
+ #[ derive( serde_derive:: Deserialize , schemars :: JsonSchema ) ]
461
487
#[ serde( rename_all = "kebab-case" ) ]
462
488
// Ensure that all unexpected fields get turned into errors.
463
489
// This helps users stay up to date when the schema changes instead of silently
@@ -601,3 +627,7 @@ struct TargetSpecJson {
601
627
supports_xray : Option < bool > ,
602
628
entry_abi : Option < ExternAbiWrapper > ,
603
629
}
630
+
631
+ pub fn json_schema ( ) -> schemars:: Schema {
632
+ schemars:: schema_for!( TargetSpecJson )
633
+ }
0 commit comments