Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[haskell-http-client] update readme; improve lens generation; fix dateFormat #6448

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public HaskellHttpClientCodegen() {
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("stack.mustache", "", "stack.yaml"));
supportingFiles.add(new SupportingFile("Setup.mustache", "", "Setup.hs"));
supportingFiles.add(new SupportingFile(".gitignore", "", ".gitignore"));
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
supportingFiles.add(new SupportingFile(".travis.yml", "", ".travis.yml"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));

Expand Down Expand Up @@ -241,7 +241,7 @@ public void setDateTimeFormat(String value) {

public void setDateFormat(String value) {
if (StringUtils.isBlank(value)) {
additionalProperties.remove(DATE_FORMAT);
additionalProperties.put(DATE_FORMAT, defaultDateFormat);
} else {
additionalProperties.put(DATE_FORMAT, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import {{title}}.Model

-- * Type Aliases

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

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

{{#vars}}
{{#required}}
-- | '{{name}}' Lens
{{name}}L :: Lens_' {{classname}} {{datatype}}
{{name}}L :: Lens_' {{classname}} ({{^required}}Maybe {{/required}}{{datatype}})
{{name}}L f {{classname}}{..} = (\{{name}} -> {{classname}} { {{name}}, ..} ) <$> f {{name}}
{-# INLINE {{name}}L #-}
{{/required}}
{{^required}}
-- | '{{name}}' Traversal
{{name}}T :: Traversal_' {{classname}} {{datatype}}
{{name}}T f s = _mtraversal {{name}} (\b -> s { {{name}} = Just b}) f s
{-# INLINE {{name}}T #-}
{{/required}}

{{/vars}}

{{/model}}
{{/models}}


-- * Helpers

_mtraversal :: Applicative f => (b -> Maybe t) -> (a -> b) -> (t -> f a) -> b -> f b
_mtraversal x fsb f s = maybe (pure s) (\a -> fsb <$> f a) (x s)
{-# INLINE _mtraversal #-}
{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ These options allow some customization of the code generation process.

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

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

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

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

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

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

### Example SwaggerPetstore App

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

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

### Usage Notes

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

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

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

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

Example for pretend _addFoo_ operation:
Example code generated for pretend _addFoo_ operation:

```haskell
data AddFoo
Expand Down
21 changes: 11 additions & 10 deletions samples/client/petstore/haskell-http-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ These options allow some customization of the code generation process.

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

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

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

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

### Example SwaggerPetstore App

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

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

### Usage Notes

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

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

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

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

Example for pretend _addFoo_ operation:
Example code generated for pretend _addFoo_ operation:

```haskell
data AddFoo
Expand Down
31 changes: 0 additions & 31 deletions samples/client/petstore/haskell-http-client/docs.sh

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading