Skip to content

Commit 4310ea3

Browse files
jonschoningwing328
authored andcommitted
[haskell-http-client] update readme; improve lens generation; fix dateFormat (#6448)
* point readme links to canonical locations * use lenses for non-required model fields, instead of traversals * fix .gitignore generation * fix dateFormat cli option bug
1 parent 3cd3b90 commit 4310ea3

29 files changed

+601
-654
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/HaskellHttpClientCodegen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public HaskellHttpClientCodegen() {
128128
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
129129
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
130130
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
131-
supportingFiles.add(new SupportingFile(".gitignore", "", ".gitignore"));
131+
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
132132
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
133133
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
134134

@@ -241,7 +241,7 @@ public void setDateTimeFormat(String value) {
241241

242242
public void setDateFormat(String value) {
243243
if (StringUtils.isBlank(value)) {
244-
additionalProperties.remove(DATE_FORMAT);
244+
additionalProperties.put(DATE_FORMAT, defaultDateFormat);
245245
} else {
246246
additionalProperties.put(DATE_FORMAT, value);
247247
}

modules/swagger-codegen/src/main/resources/haskell-http-client/Lens.mustache

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import {{title}}.Model
2929

3030
-- * Type Aliases
3131

32-
type Traversal_' s a = Traversal_ s s a a
33-
type Traversal_ s t a b = forall (f :: * -> *). Applicative f => (a -> f b) -> s -> f t
3432
type Lens_' s a = Lens_ s s a a
3533
type Lens_ s t a b = forall (f :: * -> *). Functor f => (a -> f b) -> s -> f t
3634

@@ -40,27 +38,12 @@ type Lens_ s t a b = forall (f :: * -> *). Functor f => (a -> f b) -> s -> f t
4038
-- * {{classname}}
4139

4240
{{#vars}}
43-
{{#required}}
4441
-- | '{{name}}' Lens
45-
{{name}}L :: Lens_' {{classname}} {{datatype}}
42+
{{name}}L :: Lens_' {{classname}} ({{^required}}Maybe {{/required}}{{datatype}})
4643
{{name}}L f {{classname}}{..} = (\{{name}} -> {{classname}} { {{name}}, ..} ) <$> f {{name}}
4744
{-# INLINE {{name}}L #-}
48-
{{/required}}
49-
{{^required}}
50-
-- | '{{name}}' Traversal
51-
{{name}}T :: Traversal_' {{classname}} {{datatype}}
52-
{{name}}T f s = _mtraversal {{name}} (\b -> s { {{name}} = Just b}) f s
53-
{-# INLINE {{name}}T #-}
54-
{{/required}}
5545

5646
{{/vars}}
5747

5848
{{/model}}
59-
{{/models}}
60-
61-
62-
-- * Helpers
63-
64-
_mtraversal :: Applicative f => (b -> Maybe t) -> (a -> b) -> (t -> f a) -> b -> f b
65-
_mtraversal x fsb f s = maybe (pure s) (\a -> fsb <$> f a) (x s)
66-
{-# INLINE _mtraversal #-}
49+
{{/models}}

modules/swagger-codegen/src/main/resources/haskell-http-client/README.mustache

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ These options allow some customization of the code generation process.
6262

6363
**haskell-http-client specific options:**
6464

65-
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
66-
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------- |
67-
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | {{allowFromJsonNulls}} |
68-
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | {{allowToJsonNulls}} |
69-
| dateFormat | format string used to parse/render a date | %Y-%m-%d | {{dateFormat}} |
70-
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | {{dateTimeFormat}} |
71-
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | {{generateFormUrlEncodedInstances}} |
72-
| generateLenses | Generate Lens optics for Models | true | {{generateLenses}} |
73-
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | {{generateModelConstructors}} |
74-
| modelDeriving | Additional classes to include in the deriving() clause of Models | | {{modelDeriving}} |
65+
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
66+
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
67+
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | {{{allowFromJsonNulls}}} |
68+
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | {{{allowToJsonNulls}}} |
69+
| dateFormat | format string used to parse/render a date | %Y-%m-%d | {{{dateFormat}}} |
70+
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | {{{dateTimeFormat}}} |
71+
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | {{{generateFormUrlEncodedInstances}}} |
72+
| generateLenses | Generate Lens optics for Models | true | {{{generateLenses}}} |
73+
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | {{{generateModelConstructors}}} |
74+
| modelDeriving | Additional classes to include in the deriving() clause of Models | | {{{modelDeriving}}} |
7575

7676
[1]: https://www.stackage.org/haddock/lts-9.0/iso8601-time-0.1.4/Data-Time-ISO8601.html#v:formatISO8601Millis
7777

@@ -85,13 +85,13 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help
8585

8686
An example of the generated haddock documentation targeting the server http://petstore.swagger.io/ (SwaggerPetstore) can be found [here][2]
8787

88-
[2]: https://jonschoning.github.io/swaggerpetstore-haskell-http-client/
88+
[2]: https://hackage.haskell.org/package/swagger-petstore
8989

9090
### Example SwaggerPetstore App
9191

9292
An example application using the auto-generated haskell-http-client bindings for the server http://petstore.swagger.io/ can be found [here][3]
9393

94-
[3]: https://github.com/jonschoning/swagger-codegen/tree/haskell-http-client/samples/client/petstore/haskell-http-client/example-app
94+
[3]: https://github.com/swagger-api/swagger-codegen/tree/c7d145a4ba3c0627e04ece9eb97e354ac91be821/samples/client/petstore/haskell-http-client/example-app
9595

9696
### Usage Notes
9797

@@ -103,22 +103,23 @@ This library is intended to be imported qualified.
103103
| {{title}}.API | construct requetss |
104104
| {{title}}.Model | describes models |
105105
| {{title}}.MimeTypes | encoding/decoding MIME types (content-types/accept) |
106-
| {{title}}.Lens | lenses & traversals for model fields |
106+
| {{title}}.Lens | lenses for model fields |
107107

108108
This library adds type safety around what swagger specifies as
109109
Produces and Consumes for each Operation (e.g. the list of MIME types an
110110
Operation can Produce (using 'accept' headers) and Consume (using 'content-type' headers).
111111

112112
For example, if there is an Operation named _addFoo_, there will be a
113-
data type generated named _AddFoo_ (note the capitalization) which
114-
describes additional constraints and actions on the _addFoo_
115-
operation, which can be viewed in GHCi or via the Haddocks.
113+
data type generated named _AddFoo_ (note the capitalization), which
114+
describes additional constraints and actions on the _addFoo_ operation
115+
via its typeclass instances. These typeclass instances can be viewed
116+
in GHCi or via the Haddocks.
116117

117118
* requried parameters are included as function arguments to _addFoo_
118119
* optional non-body parameters are included by using `applyOptionalParam`
119120
* optional body parameters are set by using `setBodyParam`
120121

121-
Example for pretend _addFoo_ operation:
122+
Example code generated for pretend _addFoo_ operation:
122123

123124
```haskell
124125
data AddFoo

samples/client/petstore/haskell-http-client/README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ These options allow some customization of the code generation process.
6262

6363
**haskell-http-client specific options:**
6464

65-
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
66-
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------- |
65+
| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
66+
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
6767
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | true |
6868
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | false |
69-
| dateFormat | format string used to parse/render a date | %Y-%m-%d | |
69+
| dateFormat | format string used to parse/render a date | %Y-%m-%d | %Y-%m-%d |
7070
| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | |
7171
| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | true |
7272
| generateLenses | Generate Lens optics for Models | true | true |
@@ -85,13 +85,13 @@ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help
8585

8686
An example of the generated haddock documentation targeting the server http://petstore.swagger.io/ (SwaggerPetstore) can be found [here][2]
8787

88-
[2]: https://jonschoning.github.io/swaggerpetstore-haskell-http-client/
88+
[2]: https://hackage.haskell.org/package/swagger-petstore
8989

9090
### Example SwaggerPetstore App
9191

9292
An example application using the auto-generated haskell-http-client bindings for the server http://petstore.swagger.io/ can be found [here][3]
9393

94-
[3]: https://github.com/jonschoning/swagger-codegen/tree/haskell-http-client/samples/client/petstore/haskell-http-client/example-app
94+
[3]: https://github.com/swagger-api/swagger-codegen/tree/c7d145a4ba3c0627e04ece9eb97e354ac91be821/samples/client/petstore/haskell-http-client/example-app
9595

9696
### Usage Notes
9797

@@ -103,22 +103,23 @@ This library is intended to be imported qualified.
103103
| SwaggerPetstore.API | construct requetss |
104104
| SwaggerPetstore.Model | describes models |
105105
| SwaggerPetstore.MimeTypes | encoding/decoding MIME types (content-types/accept) |
106-
| SwaggerPetstore.Lens | lenses & traversals for model fields |
106+
| SwaggerPetstore.Lens | lenses for model fields |
107107

108108
This library adds type safety around what swagger specifies as
109109
Produces and Consumes for each Operation (e.g. the list of MIME types an
110110
Operation can Produce (using 'accept' headers) and Consume (using 'content-type' headers).
111111

112112
For example, if there is an Operation named _addFoo_, there will be a
113-
data type generated named _AddFoo_ (note the capitalization) which
114-
describes additional constraints and actions on the _addFoo_
115-
operation, which can be viewed in GHCi or via the Haddocks.
113+
data type generated named _AddFoo_ (note the capitalization), which
114+
describes additional constraints and actions on the _addFoo_ operation
115+
via its typeclass instances. These typeclass instances can be viewed
116+
in GHCi or via the Haddocks.
116117

117118
* requried parameters are included as function arguments to _addFoo_
118119
* optional non-body parameters are included by using `applyOptionalParam`
119120
* optional body parameters are set by using `setBodyParam`
120121

121-
Example for pretend _addFoo_ operation:
122+
Example code generated for pretend _addFoo_ operation:
122123

123124
```haskell
124125
data AddFoo

samples/client/petstore/haskell-http-client/docs.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

samples/client/petstore/haskell-http-client/docs/SwaggerPetstore-Lens.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

samples/client/petstore/haskell-http-client/docs/SwaggerPetstore-Model.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)