Add schema_id(), handles different types with the same name (#247)
This commit is contained in:
		
							parent
							
								
									53bb51cb25
								
							
						
					
					
						commit
						342b2dff33
					
				
					 26 changed files with 415 additions and 34 deletions
				
			
		
							
								
								
									
										41
									
								
								schemars/tests/expected/same_name.json
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								schemars/tests/expected/same_name.json
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| { | ||||
|   "$schema": "http://json-schema.org/draft-07/schema#", | ||||
|   "title": "Config2", | ||||
|   "type": "object", | ||||
|   "required": [ | ||||
|     "a_cfg", | ||||
|     "b_cfg" | ||||
|   ], | ||||
|   "properties": { | ||||
|     "a_cfg": { | ||||
|       "$ref": "#/definitions/Config" | ||||
|     }, | ||||
|     "b_cfg": { | ||||
|       "$ref": "#/definitions/Config2" | ||||
|     } | ||||
|   }, | ||||
|   "definitions": { | ||||
|     "Config": { | ||||
|       "type": "object", | ||||
|       "required": [ | ||||
|         "test" | ||||
|       ], | ||||
|       "properties": { | ||||
|         "test": { | ||||
|           "type": "string" | ||||
|         } | ||||
|       } | ||||
|     }, | ||||
|     "Config2": { | ||||
|       "type": "object", | ||||
|       "required": [ | ||||
|         "test2" | ||||
|       ], | ||||
|       "properties": { | ||||
|         "test2": { | ||||
|           "type": "string" | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										35
									
								
								schemars/tests/same_name.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								schemars/tests/same_name.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| mod util; | ||||
| use schemars::JsonSchema; | ||||
| use util::*; | ||||
| 
 | ||||
| mod a { | ||||
|     use super::*; | ||||
| 
 | ||||
|     #[allow(dead_code)] | ||||
|     #[derive(JsonSchema)] | ||||
|     pub struct Config { | ||||
|         test: String, | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| mod b { | ||||
|     use super::*; | ||||
| 
 | ||||
|     #[allow(dead_code)] | ||||
|     #[derive(JsonSchema)] | ||||
|     pub struct Config { | ||||
|         test2: String, | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[allow(dead_code)] | ||||
| #[derive(JsonSchema)] | ||||
| pub struct Config2 { | ||||
|     a_cfg: a::Config, | ||||
|     b_cfg: b::Config, | ||||
| } | ||||
| 
 | ||||
| #[test] | ||||
| fn same_name() -> TestResult { | ||||
|     test_default_generated_schema::<Config2>("same_name") | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Graham Esau
						Graham Esau