Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/dependabot-automerge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,33 @@ jobs:
automerge:
name: Auto-merge Dependabot PRs
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- name: Check if Dependabot PR
id: check
run: |
if [ "${{ github.event.pull_request.user.login }}" = "dependabot[bot]" ]; then
echo "is_dependabot=true" >> $GITHUB_OUTPUT
else
echo "is_dependabot=false" >> $GITHUB_OUTPUT
echo "Not a Dependabot PR, skipping auto-merge"
fi

- name: Fetch Dependabot metadata
if: steps.check.outputs.is_dependabot == 'true'
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Enable auto-merge for minor/patch updates
if: steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch'
if: steps.check.outputs.is_dependabot == 'true' && (steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch')
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Approve patch updates
if: steps.metadata.outputs.update-type == 'version-update:semver-patch'
if: steps.check.outputs.is_dependabot == 'true' && steps.metadata.outputs.update-type == 'version-update:semver-patch'
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<a href="https://api.reuse.software/info/github.com/RAprogramm/entity-derive">
<img src="https://img.shields.io/reuse/compliance/github.com%2FRAprogramm%2Fentity-derive?style=for-the-badge" alt="REUSE Compliant"/>
</a>
<a href="https://github.com/RAprogramm/entity-derive/wiki">
<img src="https://img.shields.io/badge/Wiki-Documentation-green?style=for-the-badge&logo=github" alt="Wiki"/>
</a>
</p>

---
Expand Down
22 changes: 15 additions & 7 deletions crates/entity-derive-impl/src/entity/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
//! ```text
//! api/
//! ├── mod.rs — Orchestrator (this file)
//! ├── handlers.rs — Axum handler functions with #[utoipa::path]
//! ├── crud.rs — CRUD handler functions (create, get, update, delete, list)
//! ├── handlers.rs — Command handler functions with #[utoipa::path]
//! ├── router.rs — Router factory function
//! └── openapi.rs — OpenApi struct for Swagger UI
//! ```
Expand Down Expand Up @@ -58,6 +59,7 @@
//! let openapi = UserApi::openapi();
//! ```

mod crud;
mod handlers;
mod openapi;
mod router;
Expand All @@ -69,24 +71,30 @@ use super::parse::EntityDef;

/// Main entry point for API code generation.
///
/// Returns empty `TokenStream` if `api(...)` is not configured
/// or no commands are defined.
/// Returns empty `TokenStream` if `api(...)` is not configured.
/// Generates CRUD handlers if `handlers` is enabled, and command handlers
/// if commands are defined.
pub fn generate(entity: &EntityDef) -> TokenStream {
if !entity.has_api() {
return TokenStream::new();
}

// API generation requires commands to be enabled
if !entity.has_commands() || entity.command_defs().is_empty() {
let has_crud = entity.api_config().has_handlers();
let has_commands = entity.has_commands() && !entity.command_defs().is_empty();

// Need at least one type of handler to generate API
if !has_crud && !has_commands {
return TokenStream::new();
}

let handlers = handlers::generate(entity);
let crud_handlers = crud::generate(entity);
let command_handlers = handlers::generate(entity);
let router = router::generate(entity);
let openapi = openapi::generate(entity);

quote! {
#handlers
#crud_handlers
#command_handlers
#router
#openapi
}
Expand Down
Loading