@ -582,13 +582,29 @@ class OpenAPIBuilder implements Builder {
parameter . schema ! ,
parameter . schema ! ,
) ;
) ;
if ( result . name = = ' String ' & & parameter . schema ? . pattern ! = null ) {
if ( result . name = = ' String ' ) {
if ( parameter . schema ? . pattern ! = null ) {
code . write ( '''
code . write ( '''
if ( ! RegExp ( r'${parameter.schema!.pattern!}' ) . hasMatch ( $ { _toDartName ( parameter . name ) } ) ) {
if ( ! RegExp ( r'${parameter.schema!.pattern!}' ) . hasMatch ( $ { _toDartName ( parameter . name ) } ) ) {
throw Exception ( ' Invalid value " \$ ${ _toDartName ( parameter . name ) } " for parameter " ${ _toDartName ( parameter . name ) } " with pattern " ' r'${parameter.schema!.pattern!}"' ) ; / / coverage: ignore - line
throw Exception ( ' Invalid value " \$ ${ _toDartName ( parameter . name ) } " for parameter " ${ _toDartName ( parameter . name ) } " with pattern " ' r'${parameter.schema!.pattern!}"' ) ; / / coverage: ignore - line
}
}
''' );
''' );
}
}
if ( parameter . schema ? . minLength ! = null ) {
code . write ( '''
if ( $ { _toDartName ( parameter . name ) } . length < $ { parameter . schema ! . minLength ! } ) {
throw Exception ( ' Parameter " ${ _toDartName ( parameter . name ) } " has to be at least ${ parameter . schema ! . minLength ! } characters long ' ) ; / / coverage: ignore - line
}
''' );
}
if ( parameter . schema ? . maxLength ! = null ) {
code . write ( '''
if ( $ { _toDartName ( parameter . name ) } . length > $ { parameter . schema ! . maxLength ! } ) {
throw Exception ( ' Parameter " ${ _toDartName ( parameter . name ) } " has to be at most ${ parameter . schema ! . maxLength ! } characters long ' ) ; / / coverage: ignore - line
}
''' );
}
}
final defaultValueCode = parameter . schema ? . default_ ! = null
final defaultValueCode = parameter . schema ? . default_ ! = null
? _valueToEscapedValue ( result . name , parameter . schema ! . default_ ! . toString ( ) )
? _valueToEscapedValue ( result . name , parameter . schema ! . default_ ! . toString ( ) )
@ -1082,7 +1098,7 @@ TypeResult resolveObject(
refer ( ' JsonSerializable ' ) . call (
refer ( ' JsonSerializable ' ) . call (
[ ] ,
[ ] ,
{
{
if ( schema . additionalProperties ? ? false ) . . . {
if ( schema . additionalProperties ! = null ) . . . {
' disallowUnrecognizedKeys ' : refer ( ' false ' ) ,
' disallowUnrecognizedKeys ' : refer ( ' false ' ) ,
} ,
} ,
if ( extraJsonSerializableValues ! = null ) . . . {
if ( extraJsonSerializableValues ! = null ) . . . {
@ -1351,7 +1367,7 @@ TypeResult resolveType(
final s = schema . ofs ! [ results . indexOf ( result ) ] ;
final s = schema . ofs ! [ results . indexOf ( result ) ] ;
b
b
. . name = fields [ result . name ]
. . name = fields [ result . name ]
. . type = refer ( _makeNullable ( result . name , true ) )
. . type = refer ( _makeNullable ( result . name , ! ( schema . allOf ? . contains ( s ) ? ? false ) ) )
. . modifier = FieldModifier . final $
. . modifier = FieldModifier . final $
. . docs . addAll ( _descriptionToDocs ( s . description ) ) ;
. . docs . addAll ( _descriptionToDocs ( s . description ) ) ;
} ,
} ,
@ -1374,7 +1390,8 @@ TypeResult resolveType(
( final b ) = > b
( final b ) = > b
. . name = fields [ result . name ] !
. . name = fields [ result . name ] !
. . toThis = true
. . toThis = true
. . named = true ,
. . named = true
. . required = schema . allOf ! = null ,
) ,
) ,
] ,
] ,
] ) ,
] ) ,
@ -1393,6 +1410,14 @@ TypeResult resolveType(
)
)
. . body = Code (
. . body = Code (
< String > [
< String > [
if ( schema . allOf ! = null ) . . . [
' return ${ state . prefix } $ identifier ( ' ,
' data, ' ,
for ( final result in results ) . . . [
' ${ fields [ result . name ] ! } : ${ result . deserialize ( ' data ' ) } , ' ,
] ,
' ); ' ,
] else . . . [
for ( final result in results ) . . . [
for ( final result in results ) . . . [
' ${ result . name } ? ${ fields [ result . name ] ! } ; ' ,
' ${ result . name } ? ${ fields [ result . name ] ! } ; ' ,
] ,
] ,
@ -1426,15 +1451,13 @@ TypeResult resolveType(
if ( schema . oneOf ! = null ) . . . [
if ( schema . oneOf ! = null ) . . . [
" assert([ ${ fields . values . join ( ' , ' ) } ].where((final x) => x != null).length == 1, 'Need oneOf for \$ data'); " ,
" assert([ ${ fields . values . join ( ' , ' ) } ].where((final x) => x != null).length == 1, 'Need oneOf for \$ data'); " ,
] ,
] ,
if ( schema . allOf ! = null ) . . . [
" assert([ ${ fields . values . join ( ' , ' ) } ].where((final x) => x != null).length == ${ fields . length } , 'Need allOf for \$ data'); " ,
] ,
' return ${ state . prefix } $ identifier ( ' ,
' return ${ state . prefix } $ identifier ( ' ,
' data, ' ,
' data, ' ,
for ( final result in results ) . . . [
for ( final result in results ) . . . [
' ${ fields [ result . name ] ! } : ${ fields [ result . name ] ! } , ' ,
' ${ fields [ result . name ] ! } : ${ fields [ result . name ] ! } , ' ,
] ,
] ,
' ); ' ,
' ); ' ,
] ,
] . join ( ) ,
] . join ( ) ,
) ;
) ;
} ,
} ,
@ -1543,6 +1566,27 @@ TypeResult resolveType(
break ;
break ;
case ' object ' :
case ' object ' :
if ( schema . properties = = null ) {
if ( schema . properties = = null ) {
if ( schema . additionalProperties ! = null ) {
if ( schema . additionalProperties is EmptySchema ) {
result = TypeResultMap (
' Map<String, dynamic> ' ,
TypeResultBase ( ' dynamic ' ) ,
) ;
} else {
final subResult = resolveType (
spec ,
state ,
identifier ,
schema . additionalProperties ! ,
extraJsonSerializableValues: extraJsonSerializableValues ,
) ;
result = TypeResultMap (
' Map<String, ${ subResult . name } > ' ,
TypeResultBase ( ' dynamic ' ) ,
) ;
}
break ;
}
result = TypeResultBase ( ' dynamic ' ) ;
result = TypeResultBase ( ' dynamic ' ) ;
break ;
break ;
}
}