stablekernel/aqueduct

BasicValidator implements AuthValidator - aqueduct document error

robotoss opened this issue · 0 comments

I tried to write my own authorization:

class BasicValidator implements AuthValidator {
  @override
  List<APISecurityRequirement> documentRequirementsForAuthorizer(
      APIDocumentContext context, Authorizer authorizer,
      {List<AuthScope> scopes}) {
    return [
      APISecurityRequirement({"securitySchemes": []})
    ];
  }

  @override
  FutureOr<Authorization> validate<T>(
      AuthorizationParser<T> parser, T authorizationData,
      {List<AuthScope> requiredScope}) {
    final userId = SecurityHelper().userIdByToken(authorizationData.toString());
    if (userId != null) {
      return Authorization(
        userId.toString(),
        null,
        this,
      );
    }
    return null;
  }

The code works when the server starts up.
But when I try to use the command - aqueduct document. I get an error

PS C:\aqueductProjects\aqueduct_pd> aqueduct document
-- Aqueduct CLI Version: 4.0.0-b1
-- Aqueduct project version: 4.0.0-b1
*** Uncaught error
Bad state: NoSuchMethodError: The getter 'type' was called on null.
Receiver: null
Tried calling: type
**** Stacktrace

  • #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
  • #1 APIDocumentContext.finalize.. (package:aqueduct/src/openapi/documentable.dart:172:20)
  • #2 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
  • #3 APIDocumentContext.finalize. (package:aqueduct/src/openapi/documentable.dart:170:24)
  • #4 Iterable.forEach (dart:core/iterable.dart:283:30)
  • #5 APIDocumentContext.finalize (package:aqueduct/src/openapi/documentable.dart:169:10)
  • #6 ApplicationChannel.documentAPI (package:aqueduct/src/application/channel.dart:178:19)
  • #7 Application.document (package:aqueduct/src/application/application.dart:167:38)
  • #8 OpenAPIBuilder.execute (data:application/dart:17:1821)
  • #9 main (data:application/dart:13:35)
  • #10 _startIsolate. (dart:isolate-patch/isolate_patch.dart:297:32)
  • #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)