Skip to content

Commit a1b026b

Browse files
authored
feat: openapi client and autogeneration script (#457)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent cca6b63 commit a1b026b

25 files changed

+3131
-0
lines changed

openapi-config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
enumClassPrefix: true
2+
generateInterfaces: true
3+
structPrefix: true
4+
isGoSubmodule: true

openapi.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate -i /local/docs/swagger.yaml --git-user-id blinklabs-io --git-repo-id adder -g go -o /local/openapi -c /local/openapi-config.yml
4+
make format golines
5+
cd openapi && go mod tidy

openapi/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2+
*.o
3+
*.a
4+
*.so
5+
6+
# Folders
7+
_obj
8+
_test
9+
10+
# Architecture specific extensions/prefixes
11+
*.[568vq]
12+
[568vq].out
13+
14+
*.cgo1.go
15+
*.cgo2.c
16+
_cgo_defun.c
17+
_cgo_gotypes.go
18+
_cgo_export.*
19+
20+
_testmain.go
21+
22+
*.exe
23+
*.test
24+
*.prof

openapi/.openapi-generator-ignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
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 OpenAPI Generator 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

openapi/.openapi-generator/FILES

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.gitignore
2+
.travis.yml
3+
README.md
4+
api/openapi.yaml
5+
api_default.go
6+
client.go
7+
configuration.go
8+
docs/DefaultAPI.md
9+
docs/PushErrorResponse.md
10+
docs/PushTokenRequest.md
11+
docs/PushTokenResponse.md
12+
git_push.sh
13+
go.mod
14+
go.sum
15+
model_push_error_response.go
16+
model_push_token_request.go
17+
model_push_token_response.go
18+
response.go
19+
utils.go

openapi/.openapi-generator/VERSION

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

openapi/.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: go
2+
3+
install:
4+
- go get -d -v .
5+
6+
script:
7+
- go build -v ./
8+

openapi/README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Go API client for openapi
2+
3+
Adder API
4+
5+
## Overview
6+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.
7+
8+
- API version: v1
9+
- Package version: 1.0.0
10+
- Generator version: 7.14.0
11+
- Build package: org.openapitools.codegen.languages.GoClientCodegen
12+
For more information, please visit [https://blinklabs.io](https://blinklabs.io)
13+
14+
## Installation
15+
16+
Install the following dependencies:
17+
18+
```sh
19+
go get github.com/stretchr/testify/assert
20+
go get golang.org/x/net/context
21+
```
22+
23+
Put the package under your project folder and add the following in import:
24+
25+
```go
26+
import openapi "github.com/blinklabs-io/cardano-node-api/openapi"
27+
```
28+
29+
To use a proxy, set the environment variable `HTTP_PROXY`:
30+
31+
```go
32+
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
33+
```
34+
35+
## Configuration of Server URL
36+
37+
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
38+
39+
### Select Server Configuration
40+
41+
For using other server than the one defined on index 0 set context value `openapi.ContextServerIndex` of type `int`.
42+
43+
```go
44+
ctx := context.WithValue(context.Background(), openapi.ContextServerIndex, 1)
45+
```
46+
47+
### Templated Server URL
48+
49+
Templated server URL is formatted using default variables from configuration or from context value `openapi.ContextServerVariables` of type `map[string]string`.
50+
51+
```go
52+
ctx := context.WithValue(context.Background(), openapi.ContextServerVariables, map[string]string{
53+
"basePath": "v2",
54+
})
55+
```
56+
57+
Note, enum values are always validated and all unused variables are silently ignored.
58+
59+
### URLs Configuration per Operation
60+
61+
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
62+
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
63+
Similar rules for overriding default operation server index and variables applies by using `openapi.ContextOperationServerIndices` and `openapi.ContextOperationServerVariables` context maps.
64+
65+
```go
66+
ctx := context.WithValue(context.Background(), openapi.ContextOperationServerIndices, map[string]int{
67+
"{classname}Service.{nickname}": 2,
68+
})
69+
ctx = context.WithValue(context.Background(), openapi.ContextOperationServerVariables, map[string]map[string]string{
70+
"{classname}Service.{nickname}": {
71+
"port": "8443",
72+
},
73+
})
74+
```
75+
76+
## Documentation for API Endpoints
77+
78+
All URIs are relative to */v1*
79+
80+
Class | Method | HTTP request | Description
81+
------------ | ------------- | ------------- | -------------
82+
*DefaultAPI* | [**FcmPost**](docs/DefaultAPI.md#fcmpost) | **Post** /fcm | Store FCM Token
83+
*DefaultAPI* | [**FcmTokenDelete**](docs/DefaultAPI.md#fcmtokendelete) | **Delete** /fcm/{token} | Delete FCM Token
84+
*DefaultAPI* | [**FcmTokenGet**](docs/DefaultAPI.md#fcmtokenget) | **Get** /fcm/{token} | Get FCM Token
85+
86+
87+
## Documentation For Models
88+
89+
- [PushErrorResponse](docs/PushErrorResponse.md)
90+
- [PushTokenRequest](docs/PushTokenRequest.md)
91+
- [PushTokenResponse](docs/PushTokenResponse.md)
92+
93+
94+
## Documentation For Authorization
95+
96+
Endpoints do not require authorization.
97+
98+
99+
## Documentation for Utility Methods
100+
101+
Due to the fact that model structure members are all pointers, this package contains
102+
a number of utility functions to easily obtain pointers to values of basic types.
103+
Each of these functions takes a value of the given basic type and returns a pointer to it:
104+
105+
* `PtrBool`
106+
* `PtrInt`
107+
* `PtrInt32`
108+
* `PtrInt64`
109+
* `PtrFloat`
110+
* `PtrFloat32`
111+
* `PtrFloat64`
112+
* `PtrString`
113+
* `PtrTime`
114+
115+
## Author
116+
117+
118+

openapi/api/openapi.yaml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
openapi: 3.0.1
2+
info:
3+
contact:
4+
5+
name: Blink Labs
6+
url: https://blinklabs.io
7+
description: Adder API
8+
license:
9+
name: Apache 2.0
10+
url: http://www.apache.org/licenses/LICENSE-2.0.html
11+
title: Adder API
12+
version: v1
13+
servers:
14+
- url: /v1
15+
paths:
16+
/fcm:
17+
post:
18+
description: Store a new FCM token
19+
requestBody:
20+
content:
21+
application/json:
22+
schema:
23+
$ref: "#/components/schemas/push.TokenRequest"
24+
description: FCM Token Request
25+
required: true
26+
responses:
27+
"201":
28+
content:
29+
application/json:
30+
schema:
31+
type: string
32+
description: Created
33+
"400":
34+
content:
35+
application/json:
36+
schema:
37+
$ref: "#/components/schemas/push.ErrorResponse"
38+
description: Bad Request
39+
summary: Store FCM Token
40+
x-codegen-request-body-name: body
41+
/fcm/{token}:
42+
delete:
43+
description: Delete an FCM token by its value
44+
parameters:
45+
- description: FCM Token
46+
in: path
47+
name: token
48+
required: true
49+
schema:
50+
type: string
51+
responses:
52+
"204":
53+
content:
54+
application/json:
55+
schema:
56+
type: string
57+
description: No Content
58+
"404":
59+
content:
60+
application/json:
61+
schema:
62+
$ref: "#/components/schemas/push.ErrorResponse"
63+
description: Not Found
64+
summary: Delete FCM Token
65+
get:
66+
description: Get an FCM token by its value
67+
parameters:
68+
- description: FCM Token
69+
in: path
70+
name: token
71+
required: true
72+
schema:
73+
type: string
74+
responses:
75+
"200":
76+
content:
77+
application/json:
78+
schema:
79+
$ref: "#/components/schemas/push.TokenResponse"
80+
description: OK
81+
"404":
82+
content:
83+
application/json:
84+
schema:
85+
$ref: "#/components/schemas/push.ErrorResponse"
86+
description: Not Found
87+
summary: Get FCM Token
88+
components:
89+
schemas:
90+
push.ErrorResponse:
91+
example:
92+
error: error
93+
properties:
94+
error:
95+
type: string
96+
type: object
97+
push.TokenRequest:
98+
properties:
99+
fcmToken:
100+
type: string
101+
required:
102+
- fcmToken
103+
type: object
104+
push.TokenResponse:
105+
example:
106+
fcmToken: fcmToken
107+
properties:
108+
fcmToken:
109+
type: string
110+
type: object
111+
x-original-swagger-version: "2.0"

0 commit comments

Comments
 (0)