|
| 1 | +## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `Kubernetes` |
| 2 | + |
| 3 | +The library in `lib` provides auto-generated-from-Swagger [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) bindings to the Kubernetes API. |
| 4 | + |
| 5 | +Targeted swagger version: 2.0 |
| 6 | + |
| 7 | +OpenAPI-Specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Installation follows the standard approach to installing Stack-based projects. |
| 12 | + |
| 13 | +1. Install the [Haskell `stack` tool](http://docs.haskellstack.org/en/stable/README). |
| 14 | +2. To build the package, and generate the documentation (recommended): |
| 15 | +``` |
| 16 | +stack haddock |
| 17 | +``` |
| 18 | +which will generate docs for this lib in the `docs` folder. |
| 19 | + |
| 20 | +To generate the docs in the normal location (to enable hyperlinks to external libs), remove |
| 21 | +``` |
| 22 | +build: |
| 23 | + haddock-arguments: |
| 24 | + haddock-args: |
| 25 | + - "--odir=./docs" |
| 26 | +``` |
| 27 | +from the stack.yaml file and run `stack haddock` again. |
| 28 | + |
| 29 | +3. To run unit tests: |
| 30 | +``` |
| 31 | +stack test |
| 32 | +``` |
| 33 | + |
| 34 | +## Swagger-Codegen |
| 35 | + |
| 36 | +The code generator that produced this library, and which explains how |
| 37 | +to obtain and use the swagger-codegen cli tool lives at |
| 38 | + |
| 39 | +https://github.com/swagger-api/swagger-codegen |
| 40 | + |
| 41 | +The _language_ argument (`--lang`) passed to the cli tool used should be |
| 42 | + |
| 43 | +``` |
| 44 | +haskell-http-client |
| 45 | +``` |
| 46 | + |
| 47 | +### Unsupported Swagger Features |
| 48 | + |
| 49 | +* Model Inheritance |
| 50 | + |
| 51 | +This is beta software; other cases may not be supported. |
| 52 | + |
| 53 | +### Codegen "additional properties" parameters |
| 54 | + |
| 55 | +These options allow some customization of the code generation process. |
| 56 | + |
| 57 | +**haskell-http-client additional properties:** |
| 58 | + |
| 59 | +| OPTION | DESCRIPTION | DEFAULT | ACTUAL | |
| 60 | +| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- | |
| 61 | +| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | true | |
| 62 | +| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | false | |
| 63 | +| dateFormat | format string used to parse/render a date | %Y-%m-%d | %Y-%m-%d | |
| 64 | +| dateTimeFormat | format string used to parse/render a datetime. (Defaults to [formatISO8601Millis][1] when not provided) | | | |
| 65 | +| generateEnums | Generate specific datatypes for swagger enums | true | true | |
| 66 | +| generateFormUrlEncodedInstances | Generate FromForm/ToForm instances for models used by x-www-form-urlencoded operations (model fields must be primitive types) | true | true | |
| 67 | +| generateLenses | Generate Lens optics for Models | true | true | |
| 68 | +| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | true | |
| 69 | +| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | false | false | |
| 70 | +| modelDeriving | Additional classes to include in the deriving() clause of Models | | | |
| 71 | +| strictFields | Add strictness annotations to all model fields | true | true | |
| 72 | +| useMonadLogger | Use the monad-logger package to provide logging (if instead false, use the katip logging package) | false | false | |
| 73 | + |
| 74 | +[1]: https://www.stackage.org/haddock/lts-9.0/iso8601-time-0.1.4/Data-Time-ISO8601.html#v:formatISO8601Millis |
| 75 | + |
| 76 | +An example setting _strictFields_ and _dateTimeFormat_: |
| 77 | + |
| 78 | +``` |
| 79 | +java -jar swagger-codegen-cli.jar generate -i petstore.yaml -l haskell-http-client -o output/haskell-http-client -DstrictFields=true -DdateTimeFormat="%Y-%m-%dT%H:%M:%S%Q%z" |
| 80 | +``` |
| 81 | + |
| 82 | +View the full list of Codegen "config option" parameters with the command: |
| 83 | + |
| 84 | +``` |
| 85 | +java -jar swagger-codegen-cli.jar config-help -l haskell-http-client |
| 86 | +``` |
| 87 | + |
| 88 | +## Usage Notes |
| 89 | + |
| 90 | +### Example SwaggerPetstore Haddock documentation |
| 91 | + |
| 92 | +An example of the generated haddock documentation targeting the server http://petstore.swagger.io/ (SwaggerPetstore) can be found [here][2] |
| 93 | + |
| 94 | +[2]: https://hackage.haskell.org/package/swagger-petstore |
| 95 | + |
| 96 | +### Example SwaggerPetstore App |
| 97 | + |
| 98 | +An example application using the auto-generated haskell-http-client bindings for the server http://petstore.swagger.io/ can be found [here][3] |
| 99 | + |
| 100 | +[3]: https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/haskell-http-client/example-app |
| 101 | + |
| 102 | +This library is intended to be imported qualified. |
| 103 | + |
| 104 | +### Modules |
| 105 | + |
| 106 | +| MODULE | NOTES | |
| 107 | +| ------------------- | --------------------------------------------------- | |
| 108 | +| Kubernetes.Client | use the "dispatch" functions to send requests | |
| 109 | +| Kubernetes.Core | core funcions, config and request types | |
| 110 | +| Kubernetes.API | construct api requests | |
| 111 | +| Kubernetes.Model | describes api models | |
| 112 | +| Kubernetes.MimeTypes | encoding/decoding MIME types (content-types/accept) | |
| 113 | +| Kubernetes.ModelLens | lenses for model fields | |
| 114 | +| Kubernetes.Logging | logging functions and utils | |
| 115 | + |
| 116 | + |
| 117 | +### MimeTypes |
| 118 | + |
| 119 | +This library adds type safety around what swagger specifies as |
| 120 | +Produces and Consumes for each Operation (e.g. the list of MIME types an |
| 121 | +Operation can Produce (using 'accept' headers) and Consume (using 'content-type' headers). |
| 122 | + |
| 123 | +For example, if there is an Operation named _addFoo_, there will be a |
| 124 | +data type generated named _AddFoo_ (note the capitalization), which |
| 125 | +describes additional constraints and actions on the _addFoo_ operation |
| 126 | +via its typeclass instances. These typeclass instances can be viewed |
| 127 | +in GHCi or via the Haddocks. |
| 128 | + |
| 129 | +* required parameters are included as function arguments to _addFoo_ |
| 130 | +* optional non-body parameters are included by using `applyOptionalParam` |
| 131 | +* optional body parameters are set by using `setBodyParam` |
| 132 | + |
| 133 | +Example code generated for pretend _addFoo_ operation: |
| 134 | + |
| 135 | +```haskell |
| 136 | +data AddFoo |
| 137 | +instance Consumes AddFoo MimeJSON |
| 138 | +instance Produces AddFoo MimeJSON |
| 139 | +instance Produces AddFoo MimeXML |
| 140 | +instance HasBodyParam AddFoo FooModel |
| 141 | +instance HasOptionalParam AddFoo FooName |
| 142 | +instance HasOptionalParam AddFoo FooId |
| 143 | +``` |
| 144 | + |
| 145 | +this would indicate that: |
| 146 | + |
| 147 | +* the _addFoo_ operation can consume JSON |
| 148 | +* the _addFoo_ operation produces JSON or XML, depending on the argument passed to the dispatch function |
| 149 | +* the _addFoo_ operation can set it's body param of _FooModel_ via `setBodyParam` |
| 150 | +* the _addFoo_ operation can set 2 different optional parameters via `applyOptionalParam` |
| 151 | + |
| 152 | +If the swagger spec doesn't declare it can accept or produce a certain |
| 153 | +MIME type for a given Operation, you should either add a Produces or |
| 154 | +Consumes instance for the desired MIME types (assuming the server |
| 155 | +supports it), use `dispatchLbsUnsafe` or modify the swagger spec and |
| 156 | +run the generator again. |
| 157 | + |
| 158 | +New MIME type instances can be added via MimeType/MimeRender/MimeUnrender |
| 159 | + |
| 160 | +Only JSON instances are generated by default, and in some case |
| 161 | +x-www-form-urlencoded instances (FromFrom, ToForm) will also be |
| 162 | +generated if the model fields are primitive types, and there are |
| 163 | +Operations using x-www-form-urlencoded which use those models. |
| 164 | + |
| 165 | +### Authentication |
| 166 | + |
| 167 | +A haskell data type will be generated for each swagger authentication type. |
| 168 | + |
| 169 | +If for example the AuthMethod `AuthOAuthFoo` is generated for OAuth operations, then |
| 170 | +`addAuthMethod` should be used to add the AuthMethod config. |
| 171 | + |
| 172 | +When a request is dispatched, if a matching auth method is found in |
| 173 | +the config, it will be applied to the request. |
| 174 | + |
| 175 | +### Example |
| 176 | + |
| 177 | +```haskell |
| 178 | +mgr <- newManager defaultManagerSettings |
| 179 | +config0 <- withStdoutLogging =<< newConfig |
| 180 | +let config = config0 |
| 181 | + `addAuthMethod` AuthOAuthFoo "secret-key" |
| 182 | + |
| 183 | +let addFooRequest = |
| 184 | + addFoo |
| 185 | + (ContentType MimeJSON) |
| 186 | + (Accept MimeXML) |
| 187 | + (ParamBar paramBar) |
| 188 | + (ParamQux paramQux) |
| 189 | + modelBaz |
| 190 | + `applyOptionalParam` FooId 1 |
| 191 | + `applyOptionalParam` FooName "name" |
| 192 | + `setHeader` [("qux_header","xxyy")] |
| 193 | +addFooResult <- dispatchMime mgr config addFooRequest |
| 194 | +``` |
| 195 | + |
| 196 | +See the example app and the haddocks for details. |
0 commit comments