Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
67fe83a
Add OpenAPI support for AutoRoute JSON views
vincentcombey-design Mar 20, 2026
65cd110
Fix OpenAPI review findings
vincentcombey-design Mar 20, 2026
27c224c
Add Swagger UI OpenAPI routes
vincentcombey-design Mar 20, 2026
fb77e2a
Add openapi3 to ihp Nix derivation
vincentcombey-design Mar 20, 2026
0e8d557
Add regression test for Api action names
vincentcombey-design Mar 20, 2026
f881ab9
Add OpenAPI request body docs
vincentcombey-design Apr 7, 2026
0b0b6bf
Export request body docs for OpenAPI
vincentcombey-design Apr 7, 2026
77389c8
Fix OpenAPI test imports
vincentcombey-design Apr 7, 2026
a118f67
Remove redundant OpenAPI test import
vincentcombey-design Apr 7, 2026
93110cc
Tie OpenAPI request bodies to actions
vincentcombey-design Apr 7, 2026
d807ab0
Simplify action request body docs
vincentcombey-design Apr 7, 2026
00649fe
Remove loose OpenAPI request body helper
vincentcombey-design Apr 7, 2026
2e3c0e8
Tighten typed action request body decode
vincentcombey-design Apr 7, 2026
c97baf8
Decode request bodies by registered type
vincentcombey-design Apr 7, 2026
7e81813
Store request body type reps concretely
vincentcombey-design Apr 7, 2026
2a01d93
Add OpenAPI action doc setters
vincentcombey-design Apr 23, 2026
52bd62e
Fix JsonView OpenAPI docs after rebase
vincentcombey-design Apr 24, 2026
5e10096
Add typed OpenAPI action definitions
vincentcombey-design Apr 24, 2026
2088e9e
Make OpenAPI endpoint definitions authoritative
vincentcombey-design Apr 24, 2026
d738674
Remove ActionDefinition runner boilerplate
vincentcombey-design Apr 24, 2026
7b75149
Document supported custom OpenAPI routes
vincentcombey-design Apr 24, 2026
2546e21
Infer OpenAPI request bodies from handlers
vincentcombey-design Apr 24, 2026
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
Prev Previous commit
Next Next commit
Remove ActionDefinition runner boilerplate
  • Loading branch information
vincentcombey-design committed Apr 24, 2026
commit d738674634e89948b13b8b48a034667bfe8dffc0
3 changes: 0 additions & 3 deletions Guide/view.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -660,9 +660,6 @@ instance JsonView IndexView where
instance Controller PostsController where
type ControllerAction PostsController = ActionDefinition PostsController

runControllerAction actionDefinition =
runActionDefinition actionDefinition

action PostsAction =
endpoint
|> responseView @IndexView
Expand Down
4 changes: 4 additions & 0 deletions ihp/IHP/Controller/ActionDefinition.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ data ActionDefinition controller = ActionDefinition
, runActionDefinition :: ControllerAction' controller
}

instance RunControllerAction controller (ActionDefinition controller) where
runControllerActionDefault = runActionDefinition
{-# INLINABLE runControllerActionDefault #-}

instance
( Data controller
, Controller controller
Expand Down
19 changes: 16 additions & 3 deletions ihp/IHP/ControllerSupport.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TypeFamilies, ConstrainedClassMethods, ScopedTypeVariables, FunctionalDependencies, AllowAmbiguousTypes, RankNTypes, DefaultSignatures #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, TypeFamilies, ConstrainedClassMethods, ScopedTypeVariables, FunctionalDependencies, AllowAmbiguousTypes, RankNTypes, DefaultSignatures, MultiParamTypeClasses, TypeApplications #-}

module IHP.ControllerSupport
( Action'
, ControllerAction'
, RunControllerAction (..)
, (|>)
, getRequestBody
, getRequestPath
Expand Down Expand Up @@ -82,6 +83,18 @@ type ControllerAction' controller =
) =>
IO ResponseReceived

-- | Runs a controller's 'ControllerAction' value.
--
-- This lets action representations such as 'IHP.Controller.ActionDefinition.ActionDefinition'
-- plug into the normal controller dispatch without requiring each controller instance to
-- repeat the same 'runControllerAction' implementation.
class RunControllerAction controller action where
runControllerActionDefault :: (?context :: Context.ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, ?respond :: Respond, ?request :: Request) => action -> IO ResponseReceived

instance RunControllerAction controller (IO ResponseReceived) where
runControllerActionDefault controllerAction = controllerAction
{-# INLINABLE runControllerActionDefault #-}

class (Show controller, Eq controller) => Controller controller where
type ControllerAction controller :: Type
type ControllerAction controller = IO ResponseReceived
Expand All @@ -93,8 +106,8 @@ class (Show controller, Eq controller) => Controller controller where
action :: (?context :: Context.ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, ?respond :: Respond, ?request :: Request) => controller -> ControllerAction controller

runControllerAction :: (?context :: Context.ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, ?respond :: Respond, ?request :: Request) => ControllerAction controller -> IO ResponseReceived
default runControllerAction :: (ControllerAction controller ~ IO ResponseReceived, ?context :: Context.ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, ?respond :: Respond, ?request :: Request) => ControllerAction controller -> IO ResponseReceived
runControllerAction controllerAction = controllerAction
default runControllerAction :: (RunControllerAction controller (ControllerAction controller), ?context :: Context.ControllerContext, ?modelContext :: ModelContext, ?theAction :: controller, ?respond :: Respond, ?request :: Request) => ControllerAction controller -> IO ResponseReceived
runControllerAction = runControllerActionDefault @controller
{-# INLINABLE runControllerAction #-}

class InitControllerContext application where
Expand Down
5 changes: 0 additions & 5 deletions ihp/Test/Test/OpenApiSupportSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ instance JsonView AckView where
instance Controller DocumentedController where
type ControllerAction DocumentedController = ActionDefinition DocumentedController

runControllerAction actionDefinition = runActionDefinition actionDefinition

action ShowBandAction{..} =
endpoint
|> responseView @BandView
Expand All @@ -177,16 +175,13 @@ instance Controller CustomRouteController where
instance Controller DocumentedCustomPathController where
type ControllerAction DocumentedCustomPathController = ActionDefinition DocumentedCustomPathController

runControllerAction actionDefinition = runActionDefinition actionDefinition

action ShowDocumentedCustomPathAction{..} =
endpoint
|> responseView @DocumentedCustomPathView
|> handle (pure DocumentedCustomPathView{..})

instance Controller CrudNamedApiController where
type ControllerAction CrudNamedApiController = ActionDefinition CrudNamedApiController
runControllerAction actionDefinition = runActionDefinition actionDefinition

action CreateApiSessionAction =
endpoint
Expand Down
Loading