From b23b3341288a349b40182b94e510cb415e2fb849 Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Sun, 19 Apr 2015 14:35:42 +0200 Subject: [PATCH 1/2] Canonicalize API before generating docs. --- CHANGELOG.md | 1 + src/Servant/Docs/Internal.hs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2263072d..a0c1330b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Render endpoints in a canonical order (https://github.com/haskell-servant/servant-docs/pull/15) * Remove ToJSON superclass from ToSample * Split out Internal module +* `Canonicalize` API types before generating the docs for them 0.3 --- diff --git a/src/Servant/Docs/Internal.hs b/src/Servant/Docs/Internal.hs index 786157cd..408e1cdb 100644 --- a/src/Servant/Docs/Internal.hs +++ b/src/Servant/Docs/Internal.hs @@ -273,8 +273,8 @@ makeLenses ''Action -- | Generate the docs for a given API that implements 'HasDocs'. This is the -- default way to create documentation. -docs :: HasDocs layout => Proxy layout -> API -docs p = docsFor p (defEndpoint, defAction) +docs :: HasDocs (Canonicalize layout) => Proxy layout -> API +docs p = docsFor (canonicalize p) (defEndpoint, defAction) -- | Closed type family, check if endpoint is exactly within API. @@ -318,7 +318,7 @@ extraInfo p action = -- 'extraInfo'. -- -- If you only want to add an introduction, use 'docsWithIntros'. -docsWith :: HasDocs layout +docsWith :: HasDocs (Canonicalize layout) => [DocIntro] -> ExtraInfo layout -> Proxy layout @@ -330,7 +330,7 @@ docsWith intros (ExtraInfo endpoints) p = -- | Generate the docs for a given API that implements 'HasDocs' with with any -- number of introduction(s) -docsWithIntros :: HasDocs layout => [DocIntro] -> Proxy layout -> API +docsWithIntros :: HasDocs (Canonicalize layout) => [DocIntro] -> Proxy layout -> API docsWithIntros intros = docsWith intros mempty -- | The class that abstracts away the impact of API combinators From 47aeb20c4b4d809473a82e2b10f800b462a734bd Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Sun, 19 Apr 2015 14:51:34 +0200 Subject: [PATCH 2/2] Fix mimeRender name change --- example/greet.hs | 2 +- test/Servant/DocsSpec.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/greet.hs b/example/greet.hs index e5734472..fc649607 100644 --- a/example/greet.hs +++ b/example/greet.hs @@ -27,7 +27,7 @@ instance ToJSON Greet -- | We can also implement 'MimeRender' for additional formats like 'PlainText'. instance MimeRender PlainText Greet where - toByteString Proxy (Greet s) = "\"" <> cs s <> "\"" + mimeRender Proxy (Greet s) = "\"" <> cs s <> "\"" -- We add some useful annotations to our captures, -- query parameters and request body to make the docs diff --git a/test/Servant/DocsSpec.hs b/test/Servant/DocsSpec.hs index bc8b75ab..803823ba 100644 --- a/test/Servant/DocsSpec.hs +++ b/test/Servant/DocsSpec.hs @@ -56,7 +56,7 @@ instance ToSample Int where toSample = Just 17 instance MimeRender PlainText Int where - toByteString _ = cs . show + mimeRender _ = cs . show type TestApi1 = Get '[JSON, PlainText] Int