Skip to content

Hiding endpoint methods from an abstract class with @doNotGenerate is causing a compilation error for the Flutter app #5002

Open

Description

@EchoEllet

Describe the bug

Official serverpod documentation for this use case.

// Goal: Remove or disable startRegistration() endpoint to prevent users from signing up
class EmailIdpEndpoint extends EmailIdpBaseEndpoint {
  @override
  @doNotGenerate
  Future<UuidValue> startRegistration(
    Session session, {
    required String email,
  }) {
    // That is only added to satisfy the Dart compile.
    throw UnimplementedError();
  }
}

When hiding/removing an endpoint method (startRegistration()) that comes from an abstract class (EmailIdpBaseEndpoint) in a subclass (EmailIdpEndpoint) with @doNotGenerate annotation, and then running serverpod generate, the server runs as expected (i.e., the server responds with Method not found in endpoint when the client sends a request`).

However, the usage of @doNotGenerate in such a case cause compliation error that prevents launching the Flutter app.

More specifically, the generated EndpointEmailIdp class (in client package, from EmailIdpEndpoint) is missing implementation for EndpointEmailIdpBase.startRegistration.

Workaround:

After each time running serverpod generate, open $clientPackage/lib/src/protocol/client.dart and manually add a stub implementation method to satisfy the compiler:

// ...

class EndpointEmailIdp extends _i1.EndpointEmailIdpBase {
  EndpointEmailIdp(_i2.EndpointCaller caller) : super(caller);

+  @override
+  Future<_i1.UuidValue> startRegistration({
+    required String email,
+  }) async {
+    // Stub implementation to satisfy the Dart compiler.
+    throw UnimplementedError();
+  }

  // ...
}

On the server, startRegistration() will never be executed in practice, so a stub implementation is fine. However, in this case, the client can still call startRegistration() and the Flutter app will throw UnimplementedError(). In my case, this is also fine and expected since I want to disable the startRegistration() method and won't call it on the client, nor should it be called if it is disabled on the server.

So I think this solution is expected and as intended.

To reproduce

Download this zip file and launch the Flutter app or follow these steps:

  1. Run serverpod create reproduce_donotgenerate_missing_method_impl
  2. Use the Serverpod example code snippet in the server package of the newly created project (nano reproduce_donotgenerate_missing_method_impl_server/lib/test_endpoint.dart:
import 'package:serverpod/serverpod.dart';

abstract class CalculatorEndpoint extends Endpoint {
  Future<int> add(Session session, int a, int b) async {
    return a + b;
  }

  Future<int> subtract(Session session, int a, int b) async {
    return a - b;
  }
}

class AdderEndpoint extends CalculatorEndpoint {
  @doNotGenerate
  Future<int> subtract(Session session, int a, int b) async {
    throw UnimplementedError();
  }
}
  1. Save and run serverpod generate
  2. Run the server, and try to send an HTTP request to localhost:8080/calculator/subtract, and the server will respond with Method not found in endpoint (expected behavior)
  3. Run the Flutter app to reproduce the compilation error.

The generated code in the client package is missing an implementation for EndpointAdderEndpoint.subtract()

Workaround:

Same as before, open dummy_test_client/lib/src/protocol/client.dart, manually modify EndpointAdder to add a stub implementation:

class EndpointAdder extends EndpointCalculator {
  EndpointAdder(_i2.EndpointCaller caller) : super(caller);

   // START
  @override
  Future<int> subtract(int a, int b) async {
    throw UnimplementedError();
  }
  // END

}

Client can still run the method (and UnimplementedError will be thrown):

client.adder.subtract(10, 50);

Expected behavior

Being able to disable or remove an endpoint method that is coming from an abstract class, and then launch the Flutter App.

For my specific case, I only wanted to fully disable startRegistration() from the backend side for security reasons, since the app project is not for public consumption and requires creating the initial root user in the first server launch (command-line prompt).

That can also be done by manually re-implementing all routes except startRegistration().

Library version

  • Serverpob Dart/Flutter packages: 3.4.7
  • Serverpod command-line: 3.4.7
  • Dart: 3.11.5
  • Flutter: 3.41.7
Flutter Doctor Details

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.41.7, on macOS 15.5 24F74 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 16.4)
[✓] Chrome - develop for the web
[✓] Connected device (2 available)
[✓] Network resources

! Doctor found issues in 1 category.

Verbose Flutter Doctor details

[✓] Flutter (Channel stable, 3.41.7, on macOS 15.5 24F74 darwin-arm64, locale en-US) [268ms]
    • Flutter version 3.41.7 on channel stable at /Users/ellet/Developer/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cc0734ac71 (12 days ago), 2026-04-15 21:21:08 -0700
    • Engine revision 59aa584fdf
    • Dart version 3.11.5
    • DevTools version 2.54.2
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file,
      enable-lldb-debugging, enable-uiscene-migration

[!] Android toolchain - develop for Android devices (Android SDK version 36.1.0-rc1) [1,208ms]
    • Android SDK at /Users/ellet/Library/Android/sdk
    • Emulator version 36.3.10.0 (build_id 14472402) (CL:N/A)
    • Platform android-36, build-tools 36.1.0-rc1
    • Java binary at: /Users/ellet/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.8+-14196175-b1038.72)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [618ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [6ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (2 available) [5.9s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 147.0.7727.116

[✓] Network resources [537ms]
    • All expected network resources are available.

Platform information

macOS 15.5 (24F74), Apple M1 Pro. Also reproduced on CachyOS (Arch Linux distro, KDE Desktop, Wayland). This is likely a platform-agnostic bug.

Additional context

The docs says:

Hiding endpoints from a super class is only appropriate in case the parent class is abstract or annotated with @doNotGenerate. Otherwise, the method that should be hidden on the child would still be accessible via the parent class.

In my case, the parent class is abstract, so according to the example at least, this is possible somehow.

Workaround script

Quick/hacky solution

Currently, I'm using a Dart script to workaround the missing implementation for EndpointEmailIdp.startRegistration().

// serverpod_generate.dart
// Temporary workaround: https://github.com/serverpod/serverpod/issues/5002

import 'dart:convert';
import 'dart:io';

const _scriptPath = './scripts/serverpod_generate.dart';
const _clientFilePath = 'librelab_client/lib/src/protocol/client.dart';

void main() async {
  final generateProcess = await Process.start('serverpod', [
    'generate',
  ], runInShell: true);

  generateProcess.stdout.transform(utf8.decoder).listen((data) {
    stdout.write(data);
  });

  generateProcess.stderr.transform(utf8.decoder).listen((data) {
    stderr.write(data);
  });

  final exitCode = await generateProcess.exitCode;
  if (exitCode != 0) {
    stderr.writeln('"serverpod generate" failed');
    exit(exitCode);
  }

  final file = File(_clientFilePath);

  if (!file.existsSync()) {
    stderr.writeln(
      'The serverpod generated Dart file was not found: $_clientFilePath',
    );
    exit(1);
  }

  final content = await file.readAsString();

  const marker = 'https://github.com/serverpod/serverpod/issues/5002';

  if (content.contains(marker)) {
    stdout.writeln('Workaround already applied. Skipping.');
    return;
  }

  final classRegex = RegExp(
    // Disclaimer: The Regex is AI-generated
    r'class\s+EndpointEmailIdp\s+extends\s+_i1\.EndpointEmailIdpBase\s*\{'
    r'\s*EndpointEmailIdp\s*\(_i2\.EndpointCaller caller\)\s*:\s*super\(caller\);\s*',
    multiLine: true,
  );

  final match = classRegex.firstMatch(content);

  if (match == null) {
    stderr.writeln('Target class not found. No changes were applied.');
    exit(2);
  }

  const insertion =
      '''
  // START: https://github.com/serverpod/serverpod/issues/5002
  // This workaround was applied by running "dart $_scriptPath"
  @override
  Future<_i1.UuidValue> startRegistration({
    required String email,
  }) async {
    // Stub implementation to satisfy the Dart compiler.
    throw UnimplementedError();
  }
  // END
''';

  final updated = content.replaceFirst(
    classRegex,
    '${match.group(0)}\n$insertion',
  );

  await file.writeAsString(updated);

  stdout.writeln('Workaround applied successfully.');
}

How experienced are you with this library?

Beginner - Just getting started with this library

Are you interested in working on a PR for this?

  • I want to work on this

Activity

  1. added
    bug
    on Apr 27, 2026
  2. nicowalter256 commented on Jun 25, 2026

    @nicowalter256
    Contributor

    was this addressed?

  3. marcelomendoncasoares commented on Jun 26, 2026

    @marcelomendoncasoares
    Collaborator

    The docs says:

    Hiding endpoints from a super class is only appropriate in case the parent class is abstract or annotated with @doNotGenerate. Otherwise, the method that should be hidden on the child would still be accessible via the parent class.

    In my case, the parent class is abstract, so according to the example at least, this is possible somehow.

    Sorry for the delay in getting back to you, @EchoEllet! And thanks for the detailed report! This is actually a documentation bug rather than a generator bug. The documented suggestion is stale.

    Previously, endpoint inheritance was not reflected in the generated client hierarchy, so using @doNotGenerate on an overridden method could effectively hide that method from the generated client. Since Serverpod now generates the endpoint inheritance hierarchy on the client side, Dart's type system no longer allows this pattern: a subclass cannot remove a member inherited from its generated superclass/interface. If the parent client endpoint exposes startRegistration, the child client endpoint must also satisfy that API.

    Generating a throwing stub would make the Dart code compile, but it would also mean the method still exists on the generated client, which is not really “hiding” it anymore and would conflict with the meaning of @doNotGenerate.

    So the server-side behavior you observed is expected, but the documentation incorrectly suggests that this inheritance-based hiding pattern is still supported. We should update the docs to clarify that @doNotGenerate cannot be used to remove inherited endpoint methods from the generated client hierarchy.

    For now, the supported approach is to avoid putting methods that should not be exposed in the inherited endpoint contract. Shared implementation can be moved to private helper methods or a separate service/helper class, but a private method cannot be used to override or hide an inherited public endpoint method in Dart.

    was this addressed?

    @nicowalter256 If you want to contribute fixing the docs, it will be a great help!

  4. added
    documentation
    area: endpoints
    on Jun 26, 2026
  5. moved this from Inbox 📫 to Planned 🔭 in Serverpod Frameworkson Jun 26, 2026
  6. nicowalter256 commented on Jun 26, 2026

    @nicowalter256
    Contributor

    sure i can contrubute

  7. nicowalter256 commented on Jun 26, 2026

    @nicowalter256
    Contributor
  8. EchoEllet commented on Jun 26, 2026

    @EchoEllet
    ContributorAuthor

    Thank you for the detailed response!

    Generating a throwing stub would make the Dart code compile, but it would also mean the method still exists on the generated client, which is not really “hiding” it anymore and would conflict with the meaning of @doNotGenerate.

    @doNotGenerate suggests excluding/ignoring/removing this route rather than hiding. I used the term "hide" because the documentation section is titled "Hiding endpoint methods with @doNotGenerate".

    So the server-side behavior you observed is expected, but the documentation incorrectly suggests that this inheritance-based hiding pattern is still supported.

    Suggestion

    I would also consider making the serverpod generate fail fast/early to prevent the Flutter app compilation error.
    May be potentially useful to enhance the user experience.

    We should update the docs to clarify that @doNotGenerate cannot be used to remove inherited endpoint methods from the generated client hierarchy.

    Understood. I have addressed the problem I was trying to solve. However, I wonder whether it is possible to skip or ignore an endpoint method defined by the Serverpod auth module entirely on both sides?

    In my case, I previously wanted to fully disable account registration entirely (remove EmailIdpBaseEndpoint.startRegistration).

    For apps that are not designed for public consumption, this can be a common requirement. Example use case: like in an LIS software that might be designed for lab operators but not to be used directly by the patients.

    More context regarding the registration disable feature

    A superuser may create new users. A superuser may be registered on first launch, via a Server CLI tool or some other external method (like PostgreSQL installation on Windows), i.e., internally managed systems. Firebase Auth allows disabling login.

    Current options and workarounds:

    1. Build an auth system from scratch (without serverpod_auth_core_server) or reimplement identity provider (without serverpod_auth_idp_server)
    2. Fork serverpod_auth_idp_server and remove EmailIdpBaseEndpoint.startRegistration entirely.
    1. Or use @doNotGenerate and add stub impl on the client side with a script (see Workaround script section in PR description)

    Other public apps, on the other hand, would typically require public account registration.

    For now, the supported approach is to avoid putting methods that should not be exposed in the inherited endpoint contract. Shared implementation can be moved to private helper methods or a separate service/helper class, but a private method cannot be used to override or hide an inherited public endpoint method in Dart.

    In my case, I have since migrated from Serverpod to Dart Shelf with custom solutions to meet specific project requirements.

    However, it may still be worth filing an issue for users who may want to disable auth registration or, in general, exclude a route from being generated on either side?

    was this addressed?

    Since my report assumed this was a generator bug when it was actually a documentation bug, we may need to file another issue for the use case that tracks it separately, so we do not lose context.

    Please let me know if I should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: endpointsbugdocumentation

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions