Skip to content

Commit

Permalink
transform api member comment to start newlines (#60)
Browse files Browse the repository at this point in the history
this change transforms the api member comments to start a newline
and render multi line comments.
  • Loading branch information
piq9117 authored Oct 28, 2024
1 parent b827d9d commit e119add
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 8 deletions.
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pkgs.mkShell {
ghc
cabal-install
ghcid
ormolu
];
}
14 changes: 13 additions & 1 deletion src/Tie/Codegen/Operation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module Tie.Codegen.Operation
where

import qualified Data.Map.Strict as Map
import qualified Debug.Trace
import Prettyprinter (Doc, (<+>))
import qualified Prettyprinter as PP
import qualified Prettyprinter.Render.Text as PP
Expand Down Expand Up @@ -185,7 +186,18 @@ codegenApiTypeOperation resolver Operation {..} = do
Nothing ->
"--" <+> "@" <> toParamName name <> "@" <> PP.line
Just comment ->
"--" <+> "@" <> toParamName name <> "@" <+> PP.pretty comment <> PP.line
"--"
<+> "@"
<> toParamName name
<> "@"
<> PP.line
<> codegenMultilineComment comment
<> PP.line

codegenMultilineComment :: Text -> Doc ann
codegenMultilineComment commentLines =
let comments = fmap ("-- " <>) $ lines commentLines
in PP.cat (fmap PP.pretty comments)

codegenRequestBodyComment RequestBody {description} = case description of
Nothing ->
Expand Down
47 changes: 47 additions & 0 deletions test/golden/description.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
openapi: "3.0.0"
info:
version: 1.0.0
title: Scarf
license:
name: AllRightsReserved
servers:
- url: https://scarf.sh/api/v1
paths:
/test:
parameters:
- name: package_query
in: query
required: false
description: >
Use this query parameter to filter for the packages thats suits your use case.
It can be used by passing in either package names or package ids.
To query for multiple packages you can pass in comma separated values.
For example:
```
package_query=17ea97c0-d350-45ce-9f36-ebb66694196c,558664cd-fece-47f5-a9ca-f30974cf96a5,...
```
Or if you prefer using package names, you can also pass in
```
package_query=package_name_1,package_name_2...
```
schema:
type: string
get:
summary: test
operationId: test
responses:
'200':
description: CSV response without schema
content:
application/json:
schema:
description: Undocumented
type: array
components: {}
Loading

0 comments on commit e119add

Please sign in to comment.