Skip to content

Commit

Permalink
Added openapi generator bash
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kocisek committed Jan 19, 2022
1 parent 2aa1d8c commit 96fcd1b
Show file tree
Hide file tree
Showing 20 changed files with 2,305 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/key
/key
*.jar
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"remisa.shellman"
]
}
2 changes: 2 additions & 0 deletions ds_dphs_search.example.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash

# ziskanie objekt pre eset
. ./ds_dphs_search.sh SK2020317068 | jq '.data[]'
13 changes: 7 additions & 6 deletions ds_dphs_search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ set -e
. ./config.sh

_SEARCH=$1
_PAGE=${2:-"1"}
_PAGE=${2:-1}
_COLUMN=${3:-"ic_dph"}

curl -X GET --insecure -H "key: ${OAFS_KEY}" https://iz.opendata.financnasprava.sk/api/data/ds_dphs/search \
-G \
-d page=${_PAGE} \
-d column=${_COLUMN} \
-d search=${_SEARCH}
./generator/generated/iz/client.sh \
--host https://iz.opendata.financnasprava.sk/api/data \
dataSlugSearchGet \
'key:${OAFS_KEY}' \
slug=ds_dphs page=${_PAGE} column=${_COLUMN} search=${_SEARCH}

27 changes: 27 additions & 0 deletions generator/generate-iz.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

. generator.sh
. swagger-iz.sh

_DIR=./generated/iz

if [ ! -d "${_DIR}" ]; then
mkdir -p ${_DIR}
fi

rm -rf ../generated/iz

SWAGGER="swagger-iz.yaml"

echo $OAFS_JAR

java -ea \
${JAVA_OPTS} \
-server \
-jar ${OAFS_JAR} \
generate \
--input-spec "${SWAGGER}" \
--generator-name bash \
--output ${_DIR} \
23 changes: 23 additions & 0 deletions generator/generated/iz/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 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 (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
10 changes: 10 additions & 0 deletions generator/generated/iz/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.openapi-generator-ignore
Dockerfile
README.md
_client.sh
client.sh
client.sh.bash-completion
docs/Data.md
docs/DataApi.md
docs/List.md
docs/ListsApi.md
1 change: 1 addition & 0 deletions generator/generated/iz/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3.1
66 changes: 66 additions & 0 deletions generator/generated/iz/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
FROM alpine:3.12.0

RUN apk add --update --no-cache curl ca-certificates bash bash-completion zsh curl git vim ncurses util-linux

ADD client.sh /usr/bin/client.sh
ADD _client.sh /usr/local/share/zsh/site-functions/_client.sh
ADD client.sh.bash-completion /etc/bash-completion.d/client.sh
RUN chmod 755 /usr/bin/client.sh

#
# Install oh-my-zsh
#
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" || true

#
# Enable bash completion
#
RUN echo '\n\
. /etc/bash_completion\n\
source /etc/bash-completion.d/client.sh\n\
' >> ~/.bashrc

#
# Setup prompt
#
RUN echo 'export PS1="[OpenData FS Information Lists API] \$ "' >> ~/.bashrc
RUN echo 'export PROMPT="[OpenData FS Information Lists API] \$ "' >> ~/.zshrc

#
# Setup a welcome message with basic instruction
#
RUN echo -e 'echo "\
\n\
This Docker provides preconfigured environment for running the command\n\
line REST client for $(tput setaf 6)OpenData FS Information Lists API$(tput sgr0).\n\
\n\
For convenience, you can export the following environment variables:\n\
\n\
\n\
$(tput setaf 7)Basic usage:$(tput sgr0)\n\
\n\
$(tput setaf 3)Print the list of operations available on the service$(tput sgr0)\n\
$ client.sh -h\n\
\n\
$(tput setaf 3)Print the service description$(tput sgr0)\n\
$ client.sh --about\n\
\n\
$(tput setaf 3)Print detailed information about specific operation$(tput sgr0)\n\
$ client.sh <operationId> -h\n\
\n\
By default you are logged into Zsh with full autocompletion for your REST API,\n\
but you can switch to Bash, where basic autocompletion is also supported.\n\
\n\
"\
' | tee -a ~/.bashrc ~/.zshrc

#
# Poormans chsh & cleanup to make image as compact as possible
#

RUN sed -i 's/root:x:0:0:root:\/root:\/bin\/ash/root:x:0:0:root:\/root:\/bin\/zsh/' /etc/passwd
RUN apk del git vim && rm -f /var/cache/apk/*

ENTRYPOINT ["/bin/zsh"]
127 changes: 127 additions & 0 deletions generator/generated/iz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# OpenData FS Information Lists API Bash client

## Overview

This is a Bash client script for accessing OpenData FS Information Lists API service.

The script uses cURL underneath for making all REST calls.

## Usage

```shell
# Make sure the script has executable rights
$ chmod u+x

# Print the list of operations available on the service
$ ./ -h

# Print the service description
$ ./ --about

# Print detailed information about specific operation
$ ./ <operationId> -h

# Make GET request
./ --host http://<hostname>:<port> --accept xml <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>

# Make GET request using arbitrary curl options (must be passed before <operationId>) to an SSL service using username:password
-k -sS --tlsv1.2 --host https://<hostname> -u <user>:<password> --accept xml <operationId> <queryParam1>=<value1> <header_key1>:<header_value2>

# Make POST request
$ echo '<body_content>' | --host <hostname> --content-type json <operationId> -

# Make POST request with simple JSON content, e.g.:
# {
# "key1": "value1",
# "key2": "value2",
# "key3": 23
# }
$ echo '<body_content>' | --host <hostname> --content-type json <operationId> key1==value1 key2=value2 key3:=23 -

# Make POST request with form data
$ --host <hostname> <operationId> key1:=value1 key2:=value2 key3:=23

# Preview the cURL command without actually executing it
$ --host http://<hostname>:<port> --dry-run <operationid>

```

## Docker image

You can easily create a Docker image containing a preconfigured environment
for using the REST Bash client including working autocompletion and short
welcome message with basic instructions, using the generated Dockerfile:

```shell
docker build -t my-rest-client .
docker run -it my-rest-client
```

By default you will be logged into a Zsh environment which has much more
advanced auto completion, but you can switch to Bash, where basic autocompletion
is also available.

## Shell completion

### Bash

The generated bash-completion script can be either directly loaded to the current Bash session using:

```shell
source .bash-completion
```

Alternatively, the script can be copied to the `/etc/bash-completion.d` (or on OSX with Homebrew to `/usr/local/etc/bash-completion.d`):

```shell
sudo cp .bash-completion /etc/bash-completion.d/
```

#### OS X

On OSX you might need to install bash-completion using Homebrew:

```shell
brew install bash-completion
```

and add the following to the `~/.bashrc`:

```shell
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
```

### Zsh

In Zsh, the generated `_` Zsh completion file must be copied to one of the folders under `$FPATH` variable.

## Documentation for API Endpoints

All URIs are relative to */api*

Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*DataApi* | [**dataSlugGet**](docs/DataApi.md#dataslugget) | **GET** /data/{slug} | Data in information list
*DataApi* | [**dataSlugSearchGet**](docs/DataApi.md#dataslugsearchget) | **GET** /data/{slug}/search | Search in information list
*ListsApi* | [**listsGet**](docs/ListsApi.md#listsget) | **GET** /lists | Available information lists
*ListsApi* | [**listsSlugGet**](docs/ListsApi.md#listsslugget) | **GET** /lists/{slug} | Information list


## Documentation For Models

- [Data](docs/Data.md)
- [List](docs/List.md)


## Documentation For Authorization


## ApiKeyAuth


- **Type**: API key
- **API key parameter name**: key
- **Location**: HTTP header

Loading

0 comments on commit 96fcd1b

Please sign in to comment.