Skip to content

Commit

Permalink
Merge pull request #7 from bruderj15/some
Browse files Browse the repository at this point in the history
constrained-some
  • Loading branch information
bruderj15 authored Dec 1, 2024
2 parents 908c341 + 9dcf2fe commit 921e54a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.10.1
compilerKind: ghc
compilerVersion: 9.10.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.8.2
compilerKind: ghc
compilerVersion: 9.8.2
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PVP versioning](https://pvp.haskell.org/).

## v0.2.2 _(2024-12-01)_

### Changed
- Removed `SomeToJSON` and replaced it with `SomeF f ToJSON` from `constrained-some`

## v0.2.1 _(2024-10-25)_

### Changed
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ instance Related User where

## Goals
- [x] Deriving simple links for self and relations
- [ ] Deriving links for paging, ...
- [ ] Deriving more complex links...?
- [ ] Type-level rewriting of APIs like `CompleteAPI` to make API HATEOAS-compliant

## Media-Types
- [x] `application/hal+json`
- [x] `application/collection+json`
- [ ] Others: Easily extensible
- [ ] `application/hal-forms+json` soon
- [ ] Others: Maybe

Client usage with `MimeUnrender` is not yet supported.

Expand Down
9 changes: 5 additions & 4 deletions servant-hateoas.cabal
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cabal-version: 3.0
name: servant-hateoas
version: 0.2.1
version: 0.2.2
synopsis: HATEOAS extension for servant
description: Create Resource-Representations for your types and make your API HATEOAS-compliant.
Resource construction is generic where possible and manually adjustable where required.
Currently HAL+JSON is the only supported Content-Type, work for more is in progress.
Automatically derive hypermedia-links where possible.
Currently HAL+JSON and Collection+JSON are the only supported Content-Types.
The ultimate goal is to generate an entirely HATEOAS-compliant API generically.
homepage: https://github.com/bruderj15/servant-hateoas
bug-reports: https://github.com/bruderj15/servant-hateoas/issues
Expand All @@ -20,6 +20,7 @@ extra-doc-files: CHANGELOG.md
tested-with: GHC == 9.4.8
, GHC == 9.6.4
, GHC == 9.8.2
, GHC == 9.10.1

common warnings
ghc-options: -Wall
Expand All @@ -28,7 +29,6 @@ library
import: warnings

exposed-modules: Servant.Hateoas
, Servant.Hateoas.Some
, Servant.Hateoas.Resource
, Servant.Hateoas.ContentType.HAL
, Servant.Hateoas.ContentType.Collection
Expand All @@ -40,6 +40,7 @@ library
, http-media >= 0.8.1 && < 0.9
, servant >= 0.20.2 && < 0.21
, servant-server >= 0.20.2 && < 0.21
, constrained-some >= 0.1.0 && < 0.2
hs-source-dirs: src
default-language: GHC2021
default-extensions: DataKinds, TypeFamilies
Expand Down
2 changes: 0 additions & 2 deletions src/Servant/Hateoas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ module Servant.Hateoas
( module Servant.Hateoas.ContentType.Collection
, module Servant.Hateoas.ContentType.HAL
, module Servant.Hateoas.Resource
, module Servant.Hateoas.Some
) where

import Servant.Hateoas.ContentType.Collection (Collection, CollectionResource)
import Servant.Hateoas.ContentType.HAL (HAL, HALResource)
import Servant.Hateoas.Resource
import Servant.Hateoas.Some
8 changes: 4 additions & 4 deletions src/Servant/Hateoas/ContentType/HAL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ module Servant.Hateoas.ContentType.HAL
where

import Servant.Hateoas.Resource
import Servant.Hateoas.Some
import Servant.API.ContentTypes
import qualified Network.HTTP.Media as M
import Servant.Links
import qualified Data.Foldable as Foldable
import Data.Some.Constraint
import Data.Kind
import Data.Proxy
import Data.Aeson
Expand All @@ -32,7 +32,7 @@ data HAL (t :: Type)
data HALResource a = HALResource
{ resource :: a -- ^ Wrapped resource
, links :: [(String, Link)] -- ^ Pairs @(rel, link)@ for relations
, embedded :: [(String, SomeToJSON HALResource)] -- ^ Pairs @(rel, resource)@ for embedded resources
, embedded :: [(String, SomeF HALResource ToJSON)] -- ^ Pairs @(rel, resource)@ for embedded resources
} deriving (Generic)

instance Resource HALResource where
Expand All @@ -50,7 +50,7 @@ instance {-# OVERLAPPABLE #-} ToJSON a => ToJSON (HALResource a) where
v -> v
where
ls' = object [fromString rel .= object ["href" .= linkURI href] | (rel, href) <- ls]
es' = object [fromString name .= toJSON e | (name, e) <- es]
es' = object [fromString name .= toJSON e | (name, (Some1 e)) <- es]

instance {-# OVERLAPPING #-} (ToJSON a, Related a, KnownSymbol (CollectionName a)) => ToJSON [HALResource a] where
toJSON xs = object ["_links" .= (mempty :: Object), "_embedded" .= es]
Expand All @@ -61,7 +61,7 @@ instance {-# OVERLAPPING #-} (ToJSON a, Related a, KnownSymbol (CollectionName a
]

instance EmbeddingResource HALResource where
embed e (HALResource r ls es) = HALResource r ls $ fmap SomeToJSON e : es
embed e (HALResource r ls es) = HALResource r ls $ fmap (\res -> Some1 $ HALResource res [] []) e : es

instance {-# OVERLAPPABLE #-}
( Related a, HasField (IdSelName a) a id, IsElem (GetOneApi a) api
Expand Down
2 changes: 1 addition & 1 deletion src/Servant/Hateoas/Resource.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Resource res where
-- | Class for 'Resource's that can embed other resources.
class Resource res => EmbeddingResource res where
-- | Embed a resource @b@ with its relation @rel@ as tuple @(rel, b)@.
embed :: ToJSON b => (String, b) -> res a -> res a
embed :: ToJSON e => (String, e) -> res a -> res a

-- | Class for 'Resource's that can collect multiple resources.
class Resource res => CollectingResource res where
Expand Down
10 changes: 0 additions & 10 deletions src/Servant/Hateoas/Some.hs

This file was deleted.

0 comments on commit 921e54a

Please sign in to comment.