Skip to content

Commit b74dede

Browse files
authored
Merge pull request #7 from mbohlool/first
Add first version of generated client
2 parents 2667717 + 3cb4426 commit b74dede

26 files changed

+476391
-0
lines changed

kubernetes/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.stack-work
2+
src/highlight.js
3+
src/style.css
4+
dist
5+
dist-newstyle
6+
cabal.project.local
7+
.cabal-sandbox
8+
cabal.sandbox.config

kubernetes/.swagger-codegen-ignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Codegen Ignore
2+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md

kubernetes/.swagger-codegen/COMMIT

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Requested Commit: 5b76151a874009605f5ac5d4e6dc1aaa389339ed
2+
Actual Commit: 5b76151a874009605f5ac5d4e6dc1aaa389339ed

kubernetes/.swagger-codegen/VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.3.0-SNAPSHOT

kubernetes/.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sudo: false
2+
language: c
3+
addons:
4+
apt:
5+
packages:
6+
- libgmp-dev
7+
before_install:
8+
- mkdir -p ~/.local/bin
9+
- export PATH=$HOME/.local/bin:$PATH
10+
- travis_retry curl -L https://www.stackage.org/stack/linux-x86_64 | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
11+
script:
12+
- stack --install-ghc --no-haddock-deps haddock
13+
- stack test
14+
cache:
15+
directories:
16+
- $HOME/.stack

kubernetes/README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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.

kubernetes/Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

kubernetes/git_push.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/sh
2+
# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3+
#
4+
# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update"
5+
6+
git_user_id=$1
7+
git_repo_id=$2
8+
release_note=$3
9+
10+
if [ "$git_user_id" = "" ]; then
11+
git_user_id="GIT_USER_ID"
12+
echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
13+
fi
14+
15+
if [ "$git_repo_id" = "" ]; then
16+
git_repo_id="GIT_REPO_ID"
17+
echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
18+
fi
19+
20+
if [ "$release_note" = "" ]; then
21+
release_note="Minor update"
22+
echo "[INFO] No command line input provided. Set \$release_note to $release_note"
23+
fi
24+
25+
# Initialize the local directory as a Git repository
26+
git init
27+
28+
# Adds the files in the local repository and stages them for commit.
29+
git add .
30+
31+
# Commits the tracked changes and prepares them to be pushed to a remote repository.
32+
git commit -m "$release_note"
33+
34+
# Sets the new remote
35+
git_remote=`git remote`
36+
if [ "$git_remote" = "" ]; then # git remote not defined
37+
38+
if [ "$GIT_TOKEN" = "" ]; then
39+
echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
40+
git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git
41+
else
42+
git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git
43+
fi
44+
45+
fi
46+
47+
git pull origin master
48+
49+
# Pushes (Forces) the changes in the local repository up to the remote repository
50+
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
51+
git push origin master 2>&1 | grep -v 'To https'
52+

0 commit comments

Comments
 (0)