Skip to content

fix(dart): make generated method examples analyze cleanly - #2090

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/dart-example-imports
Oct 17, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/dart-example-imports

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Generated Dart and Flutter method examples did not analyze. For example docs/examples/tablesdb/create-row.md imported package:dart_appwrite/permission.dart and package:dart_appwrite/role.dart, which are part of the main library, so dart analyze reported import_of_non_library. The main library import already exposes Permission and Role, so those imports are dropped.

Analyzing every example against the generated package turned up three more failures in the same templates, fixed here too:

  • Location examples (Dart) used Uint8List without importing dart:typed_data.
  • Upload examples imported dart:io without using it; InputFile(path: ...) needs nothing from it. Flutter still imports it for location examples, which use File.
  • Methods whose service returns a plain Future rendered models. result = (no response model, e.g. analytics.createEvent, oauth2.revoke, project.createSmtpTest) or models.Any result = (graphql.query, graphql.mutation). These now await without a typed result, or assign to dynamic for any, and skip the unused models import.

To keep it that way, scripts/validate-dart-examples.sh extracts the code block from every generated docs example, wraps the statements in main() (the examples use top-level await), and runs dart analyze --fatal-warnings inside the generated package. The dart and flutter Validation jobs run it after analyzing the SDK, mirroring validate-go-examples.sh for Go.

Test Plan

  • Red: with the templates from main, the script fails on the live spec. Dart server: 54 issues (32 import_of_non_library, 16 undefined_class, 3 undefined_identifier, 3 unused_import). Flutter client: 27 issues (20 import_of_non_library, 2 undefined_class, 4 undefined_identifier, 1 unused_import).
  • Green: with this change, ./scripts/validate-dart-examples.sh examples/dart (781 examples) and ./scripts/validate-dart-examples.sh examples/flutter (191 examples, Flutter 3.38.10) both report No issues found!.
  • composer lint-twig, composer refactor:check, max-line-length.sh, shellcheck and the Generation suite pass.

Related PRs and Issues

None.

Closes #2091

Examples imported permission.dart and role.dart, which are part files of the main library, so dart analyze rejected them with import_of_non_library; the main library import already brings Permission and Role into scope. Location examples used Uint8List without dart:typed_data, upload examples imported an unused dart:io, and methods without a typed response rendered models. or models.Any where the service returns a plain Future.

Validation now extracts every Dart and Flutter docs example and analyzes it against the generated package, like validate-go-examples.sh does for Go.
@hansi-codes

hansi-codes Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The template changes and validation-script wiring appear consistent with the generated Dart and Flutter libraries.

The Dart and Flutter method-example templates now emit imports and response assignments that match the generated SDK APIs. A new validator analyzes extracted documentation examples, and the Dart and Flutter validation jobs run it after SDK analysis.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
.github/workflows/validation.yml Run the documentation-example analyzer in the Dart and Flutter validation jobs.
scripts/validate-dart-examples.sh Extract Dart code blocks from generated method documentation and analyze them in the SDK package.
templates/dart/docs/example.md.twig Correct imports and response-variable generation for Dart examples.
templates/flutter/docs/example.md.twig Correct imports and response-variable generation for Flutter examples.

Reviewed 7a73da5 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@hansi-codes hansi-codes Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 045904a into main Oct 17, 2026
61 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/dart-example-imports branch October 17, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make generated Dart and Flutter method examples analyze cleanly

1 participant