Skip to content

Commit

Permalink
Complete release v2
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-k committed Nov 4, 2023
1 parent b1cc768 commit 87273b6
Show file tree
Hide file tree
Showing 32 changed files with 356 additions and 85 deletions.
40 changes: 40 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Changelog

## v2

The servers are augmented with info on API structure. It allows us to
build OpenApi schema, swagger and clients for servers.

* OpenApi schema for servers

* swagger servers support

* clients from the same code as servers

* redesign of internal types

* redesign of DSL for routes

* many ergonomic improvements

* packages for extra utils

* split of `mig` package to several packages:

* `mig` - core
* `mig-wai` - rendering servers to wai apps
* `mig-client` - clients
* `mig-extra` - extra utils
* `mig-server` - mig servers with batteries
* `mig-swagger-ui` - swagger ui server

* tutorial and quickstart guide on github pages

* CI for repo with formatter, build and tests and update of docs on github pages

Thanks to Ambros for contribution.

## v1

Initial version. Servers as functions with type-safe dsl.

17 changes: 13 additions & 4 deletions docs/src/00-foreword.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,19 @@ With cabal we can install it from Hackage:
cabal install mig-server --lib
```

With stack we can link to the repo in extra-deps

```
TODO: example here
With stack we can link to the repo in `extra-deps` (put it in your `stack.yaml`):

```yaml
extra-deps:
- git: https://github.com/anton-k/mig
commit: <some-commit-of-the-mig-libray>
subdirs:
- mig
- mig-extra
- mig-client
- mig-wai
- mig-swagger-ui
- mig-server
```
## Structure of the library
Expand Down
30 changes: 30 additions & 0 deletions mig-client/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Anton Kholomiov (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 2 additions & 1 deletion mig-client/mig-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ author: Anton Kholomiov
maintainer: [email protected]
copyright: 2023 Anton Kholomiov
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
Expand Down Expand Up @@ -49,7 +50,7 @@ library
, http-client
, http-media
, http-types
, mig
, mig >=0.2
, mtl
, text
default-language: GHC2021
3 changes: 2 additions & 1 deletion mig-client/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license: BSD3
author: "Anton Kholomiov"
maintainer: "[email protected]"
copyright: "2023 Anton Kholomiov"
license-file: LICENSE

extra-source-files:
- README.md
Expand All @@ -27,7 +28,7 @@ dependencies:
- bytestring
- containers
- http-api-data
- mig
- mig >= 0.2
- http-client
- http-media
- mtl
Expand Down
30 changes: 30 additions & 0 deletions mig-extra/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Anton Kholomiov (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 2 additions & 1 deletion mig-extra/mig-extra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ author: Anton Kholomiov
maintainer: [email protected]
copyright: 2023 Anton Kholomiov
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
Expand Down Expand Up @@ -61,7 +62,7 @@ library
, http-api-data
, http-media
, http-types
, mig
, mig >=0.2
, mig-client
, openapi3
, template-haskell
Expand Down
3 changes: 2 additions & 1 deletion mig-extra/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license: BSD3
author: "Anton Kholomiov"
maintainer: "[email protected]"
copyright: "2023 Anton Kholomiov"
license-file: LICENSE

extra-source-files:
- README.md
Expand Down Expand Up @@ -32,7 +33,7 @@ default-extensions:
dependencies:
- base >= 4.7 && < 5
- data-default
- mig
- mig >= 0.2
- http-api-data
- blaze-html
- http-types
Expand Down
5 changes: 4 additions & 1 deletion mig-extra/src/Mig/Extra/Plugin/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ module Mig.Extra.Plugin.Auth (
import Control.Monad.IO.Class
import Mig.Core

-- | Authorization plugin interface
data WithAuth m token resp = WithAuth
{ isValid :: token -> m Bool
-- ^ check that token is valid and return info
-- ^ check that token is valid
, authFail :: token -> m resp
-- ^ how to respond on failure
}

-- | Creates plugin that applies check of auth credentials which are passed as HTTP Header with name auth.
withHeaderAuth :: forall m token resp. (IsResp resp, MonadIO m) => WithAuth m token resp -> Header "auth" token -> Plugin m
withHeaderAuth env (Header token) = processResponse $ \getResp -> do
isOk <- env.isValid token
Expand Down
8 changes: 5 additions & 3 deletions mig-extra/src/Mig/Extra/Plugin/Trace.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{-| Debug utils for server. Simple logger for HTTP requests and responses
Also we can use real logging functions with ***By versions.
Simple variants are only for manual testing. It prints to stdout
Also we can use real logging functions with ***By versions of the logger functions.
Simple variants are only for local testing. It prints to stdout
with no ordering of the concurrent prints.
It can be useful for fast setup of debug for your application.
It can be useful for fast setup of debug for your application. Example of the usage:
> applyPlugin (logHttp V2) server
-}
module Mig.Extra.Plugin.Trace (
logReq,
Expand Down
2 changes: 1 addition & 1 deletion mig-server/LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright Author name here (c) 2023
Copyright Anton Kholomiov (c) 2023

All rights reserved.

Expand Down
10 changes: 6 additions & 4 deletions mig-server/mig-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ description: With library mig we can build lightweight and composable ser
* quick start guide at <https://anton-k.github.io/mig/>
.
* examples directory for more fun servers: at <https://github.com/anton-k/mig/tree/main/examples/mig-example-apps#readme>
.
* reference for the main functions: <https://anton-k.github.io/mig/09-reference.html>
category: Web
homepage: https://github.com/anton-k/mig#readme
bug-reports: https://github.com/anton-k/mig/issues
Expand Down Expand Up @@ -101,10 +103,10 @@ library
, data-default
, http-api-data
, http-types
, mig
, mig-extra
, mig-swagger-ui
, mig-wai
, mig >=0.2
, mig-extra >=0.1
, mig-swagger-ui >=0.1
, mig-wai >=0.1
, openapi3
, text
, transformers
Expand Down
11 changes: 7 additions & 4 deletions mig-server/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ license: BSD3
author: "Anton Kholomiov"
maintainer: "[email protected]"
copyright: "2023 Anton Kholomiov"
license-file: LICENSE

extra-source-files:
- README.md
Expand Down Expand Up @@ -66,6 +67,8 @@ description: |
* quick start guide at <https://anton-k.github.io/mig/>
.
* examples directory for more fun servers: at <https://github.com/anton-k/mig/tree/main/examples/mig-example-apps#readme>
.
* reference for the main functions: <https://anton-k.github.io/mig/09-reference.html>
language: GHC2021

Expand All @@ -81,16 +84,16 @@ default-extensions:
dependencies:
- aeson
- base >= 4.7 && < 5
- mig
- mig-extra
- mig-wai
- mig >= 0.2
- mig-extra >= 0.1
- mig-wai >= 0.1
- http-types
- text
- http-api-data
- openapi3
- blaze-html
- warp
- mig-swagger-ui
- mig-swagger-ui >= 0.1
- data-default
- transformers

Expand Down
30 changes: 30 additions & 0 deletions mig-swagger-ui/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Anton Kholomiov (c) 2023

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 7 additions & 3 deletions mig-swagger-ui/mig-swagger-ui.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ cabal-version: 1.12
name: mig-swagger-ui
version: 0.1.0.0
synopsis: Swagger servers for mig library
description: Swagger servers for mig library
description: Appends swagger servers for mig servers.
Example of the usage. This code adds swagger server which is serverd on path "swagger-ui" to our server
.
> withSwagger def server
category: Web
homepage: https://github.com/anton-k/mig#readme
bug-reports: https://github.com/anton-k/mig/issues
author: Anton Kholomiov
maintainer: example@example.com
maintainer: anton.kholomiov@gmail.com
copyright: 2023 Anton Kholomiov
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
Expand Down Expand Up @@ -65,7 +69,7 @@ library
, file-embed-lzma
, http-api-data
, lens
, mig
, mig >=0.2
, openapi3
, text
default-language: GHC2021
11 changes: 8 additions & 3 deletions mig-swagger-ui/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ version: 0.1.0.0
github: "anton-k/mig"
license: BSD3
author: "Anton Kholomiov"
maintainer: "example@example.com"
maintainer: "anton.kholomiov@gmail.com"
copyright: "2023 Anton Kholomiov"
license-file: LICENSE

# Metadata used when publishing your package
synopsis: Swagger servers for mig library
Expand All @@ -13,7 +14,11 @@ category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Swagger servers for mig library
description: |
Appends swagger servers for mig servers.
Example of the usage. This code adds swagger server which is serverd on path "swagger-ui" to our server
.
> withSwagger def server
language:
GHC2021
Expand All @@ -30,7 +35,7 @@ dependencies:
- bytestring
- text
- lens
- mig
- mig >= 0.2
- file-embed-lzma
- blaze-html
- blaze-markup
Expand Down
3 changes: 3 additions & 0 deletions mig-swagger-ui/src/Mig/Swagger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ data DefaultInfo = DefaultInfo
, version :: Text
}

{-| Adds most common used info to OpenApi schema. Use this function
in the @mapSchema@ field of the @SwaggerConfig@.
-}
addDefaultInfo :: DefaultInfo -> OpenApi -> OpenApi
addDefaultInfo appInfo =
OA.info
Expand Down
Loading

0 comments on commit 87273b6

Please sign in to comment.