Skip to content

Commit

Permalink
transform api member comment to start newlines
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 committed Oct 28, 2024
1 parent b827d9d commit 15d94eb
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 10 deletions.
16 changes: 13 additions & 3 deletions src/Tie/Codegen/Operation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Tie.Codegen.Operation
)
where

import qualified Debug.Trace
import qualified Data.Map.Strict as Map
import Prettyprinter (Doc, (<+>))
import qualified Prettyprinter as PP
Expand Down Expand Up @@ -184,9 +185,18 @@ codegenApiTypeOperation resolver Operation {..} = do
codegenParamComment Param {name, summary} = case summary of
Nothing ->
"--" <+> "@" <> toParamName name <> "@" <> PP.line
Just comment ->
"--" <+> "@" <> toParamName name <> "@" <+> PP.pretty comment <> PP.line

-- TODO: this is not pretty printed with the newline
Just comment ->
"--" <+> "@" <> 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 ->
mempty
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 15d94eb

Please sign in to comment.