Skip to content

#67 feat(api): add OpenAPI info config and selective handlers#94

Merged
RAprogramm merged 4 commits intodevfrom
67-fix-examples-crud-handlers
Jan 7, 2026
Merged

#67 feat(api): add OpenAPI info config and selective handlers#94
RAprogramm merged 4 commits intodevfrom
67-fix-examples-crud-handlers

Conversation

@RAprogramm
Copy link
Owner

Summary

  • Add OpenAPI info configuration (title, description, api_version, license, contact)
  • Add selective handlers via handlers(create, get, list) syntax
  • Generate ErrorResponse and PaginationQuery schemas in OpenAPI
  • Fix utoipa 5.x compatibility with Modify trait pattern

New Features

OpenAPI Info Configuration

#[entity(api(
    tag = "Users",
    handlers,
    title = "User Service API",
    description = "RESTful API for user management",
    api_version = "1.0.0",
    license = "MIT",
    contact_name = "API Support",
    contact_email = "support@example.com"
))]

Selective Handlers

// Generate only create, get, and list handlers
#[entity(api(tag = "Users", handlers(create, get, list)))]

// Generate all handlers (existing syntax)
#[entity(api(tag = "Users", handlers))]

Technical Changes

  • Added HandlerConfig struct for selective CRUD generation
  • Refactored path generation in openapi.rs to be conditional
  • Updated router.rs and crud.rs to respect HandlerConfig
  • Added generate_info_code() for OpenAPI info section

Test Plan

  • Unit tests for new parsing (127 tests pass)
  • Basic example compiles and runs
  • Swagger UI shows correct info, schemas, and paths
  • Manual testing of selective handlers

Add `api(handlers)` option to generate REST handlers automatically:
- create_{entity} - POST handler
- get_{entity} - GET by ID handler
- update_{entity} - PATCH handler
- delete_{entity} - DELETE handler
- list_{entity} - GET list handler

Also adds separate routers:
- {entity}_router<R>() for CRUD (Repository trait)
- {entity}_commands_router<H>() for commands (CommandHandler trait)

Part of #67: fix examples with generated handlers
- Add OpenAPI info configuration (title, description, version, license, contact)
- Add selective handlers via handlers(create, get, list) syntax
- Generate ErrorResponse and PaginationQuery schemas in OpenAPI
- Refactor path generation to only include enabled handlers
- Update router and crud modules to respect HandlerConfig
- Fix utoipa 5.x compatibility with Modify trait pattern
@RAprogramm RAprogramm changed the base branch from main to dev January 7, 2026 06:13
- OpenAPI now only includes CreateRequest if handlers.create is enabled
- OpenAPI now only includes UpdateRequest if handlers.update is enabled
- Response schema is always included (used by all read operations)
- Added 3 tests for selective handlers schema registration
Changed workflow to run for all PRs but skip auto-merge steps
for non-dependabot PRs. This shows green (success) instead of
gray (skipped) status in the PR checks.
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 75.60000% with 183 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/entity-derive-impl/src/entity/api/router.rs 27.10% 78 Missing ⚠️
...rates/entity-derive-impl/src/entity/api/openapi.rs 84.42% 43 Missing ⚠️
crates/entity-derive-impl/src/entity/parse/api.rs 70.33% 35 Missing ⚠️
crates/entity-derive-impl/src/entity/api/crud.rs 90.98% 22 Missing ⚠️
crates/entity-derive-impl/src/entity/api.rs 0.00% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@RAprogramm RAprogramm merged commit 3cee183 into dev Jan 7, 2026
16 checks passed
@RAprogramm RAprogramm deleted the 67-fix-examples-crud-handlers branch January 7, 2026 06:32
RAprogramm added a commit that referenced this pull request Jan 7, 2026
* feat(examples): add comprehensive feature examples

Restructure examples to demonstrate each entity-derive feature:
- basic: renamed from axum-crud, simple CRUD operations
- filtering: #[filter], #[filter(like)], #[filter(range)]
- relations: #[belongs_to], #[has_many]
- events: #[entity(events)] with event enums
- hooks: #[entity(hooks)] with lifecycle hooks
- commands: #[entity(commands)], #[command] CQRS pattern
- transactions: #[entity(transactions)] atomic operations
- soft-delete: #[entity(soft_delete)] with restore
- streams: #[entity(streams)] async streaming
- full-app: complete e-commerce app with all features

All examples have publish = false to exclude from crates.io.

* fix(examples): add required dependencies and fix compilation

- Add workspace.exclude for examples directories
- Add postgres/api features to example crates
- Add async-trait and utoipa dependencies
- Add entity-core where needed
- Fix SPDX headers in migration files
- Fix type annotations for multi-entity repos
- Add utoipa::path attributes to basic example
- Update gitignore for example targets

* #68 fix: hooks example - add utoipa dependency

- Add utoipa dependency to Cargo.toml
- Fix unused imports

* #69 fix: commands example - fix dependencies and struct naming

- Add entity-core and utoipa dependencies
- Rename AccountCommandHandler to MyAccountHandler (avoid conflict with generated trait)
- Use source = "update" for UpdateEmail command
- Create separate input types for HTTP handlers (commands lack Deserialize)
- Use AccountRepository:: fully qualified syntax

* feat: implement multi-entity transaction API (#70)

- Simplified TransactionContext to use 'static lifetime for sqlx::Transaction
- Added extension traits for entity repository access (ctx.bank_accounts())
- Implemented pluralize() function for proper method naming
- Updated transactions example with fully qualified syntax
- Added cfg guards for postgres-specific code

* fix: remove unused import in soft-delete example (#71)

* feat: implement stream_filtered for database streaming (#72)

- Added stream_filtered method to repository trait
- Added Filter type alias (same as Query struct)
- Implemented stream_filtered for PostgreSQL
- Fixed streams example with correct field names
- Added Serialize/Deserialize to AuditLog entity
- Added events feature for subscriber support

* fix: update events example for new event variants (#67)

* fix: gate Future import behind postgres feature

* style: reorder imports per rustfmt

* #76 feat: add api attribute parsing for OpenAPI integration

- Add ApiConfig struct with tag, security, path_prefix, version options
- Parse api(...) nested attributes from #[entity(api(...))]
- Support public commands list for bypassing authentication
- Add has_api() and api_config() methods to EntityDef
- Comprehensive test coverage for all parsing scenarios

* #77 feat: add HTTP handler generation with OpenAPI documentation (#88)

- Add api/ module with handlers, router, and openapi submodules
- Generate axum handlers with #[utoipa::path] annotations
- Support security configuration (bearer, api_key) per endpoint
- Mark public commands without authentication requirement
- Generate router factory function for easy integration
- Generate OpenApi struct for Swagger UI
- HTTP method selection based on command kind (POST/PUT/DELETE)
- Path parameters for commands requiring entity ID
- 4 unit tests for HTTP method selection

* #78 feat: extract doc comments for OpenAPI descriptions

- Add utils/docs.rs module for doc comment extraction
- Extract /// comments from entity struct for tag descriptions
- Extract /// comments from fields for schema descriptions
- Use entity doc as fallback for tag_description in OpenAPI
- 6 unit tests for doc extraction functions

* #78 feat: extract doc comments for OpenAPI descriptions

- Add utils/docs.rs module for doc comment extraction
- Extract /// comments from entity struct for tag descriptions
- Extract /// comments from fields for schema descriptions
- Use entity doc as fallback for tag_description in OpenAPI
- 6 unit tests for doc extraction functions

* #79 feat: parse validation attributes for OpenAPI constraints

- Add validation.rs module for #[validate(...)] parsing
- Support length(min, max), range(min, max), email, url, regex
- Generate OpenAPI schema constraints (minLength, maxLength, etc.)
- Store raw attrs for passthrough to generated DTOs
- 8 unit tests for validation parsing

* #80 feat: add example attribute parsing for OpenAPI schemas

- Add example.rs module for parsing #[example = ...] attributes
- Support string, integer, float, and boolean literals
- Support negative numbers
- Add ExampleValue enum with to_tokens() and to_schema_attr()
- Add example field to FieldDef with accessor methods
- Include 8 unit tests for parsing

Closes #80

* #81 feat: add command-level security configuration

- Add security field to CommandDef for per-command override
- Parse security = "..." option in #[command(...)] attributes
- Support "none" value to make specific commands public
- Update handler generation to use command security with priority:
  1. Command-level security override
  2. Entity-level public commands list
  3. Entity-level default security
- Add security_scheme_name helper for mapping schemes
- Add 3 unit tests for security parsing

Closes #81

* #82 feat: add EntityError derive macro for OpenAPI error docs

- Create error.rs module with EntityError derive macro
- Parse #[status(code)] attributes for HTTP status codes
- Use doc comments as error descriptions
- Generate {Error}Responses struct with helper methods:
  - status_codes() - all error status codes
  - descriptions() - all error descriptions
  - utoipa_responses() - tuples for OpenAPI
- Add 4 unit tests for error parsing

Closes #82

* #83 feat: add API versioning and deprecation support

- Wire up deprecated_in config to generate deprecated = true in utoipa
- Version is already supported via full_path_prefix()
- Add 5 unit tests for security scheme name mapping

Closes #83

* fix: use non-PI float value in example test

* #67 feat(api): add OpenAPI info config and selective handlers (#94)

* feat(api): add CRUD handler generation

Add `api(handlers)` option to generate REST handlers automatically:
- create_{entity} - POST handler
- get_{entity} - GET by ID handler
- update_{entity} - PATCH handler
- delete_{entity} - DELETE handler
- list_{entity} - GET list handler

Also adds separate routers:
- {entity}_router<R>() for CRUD (Repository trait)
- {entity}_commands_router<H>() for commands (CommandHandler trait)

Part of #67: fix examples with generated handlers

* #67 feat(api): add OpenAPI info config and selective handlers

- Add OpenAPI info configuration (title, description, version, license, contact)
- Add selective handlers via handlers(create, get, list) syntax
- Generate ErrorResponse and PaginationQuery schemas in OpenAPI
- Refactor path generation to only include enabled handlers
- Update router and crud modules to respect HandlerConfig
- Fix utoipa 5.x compatibility with Modify trait pattern

* #67 fix(openapi): register only schemas for enabled handlers

- OpenAPI now only includes CreateRequest if handlers.create is enabled
- OpenAPI now only includes UpdateRequest if handlers.update is enabled
- Response schema is always included (used by all read operations)
- Added 3 tests for selective handlers schema registration

* #67 fix(ci): show green status for non-dependabot PRs

Changed workflow to run for all PRs but skip auto-merge steps
for non-dependabot PRs. This shows green (success) instead of
gray (skipped) status in the PR checks.

* chore: bump versions and fix full-app example

- Bump entity-core: 0.1.3 -> 0.2.0
- Bump entity-derive: 0.3.3 -> 0.4.0
- Bump entity-derive-impl: 0.1.3 -> 0.2.0
- Bump workspace: 0.3.0 -> 0.4.0

Full-app example fixes:
- Add masterror dependency
- Add streams feature to entity-core
- Fix relation patterns (use #[has_many] at struct level)
- Add Serialize/Deserialize derives to AuditLog
- Simplify to single entity with api(handlers)

* docs: update README with v0.4 features

* refactor: split large modules into smaller components

Split 5 large modules (600-900 lines) into focused submodules:

- openapi.rs (922 lines) → openapi/ (6 files)
- crud.rs (708 lines) → crud/ (8 files)
- command.rs (630 lines) → command/ (4 files)
- api.rs (576 lines) → parse/api/ (4 files)
- entity.rs (806 lines) → parse/entity/ (8 files)

Changes:
- Replace inline comments with doc comments (//! and ///)
- Remove regular comments (allowed only in examples)
- Add detailed module-level documentation
- Improve code organization for better testability

* docs: add comprehensive module documentation

Add tokio-level documentation to all parse/ and api/ submodules:

- crud/: delete, get, list, update handler generators
- openapi/: info, paths, schemas, security modules
- parse/api/: config, parser modules
- parse/command/: types, parser modules
- parse/entity/: def, accessors, constructor, helpers, projection

Each module now includes:
- Architecture diagrams showing data flow
- Type hierarchy tables
- Usage examples
- Function reference tables

* fmt

* test: improve coverage to 94%

* test: increase coverage to 95%+ with comprehensive tests

* test: add comprehensive tests for streams, field, and query modules

* style: fix formatting
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.

1 participant