@@ -39,9 +39,7 @@ pub fn schema_object_type(
3939 let mut is_nullable = is_null ( schema) ;
4040
4141 // if it has a title, use that
42- let ( ty, json_annotations) = if let Some ( title) =
43- schema. metadata . as_ref ( ) . and_then ( |m| m. title . as_ref ( ) )
44- {
42+ let ty = if let Some ( title) = schema. metadata . as_ref ( ) . and_then ( |m| m. title . as_ref ( ) ) {
4543 replace_custom_type ( title)
4644 } else if let Some ( reference) = & schema. reference {
4745 // if it has a reference, strip the path and use that
@@ -52,25 +50,17 @@ pub fn schema_object_type(
5250 . expect ( "split should always return at least one item" ) ,
5351 ) )
5452 } else if let Some ( t) = & schema. instance_type {
55- (
56- type_from_instance_type ( schema, type_context, t, additional_structs) ?,
57- None ,
58- )
53+ type_from_instance_type ( schema, type_context, t, additional_structs) ?
5954 } else if let Some ( subschemas) = schema. subschemas . as_ref ( ) . and_then ( |s| s. any_of . as_ref ( ) ) {
6055 // check if one of them is null
61- let nullable: Option < & SchemaObject > = nullable_type ( subschemas) ?;
56+ let nullable = nullable_type ( subschemas) ?;
6257 if let Some ( non_null) = nullable {
6358 ensure ! ( subschemas. len( ) == 2 , "multiple subschemas in anyOf" ) ;
6459 is_nullable = true ;
6560 // extract non-null type
66- let GoType {
67- name,
68- json_annotations,
69- ..
70- } = schema_object_type ( non_null, type_context, additional_structs) ?;
71- // let (ty, annotations) = replace_custom_type(&name);
72- // (ty, annotations.or(json_annotations))
73- ( name, json_annotations)
61+ let GoType { name, .. } =
62+ schema_object_type ( non_null, type_context, additional_structs) ?;
63+ replace_custom_type ( & name)
7464 } else {
7565 subschema_type ( subschemas, type_context, additional_structs)
7666 . context ( "failed to get type of anyOf subschemas" ) ?
@@ -89,7 +79,6 @@ pub fn schema_object_type(
8979 Ok ( GoType {
9080 name : ty,
9181 is_nullable,
92- json_annotations, // TODO: implement
9382 } )
9483}
9584
@@ -208,11 +197,11 @@ pub fn type_from_instance_type(
208197 // for nullable array item types, we have to use a pointer type, even for basic types,
209198 // so we can pass null as elements
210199 // otherwise they would just be omitted from the array
211- if item_type. is_nullable {
200+ replace_custom_type ( & if item_type. is_nullable {
212201 format ! ( "[]*{}" , item_type. name)
213202 } else {
214203 format ! ( "[]{}" , item_type. name)
215- }
204+ } )
216205 } else {
217206 unreachable ! ( "instance type should be one of the above" )
218207 } )
@@ -244,7 +233,7 @@ pub fn subschema_type(
244233 subschemas : & [ Schema ] ,
245234 type_context : TypeContext ,
246235 additional_structs : & mut Vec < GoStruct > ,
247- ) -> Result < ( String , Option < String > ) > {
236+ ) -> Result < String > {
248237 ensure ! (
249238 subschemas. len( ) == 1 ,
250239 "multiple subschemas are not supported"
@@ -268,27 +257,26 @@ pub fn documentation(schema: &SchemaObject) -> Option<String> {
268257
269258/// Maps special types to their Go equivalents.
270259/// If the given type is not a special type, returns `None`.
271- /// Otherwise, returns a tuple of the Go type name and additional json annotations.
272- pub fn custom_type_of ( ty : & str ) -> Option < ( & str , Option < & str > ) > {
260+ pub fn custom_type_of ( ty : & str ) -> Option < & str > {
273261 match ty {
274- "Uint64" => Some ( ( "string" , None ) ) ,
275- "Uint128" => Some ( ( "string" , None ) ) ,
276- "Int64" => Some ( ( "string" , None ) ) ,
277- "Int128" => Some ( ( "string" , None ) ) ,
278- "Binary" => Some ( ( "[]byte" , None ) ) ,
279- "HexBinary" => Some ( ( "Checksum" , None ) ) ,
280- "Addr" => Some ( ( "string" , None ) ) ,
281- "Decimal" => Some ( ( "string" , None ) ) ,
282- "Decimal256" => Some ( ( "string" , None ) ) ,
283- "SignedDecimal" => Some ( ( "string" , None ) ) ,
284- "SignedDecimal256" => Some ( ( "string" , None ) ) ,
285- "Timestamp" => Some ( ( "uint64" , Some ( "string" ) ) ) ,
262+ "Uint64" => Some ( "string" ) ,
263+ "Uint128" => Some ( "string" ) ,
264+ "Int64" => Some ( "string" ) ,
265+ "Int128" => Some ( "string" ) ,
266+ "Binary" => Some ( "[]byte" ) ,
267+ "HexBinary" => Some ( "Checksum" ) ,
268+ "Addr" => Some ( "string" ) ,
269+ "Decimal" => Some ( "string" ) ,
270+ "Decimal256" => Some ( "string" ) ,
271+ "SignedDecimal" => Some ( "string" ) ,
272+ "SignedDecimal256" => Some ( "string" ) ,
273+ "Timestamp" => Some ( "uint64" ) ,
286274 _ => None ,
287275 }
288276}
289277
290- pub fn replace_custom_type ( ty : & str ) -> ( String , Option < String > ) {
278+ pub fn replace_custom_type ( ty : & str ) -> String {
291279 custom_type_of ( ty)
292- . map ( |( ty , json_annotations ) | ( ty. to_string ( ) , json_annotations . map ( String :: from ) ) )
293- . unwrap_or_else ( || ( ty. to_string ( ) , None ) )
280+ . map ( |ty| ty. to_string ( ) )
281+ . unwrap_or_else ( || ty. to_string ( ) )
294282}
0 commit comments