Skip to content

Commit

Permalink
generate with openapi-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschoning committed Feb 28, 2019
1 parent e084d0c commit 6433ac6
Show file tree
Hide file tree
Showing 73 changed files with 235,604 additions and 240,918 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
Expand All @@ -21,5 +21,3 @@
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

README.md
2 changes: 2 additions & 0 deletions kubernetes/.openapi-generator/COMMIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Requested Commit: c30a21ac3cd8b1d8a3db600e4079977af0681e11
Actual Commit: c30a21ac3cd8b1d8a3db600e4079977af0681e11
1 change: 1 addition & 0 deletions kubernetes/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0-SNAPSHOT
1 change: 1 addition & 0 deletions kubernetes/.openapi-generator/swagger.json.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
68a75356636abec984972b3864294695fe7f117192ddd4acd5ffa77a215422e4
2 changes: 0 additions & 2 deletions kubernetes/.swagger-codegen/COMMIT

This file was deleted.

1 change: 0 additions & 1 deletion kubernetes/.swagger-codegen/VERSION

This file was deleted.

201 changes: 195 additions & 6 deletions kubernetes/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,200 @@
## Swagger Auto-Generated [http-client](https://www.stackage.org/lts-9.0/package/http-client-0.5.7.0) Bindings to `Kubernetes`
## OpenAPI Auto-Generated [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) Bindings to `Kubernetes`

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.
The library in `lib` provides auto-generated-from-OpenAPI [http-client](https://www.stackage.org/lts-10.0/package/http-client-0.5.7.1) bindings to the Kubernetes API.

Targeted swagger version: 2.0
OpenApi Version: 3.0.1

OpenAPI-Specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
## Installation

## Usage
Installation follows the standard approach to installing Stack-based projects.

Please refer to the README of the `kubernetes-client-helper` package.
1. Install the [Haskell `stack` tool](http://docs.haskellstack.org/en/stable/README).
2. To build the package, and generate the documentation (recommended):
```
stack haddock
```
which will generate docs for this lib in the `docs` folder.

To generate the docs in the normal location (to enable hyperlinks to external libs), remove
```
build:
haddock-arguments:
haddock-args:
- "--odir=./docs"
```
from the stack.yaml file and run `stack haddock` again.

3. To run unit tests:
```
stack test
```

## OpenAPI-Generator

The code generator that produced this library, and which explains how
to obtain and use the openapi-generator cli tool lives at

https://openapi-generator.tech

The _generator-name_ argument (`--generator-name`) passed to the cli tool used should be

```
haskell-http-client
```

### Unsupported OpenAPI Features

* Model Inheritance

This is beta software; other cases may not be supported.

### Codegen "additional properties" parameters

These options allow some customization of the code generation process.

**haskell-http-client additional properties:**

| OPTION | DESCRIPTION | DEFAULT | ACTUAL |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- | -------- | ------------------------------------- |
| allowFromJsonNulls | allow JSON Null during model decoding from JSON | true | true |
| allowNonUniqueOperationIds | allow *different* API modules to contain the same operationId. Each API must be imported qualified | false | true |
| allowToJsonNulls | allow emitting JSON Null during model encoding to JSON | false | false |
| baseModule | Set the base module namespace | | Kubernetes.OpenAPI |
| cabalPackage | Set the cabal package name, which consists of one or more alphanumeric words separated by hyphens | | kubernetes-openapi-client-gen |
| cabalVersion | Set the cabal version number, consisting of a sequence of one or more integers separated by dots | 0.1.0.0 | 0.1.0.0 |
| configType | Set the name of the type used for configuration | | KubernetesClientConfig |
| 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) | | |
| generateEnums | Generate specific datatypes for OpenAPI enums | true | true |
| 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 |
| generateModelConstructors | Generate smart constructors (only supply required fields) for models | true | true |
| inlineMimeTypes | Inline (hardcode) the content-type and accept parameters on operations, when there is only 1 option | true | true |
| modelDeriving | Additional classes to include in the deriving() clause of Models | | |
| requestType | Set the name of the type used to generate requests | | KubernetesRequest |
| strictFields | Add strictness annotations to all model fields | true | true |
| useKatip | Sets the default value for the UseKatip cabal flag. If true, the katip package provides logging instead of monad-logger | true | true |

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

An example setting _strictFields_ and _dateTimeFormat_:

```
java -jar openapi-generator-cli.jar generate -i petstore.yaml -g haskell-http-client -o output/haskell-http-client -DstrictFields=true -DdateTimeFormat="%Y-%m-%dT%H:%M:%S%Q%z"
```

View the full list of Codegen "config option" parameters with the command:

```
java -jar openapi-generator-cli.jar config-help -g haskell-http-client
```

## Usage Notes

### Example Petstore Haddock documentation

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

[2]: https://hackage.haskell.org/package/swagger-petstore

### Example Petstore 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/openapitools/openapi-generator/tree/master/samples/client/petstore/haskell-http-client/example-app

This library is intended to be imported qualified.

### Modules

| MODULE | NOTES |
| ------------------- | --------------------------------------------------- |
| Kubernetes.OpenAPI.Client | use the "dispatch" functions to send requests |
| Kubernetes.OpenAPI.Core | core funcions, config and request types |
| Kubernetes.OpenAPI.API | construct api requests |
| Kubernetes.OpenAPI.Model | describes api models |
| Kubernetes.OpenAPI.MimeTypes | encoding/decoding MIME types (content-types/accept) |
| Kubernetes.OpenAPI.ModelLens | lenses for model fields |
| Kubernetes.OpenAPI.Logging | logging functions and utils |


### MimeTypes

This library adds type safety around what OpenAPI 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
via its typeclass instances. These typeclass instances can be viewed
in GHCi or via the Haddocks.

* required 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 code generated for pretend _addFoo_ operation:

```haskell
data AddFoo
instance Consumes AddFoo MimeJSON
instance Produces AddFoo MimeJSON
instance Produces AddFoo MimeXML
instance HasBodyParam AddFoo FooModel
instance HasOptionalParam AddFoo FooName
instance HasOptionalParam AddFoo FooId
```

this would indicate that:

* the _addFoo_ operation can consume JSON
* the _addFoo_ operation produces JSON or XML, depending on the argument passed to the dispatch function
* the _addFoo_ operation can set it's body param of _FooModel_ via `setBodyParam`
* the _addFoo_ operation can set 2 different optional parameters via `applyOptionalParam`

If the OpenAPI spec doesn't declare it can accept or produce a certain
MIME type for a given Operation, you should either add a Produces or
Consumes instance for the desired MIME types (assuming the server
supports it), use `dispatchLbsUnsafe` or modify the OpenAPI spec and
run the generator again.

New MIME type instances can be added via MimeType/MimeRender/MimeUnrender

Only JSON instances are generated by default, and in some case
x-www-form-urlencoded instances (FromFrom, ToForm) will also be
generated if the model fields are primitive types, and there are
Operations using x-www-form-urlencoded which use those models.

### Authentication

A haskell data type will be generated for each OpenAPI authentication type.

If for example the AuthMethod `AuthOAuthFoo` is generated for OAuth operations, then
`addAuthMethod` should be used to add the AuthMethod config.

When a request is dispatched, if a matching auth method is found in
the config, it will be applied to the request.

### Example

```haskell
mgr <- newManager defaultManagerSettings
config0 <- withStdoutLogging =<< newConfig
let config = config0
`addAuthMethod` AuthOAuthFoo "secret-key"

let addFooRequest =
addFoo
(ContentType MimeJSON)
(Accept MimeXML)
(ParamBar paramBar)
(ParamQux paramQux)
modelBaz
`applyOptionalParam` FooId 1
`applyOptionalParam` FooName "name"
`setHeader` [("qux_header","xxyy")]
addFooResult <- dispatchMime mgr config addFooRequest
```

See the example app and the haddocks for details.
2 changes: 1 addition & 1 deletion kubernetes/git_push.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
#
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update"

git_user_id=$1
git_repo_id=$2
Expand Down
33 changes: 22 additions & 11 deletions kubernetes/kubernetes-openapi-client-gen.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ synopsis: Auto-generated kubernetes-openapi-client-gen API Client
description: .
Client library for calling the Kubernetes API based on http-client.
.
host:
host: localhost
.
base path: https://localhost
base path: http://localhost
.
Kubernetes API version: v1.9.12
.
OpenAPI spec version: 2.0
OpenAPI version: 3.0.1
.
OpenAPI-Specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
.
category: Web
category: Web
homepage: https://github.com/kubernetes-client/haskell
author: Auto Generated
maintainer: Shimin Guo <smguo2001@gmail.com>
Expand All @@ -24,7 +22,12 @@ cabal-version: >= 1.10

extra-source-files:
README.md
swagger.yaml
openapi.yaml

Flag UseKatip
Description: Use the katip package to provide logging (if false, use the default monad-logger package)
Default: True
Manual: True

library
hs-source-dirs:
Expand All @@ -36,26 +39,25 @@ library
, base64-bytestring >1.0 && <2.0
, bytestring >=0.10.0 && <0.11
, case-insensitive
, containers >=0.5.0.0 && <0.6
, containers >=0.5.0.0 && <0.8
, deepseq >= 1.4 && <1.6
, exceptions >= 0.4
, http-api-data >= 0.3.4 && <0.4
, http-api-data >= 0.3.4 && <0.5
, http-client >=0.5 && <0.6
, http-client-tls
, http-media >= 0.4 && < 0.8
, http-types >=0.8 && <0.13
, iso8601-time >=0.1.3 && <0.2.0
, microlens >= 0.4.3 && <0.5
, mtl >=2.2.1
, network >=2.6.2 && <2.7
, network >=2.6.2 && <2.9
, random >=1.1
, safe-exceptions <0.2
, text >=0.11 && <1.3
, time >=1.5 && <1.10
, transformers >=0.4.0.0
, unordered-containers
, vector >=0.10.9 && <0.13
, katip >=0.4 && < 0.6
other-modules:
Paths_kubernetes_openapi_client_gen
exposed-modules:
Expand Down Expand Up @@ -120,6 +122,15 @@ library
Kubernetes.OpenAPI.ModelLens
default-language: Haskell2010

if flag(UseKatip)
build-depends: katip >=0.6 && < 1.0
other-modules: Kubernetes.OpenAPI.LoggingKatip
cpp-options: -DUSE_KATIP
else
build-depends: monad-logger >=0.3 && <0.4
other-modules: Kubernetes.OpenAPI.LoggingMonadLogger
cpp-options: -DUSE_MONAD_LOGGER

test-suite tests
type: exitcode-stdio-1.0
main-is: Test.hs
Expand Down
6 changes: 3 additions & 3 deletions kubernetes/lib/Kubernetes/OpenAPI.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{-
Kubernetes
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
OpenAPI spec version: 2.0
OpenAPI Version: 3.0.1
Kubernetes API version: v1.9.12
Generated by Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
Generated by OpenAPI Generator (https://openapi-generator.tech)
-}

{-|
Expand Down
18 changes: 5 additions & 13 deletions kubernetes/lib/Kubernetes/OpenAPI/API/Admissionregistration.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{-
Kubernetes
No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
OpenAPI spec version: 2.0
OpenAPI Version: 3.0.1
Kubernetes API version: v1.9.12
Generated by Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
Generated by OpenAPI Generator (https://openapi-generator.tech)
-}

{-|
Expand Down Expand Up @@ -73,18 +73,10 @@ getAPIGroup _ =
`_hasAuthType` (P.Proxy :: P.Proxy AuthApiKeyBearerToken)

data GetAPIGroup

-- | @application/json@
instance Consumes GetAPIGroup MimeJSON
-- | @application/yaml@
instance Consumes GetAPIGroup MimeYaml
-- | @application/vnd.kubernetes.protobuf@
instance Consumes GetAPIGroup MimeVndKubernetesProtobuf

-- | @application/json@
instance Produces GetAPIGroup MimeJSON
-- | @application/yaml@
instance Produces GetAPIGroup MimeYaml
-- | @application/vnd.kubernetes.protobuf@
instance Produces GetAPIGroup MimeVndKubernetesProtobuf
-- | @application/yaml@
instance Produces GetAPIGroup MimeYaml

Loading

0 comments on commit 6433ac6

Please sign in to comment.