Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generator from openapi schema #26

Open
anton-k opened this issue Oct 19, 2023 · 0 comments
Open

Code generator from openapi schema #26

anton-k opened this issue Oct 19, 2023 · 0 comments

Comments

@anton-k
Copy link
Owner

anton-k commented Oct 19, 2023

We can generate API-types, server stub and client. From openapi schema.
By openapi input it will generate 3 packages:

  • foo-api-types
  • foo-server
  • foo-client

The server is defined in terms of interfaces. For example:

in the API types:

type GetArticle m = Query "a" -> Get (Resp Json Article)
type PostArticle m = Body Article -> Query "author" Text -> Post (Resp Json ())

data Routes m = Routes {
  getArticle :: GetArticle m,
  postArticle :: PostArticle m
}

The server:

server :: Routes m -> Server m
server routes = 
   "site" /. [ "get/article" /. routes.getArticle
                , "post/article" /. routes.postArticle  ]

The client:

client :: Routes Client
client = Routes{..}
  where
     (getArticle, postArticle) = toClient (Routes getArticle, postArticle)
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

No branches or pull requests

1 participant