### Dart JSON Schema Configuration File Example Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md An example of the optional `dart_json_schema.yaml` configuration file. This file allows users to customize generation settings such as input/output directories, file naming conventions, and schema version. ```yaml # dart_json_schema.yaml (optional config file) dart_json_schema: input_directories: - lib/models/ - lib/entities/ output_directory: build/schemas/ file_naming: snake_case # or camelCase include_metadata: true watch_mode: false schema_version: "https://json-schema.org/draft/2020-12/schema" ``` -------------------------------- ### Install dart_json_schema dependencies Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Commands to fetch the installed dependencies for Dart or Flutter projects after adding the package. ```bash dart pub get # or for Flutter projects flutter pub get ``` -------------------------------- ### CI/CD Integration Example Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md A GitHub Actions workflow example to automatically generate and verify JSON schemas on code pushes or pull requests. ```yaml # .github/workflows/schemas.yml name: Generate JSON Schemas on: [push, pull_request] jobs: generate-schemas: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 - run: dart pub get - run: dart run dart_json_schema:generate - run: git diff --exit-code build/schemas/ # Ensure schemas are up to date ``` -------------------------------- ### User Schema Example (JSON) Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md An example of a generated JSON schema for a User object, compatible with Pydantic. It defines properties like 'id', 'name', and 'email' with their respective types, descriptions, and examples. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "title": "User", "properties": { "id": { "title": "User ID", "description": "Unique identifier for the user", "examples": [1, 2, 3], "type": "integer" }, "name": { "title": "Full Name", "description": "The user's full name", "examples": ["John Doe", "Jane Smith"], "type": "string" }, "email": { "title": "Email Address", "description": "User's email address", "examples": ["john@example.com"], "type": "string" } }, "required": ["id", "name", "email"], "$defs": {} } ``` -------------------------------- ### Run Tests with Dart CLI Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md This snippet shows the command to execute the test suite for the Dart project. It requires the Dart SDK to be installed and configured in the environment. ```bash dart test ``` -------------------------------- ### Development Workflow Example Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Illustrates a typical development workflow using dart_json_schema, showing how developers annotate models and run the generation command to produce JSON schemas. ```bash # Developer adds @Field annotations to models # lib/models/user.dart # Run generation command dart run dart_json_schema:generate # JSON schemas are generated in build/schemas/ directory # build/schemas/user.schema.json # Use schemas for API docs, validation, OpenAPI specs, etc. ``` -------------------------------- ### dart_json_schema Configuration File Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Example of a YAML configuration file (`dart_json_schema.yaml`) to customize the schema generation process. ```yaml dart_json_schema: input_directories: - lib/models/ - lib/entities/ output_directory: build/schemas/ file_naming: snake_case include_metadata: true watch_mode: false schema_version: "https://json-schema.org/draft/2020-12/schema" ``` -------------------------------- ### Dart JSON Schema CLI Commands Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Documentation for the dart_json_schema command-line interface, detailing the 'generate', 'init', and 'version' commands with their options, descriptions, and usage examples. ```APIDOC dart_json_schema CLI Commands: Generate Command: dart run dart_json_schema:generate [options] [files...] - Generates JSON schemas from Dart code. - Parameters: - [options]: Optional flags to control generation. - -o, --output: Output directory (default: schemas/). - -w, --watch: Watch for changes and regenerate. - -c, --config: Config file path (default: dart_json_schema.yaml). - -v, --verbose: Verbose output. - -h, --help: Show help. - --include-private: Include private fields. - --format: Output format (json|yaml) (default: json). - --schema-version: JSON Schema version (default: 2020-12). - [files...]: Specific Dart files or directories to process. - Examples: - dart run dart_json_schema:generate - dart run dart_json_schema:generate --output api/schemas/ - dart run dart_json_schema:generate lib/models/ --watch - dart run dart_json_schema:generate --config custom_config.yaml Init Command: dart run dart_json_schema:init - Initializes the project by creating a default configuration file and setting up recommended directory structures. Version Command: dart run dart_json_schema:version - Outputs the current version of the dart_json_schema package. - Example Output: dart_json_schema version 0.0.2 ``` -------------------------------- ### CI/CD Integration Example Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md A GitHub Actions workflow file (.github/workflows/schemas.yml) demonstrating how to integrate JSON schema generation into a CI/CD pipeline for automated checks. ```yaml name: Generate JSON Schemas on: [push, pull_request] jobs: generate-schemas: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: dart-lang/setup-dart@v1 - run: dart pub get - run: dart run dart_json_schema:generate - run: git diff --exit-code build/schemas/ # Ensure schemas are up to date ``` -------------------------------- ### Generated JSON Schema Output Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md An example of a JSON schema generated by the dart_json_schema package for an annotated Dart model. ```json { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "title": "User", "properties": { "id": { "title": "User ID", "description": "Unique identifier for the user", "examples": [1, 2, 3], "type": "integer" }, "name": { "title": "Full Name", "description": "The user's full name", "examples": ["John Doe", "Jane Smith"], "type": "string" }, "email": { "title": "Email Address", "description": "User's email address", "examples": ["john@example.com"], "type": "string" } }, "required": ["id", "name", "email"], "$defs": {} } ``` -------------------------------- ### Annotate Dart Models with @Field Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Demonstrates how to use the `@Field` annotation to add metadata like title, description, and examples to model properties in Dart. ```dart // lib/models/user.dart import 'package:dart_json_schema/dart_json_schema.dart'; class User { @Field( title: "User ID", description: "Unique identifier for the user", examples: [1, 2, 3] ) final int id; @Field( title: "Full Name", description: "The user's full name", examples: ["John Doe", "Jane Smith"] ) final String name; @Field( title: "Email Address", description: "User's email address", examples: ["john@example.com"] ) final String email; const User({ required this.id, required this.name, required this.email, }); } ``` -------------------------------- ### Dart Model Definition with @Field Annotations Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Illustrates how to define a Dart model class (`User`) and apply the `@Field` annotation to its properties. This annotation provides metadata like title, description, and examples, which are used by the generator. ```dart // lib/models/user.dart import 'package:dart_json_schema/dart_json_schema.dart'; class User { @Field( title: "User ID", description: "Unique identifier for the user", examples: [1, 2, 3] ) final int id; @Field( title: "Full Name", description: "The user's full name", examples: ["John Doe", "Jane Smith"] ) final String name; @Field( title: "Email Address", description: "User's email address", examples: ["john@example.com"] ) final String email; const User({ required this.id, required this.name, required this.email, }); } ``` -------------------------------- ### Dart @Field Annotation Definition Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Defines the @Field annotation used to add metadata like title, description, and examples to model fields in Dart. This metadata is used by the generator to create richer JSON schemas. ```dart class Field { final String? title; final String? description; final List? examples; const Field({ this.title, this.description, this.examples, }); } ``` -------------------------------- ### dart_json_schema CLI Commands Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Reference for the available commands and options for the dart_json_schema command-line interface. ```APIDOC Commands: generate [options] [files...] Generate JSON schemas for annotated models. Options: -o, --output: Output directory (default: build/schemas) -w, --watch: Watch for changes and regenerate -c, --config: Config file path (default: dart_json_schema.yaml) -v, --verbose: Verbose output -h, --help: Show help --include-private: Include private fields --format: Output format (json|yaml) (default: json) --schema-version: JSON Schema version (default: 2020-12) --input: Input files or directories init Create a default configuration file. Usage: dart run dart_json_schema:init version Show the package version. Usage: dart run dart_json_schema:version ``` -------------------------------- ### Dart JSON Schema CLI Generation Commands Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Provides commands to run the JSON schema generation tool from the command line. These commands allow users to generate schemas for all models, specify output directories, target specific files, or enable watch mode for automatic regeneration. ```bash # Generate JSON schemas for all annotated models dart run dart_json_schema:generate # Generate with custom output directory dart run dart_json_schema:generate --output schemas/ # Generate for specific files dart run dart_json_schema:generate lib/models/user.dart # Watch mode (regenerate on file changes) dart run dart_json_schema:generate --watch ``` -------------------------------- ### Integration with Build Process Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Configuration for integrating dart_json_schema generation into the project's build scripts, often used with build_runner. ```yaml dev_dependencies: dart_json_schema: ^0.0.2 build_runner: ^2.3.0 scripts: build: dart run build_runner build schemas: dart run dart_json_schema:generate watch: dart run dart_json_schema:generate --watch ``` -------------------------------- ### Generate JSON Schemas via CLI Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Commands to generate JSON schemas from annotated Dart models using the package's command-line tool. ```bash # Generate schemas for all annotated models dart run dart_json_schema:generate # Generate with custom output directory dart run dart_json_schema:generate --output build/schemas/ # Generate for specific files dart run dart_json_schema:generate lib/models/user.dart # Watch mode (regenerate on file changes) dart run dart_json_schema:generate --watch ``` -------------------------------- ### Pubspec.yaml Integration Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md Configuration for the pubspec.yaml file to include dart_json_schema as a dev dependency and define scripts for schema generation and watching for changes. ```yaml dev_dependencies: dart_json_schema: ^1.0.0 build_runner: ^2.3.0 # Add build script scripts: build: dart run build_runner build schemas: dart run dart_json_schema:generate watch: dart run dart_json_schema:generate --watch ``` -------------------------------- ### Add dart_json_schema to pubspec.yaml Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Specifies how to add the dart_json_schema package as a dev dependency in your pubspec.yaml file. ```yaml dev_dependencies: dart_json_schema: ^0.0.2 ``` -------------------------------- ### Dart JsonSchemaGenerator Class Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/spec.md The core class for generating JSON schemas. It includes static methods to scan directories for annotated models and generate schemas for individual files, handling the primary generation logic. ```dart class JsonSchemaGenerator { /// Scan directory and generate all schemas static Future generateAllSchemas({ String inputDir = 'lib/', String outputDir = 'build/schemas', }); /// Generate JSON schema for a single model file static Future?> generateSchemaForFile(String filePath); } ``` -------------------------------- ### @Field Annotation API Reference Source: https://github.com/sagarmahobia/dart_json_schema/blob/main/README.md Defines the structure and parameters of the `@Field` annotation used for adding metadata to Dart model fields. ```APIDOC class Field { final String? title; final String? description; final List? examples; const Field({ this.title, this.description, this.examples, }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.