@ -79,20 +79,20 @@ List<Class> generateDynamiteOverrides(final State state) => [
. . type = refer ( ' HttpClientResponse ' ) ,
. . type = refer ( ' HttpClientResponse ' ) ,
) ,
) ,
)
)
. . body = Block . of ( [
. . body = Code ( '''
const Code ( ' String body; ' ) ,
String body ;
const Code ( ' try { ' ) ,
try {
const Code ( ' body = await response.body; ' ) ,
body = await response . body ;
const Code ( ' } on FormatException { ' ) ,
} on FormatException {
const Code ( " body = 'binary'; " ) ,
body = ' binary ' ;
const Code ( ' }' ) ,
}
const Code ( ' ' ) ,
Code ( ' return $ { state . classPrefix } ApiException( ' ) ,
return $ { state . classPrefix } ApiException (
const Code ( ' response.statusCode, ' ) ,
response . statusCode ,
const Code ( ' response.responseHeaders, ' ) ,
response . responseHeaders ,
const Code ( ' body, ' ) ,
body ,
const Code ( ' ); ' ) ,
) ;
] ) ,
''' ) ,
) ,
) ,
Method (
Method (
( final b ) = > b
( final b ) = > b
@ -190,14 +190,14 @@ Class buildRootClient(
)
)
. . initializers . add (
. . initializers . add (
const Code ( '''
const Code ( '''
super (
super (
client . baseURL ,
client . baseURL ,
baseHeaders: client . baseHeaders ,
baseHeaders: client . baseHeaders ,
httpClient: client . httpClient ,
httpClient: client . httpClient ,
cookieJar: client . cookieJar ,
cookieJar: client . cookieJar ,
authentications: client . authentications ,
authentications: client . authentications ,
)
)
''' ),
''' ),
) ,
) ,
) ,
) ,
] ) ;
] ) ;
@ -305,11 +305,11 @@ Iterable<Method> buildTags(
. join ( ' , ' ) ? ?
. join ( ' , ' ) ? ?
' ' ;
' ' ;
final code = StringBuffer ( '''
final code = StringBuffer ( '''
var _path = ' ${ pathEntry . key } ' ;
var _path = ' ${ pathEntry . key } ' ;
final _queryParameters = < String , dynamic > { } ;
final _queryParameters = < String , dynamic > { } ;
final _headers = < String , String > { $ { acceptHeader . isNotEmpty ? " 'Accept': ' $ acceptHeader ', " : ' ' } } ;
final _headers = < String , String > { $ { acceptHeader . isNotEmpty ? " 'Accept': ' $ acceptHeader ', " : ' ' } } ;
Uint8List ? _body ;
Uint8List ? _body ;
''' );
''' );
final security = operation . security ? ? spec . security ? ? [ ] ;
final security = operation . security ? ? spec . security ? ? [ ] ;
final securityRequirements = security . where ( ( final requirement ) = > requirement . isNotEmpty ) ;
final securityRequirements = security . where ( ( final requirement ) = > requirement . isNotEmpty ) ;
@ -318,20 +318,20 @@ Iterable<Method> buildTags(
for ( final requirement in securityRequirements ) {
for ( final requirement in securityRequirements ) {
final securityScheme = spec . components ! . securitySchemes ! [ requirement . keys . single ] ! ;
final securityScheme = spec . components ! . securitySchemes ! [ requirement . keys . single ] ! ;
code . write ( '''
code . write ( '''
if ( $ { isRootClient ? ' this ' : ' _rootClient ' } . authentications . where ( ( final a ) = > a . type = = ' ${ securityScheme . type } ' & & a . scheme = = ' ${ securityScheme . scheme } ' ) . isNotEmpty ) {
if ( $ { isRootClient ? ' this ' : ' _rootClient ' } . authentications . where ( ( final a ) = > a . type = = ' ${ securityScheme . type } ' & & a . scheme = = ' ${ securityScheme . scheme } ' ) . isNotEmpty ) {
_headers . addAll ( $ { isRootClient ? ' this ' : ' _rootClient ' } . authentications . singleWhere ( ( final a ) = > a . type = = ' ${ securityScheme . type } ' & & a . scheme = = ' ${ securityScheme . scheme } ' ) . headers ) ;
_headers . addAll ( $ { isRootClient ? ' this ' : ' _rootClient ' } . authentications . singleWhere ( ( final a ) = > a . type = = ' ${ securityScheme . type } ' & & a . scheme = = ' ${ securityScheme . scheme } ' ) . headers ) ;
}
}
''' );
''' );
if ( securityRequirements . last ! = requirement ) {
if ( securityRequirements . last ! = requirement ) {
code . write ( ' else ' ) ;
code . write ( ' else ' ) ;
}
}
}
}
if ( securityRequirements . isNotEmpty & & ! isOptionalSecurity ) {
if ( securityRequirements . isNotEmpty & & ! isOptionalSecurity ) {
code . write ( '''
code . write ( '''
else {
else {
throw Exception ( ' Missing authentication for ${ securityRequirements . map ( ( final r ) = > r . keys . single ) . join ( ' or ' ) } ' ) ;
throw Exception ( ' Missing authentication for ${ securityRequirements . map ( ( final r ) = > r . keys . single ) . join ( ' or ' ) } ' ) ;
}
}
''' );
''' );
}
}
code . write ( ' // coverage:ignore-end \n ' ) ;
code . write ( ' // coverage:ignore-end \n ' ) ;
@ -355,24 +355,24 @@ Iterable<Method> buildTags(
if ( result . name = = ' String ' ) {
if ( result . name = = ' String ' ) {
if ( parameter . schema ? . pattern ! = null ) {
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 ) {
if ( parameter . schema ? . minLength ! = null ) {
code . write ( '''
code . write ( '''
if ( $ { toDartName ( parameter . name ) } . length < $ { parameter . schema ! . minLength ! } ) {
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
throw Exception ( ' Parameter " ${ toDartName ( parameter . name ) } " has to be at least ${ parameter . schema ! . minLength ! } characters long ' ) ; / / coverage: ignore - line
}
}
''' );
''' );
}
}
if ( parameter . schema ? . maxLength ! = null ) {
if ( parameter . schema ? . maxLength ! = null ) {
code . write ( '''
code . write ( '''
if ( $ { toDartName ( parameter . name ) } . length > $ { parameter . schema ! . maxLength ! } ) {
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
throw Exception ( ' Parameter " ${ toDartName ( parameter . name ) } " has to be at most ${ parameter . schema ! . maxLength ! } characters long ' ) ; / / coverage: ignore - line
}
}
''' );
''' );
}
}
}
}
@ -488,13 +488,13 @@ Iterable<Method> buildTags(
code . write (
code . write (
'''
'''
final _response = await $ { isRootClient ? ' this ' : ' _rootClient ' } . doRequest (
final _response = await $ { isRootClient ? ' this ' : ' _rootClient ' } . doRequest (
' $ httpMethod ' ,
' $ httpMethod ' ,
Uri ( path: _path , queryParameters: _queryParameters . isNotEmpty ? _queryParameters : null ) ,
Uri ( path: _path , queryParameters: _queryParameters . isNotEmpty ? _queryParameters : null ) ,
_headers ,
_headers ,
_body ,
_body ,
) ;
) ;
''' ,
''' ,
) ;
) ;
if ( operation . responses ! = null ) {
if ( operation . responses ! = null ) {