Skip to content

Commit 4f5810d

Browse files
committed
automated codegen commit
1 parent 8549e8b commit 4f5810d

23 files changed

+897
-0
lines changed

openapi-generator-cli

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
####
3+
# Save as openapi-generator-cli on your PATH. chmod u+x. Enjoy.
4+
#
5+
# This script will query github on every invocation to pull the latest released version
6+
# of openapi-generator.
7+
#
8+
# If you want repeatable executions, you can explicitly set a version via
9+
# OPENAPI_GENERATOR_VERSION
10+
# e.g. (in Bash)
11+
# export OPENAPI_GENERATOR_VERSION=3.1.0
12+
# openapi-generator-cli.sh
13+
# or
14+
# OPENAPI_GENERATOR_VERSION=3.1.0 openapi-generator-cli.sh
15+
#
16+
# This is also helpful, for example, if you want want to evaluate a SNAPSHOT version.
17+
#
18+
# NOTE: Jars are downloaded on demand from maven into the same directory as this script
19+
# for every 'latest' version pulled from github. Consider putting this under its own directory.
20+
####
21+
set -o pipefail
22+
23+
for cmd in {mvn,jq,curl}; do
24+
if ! command -v ${cmd} > /dev/null; then
25+
>&2 echo "This script requires '${cmd}' to be installed."
26+
exit 1
27+
fi
28+
done
29+
30+
function latest.tag {
31+
local uri="https://api.github.com/repos/${1}/releases"
32+
local ver=$(curl -s ${uri} | jq -r 'first(.[]|select(.prerelease==false)).tag_name')
33+
if [[ $ver == v* ]]; then
34+
ver=${ver:1}
35+
fi
36+
echo $ver
37+
}
38+
39+
ghrepo=openapitools/openapi-generator
40+
groupid=org.openapitools
41+
artifactid=openapi-generator-cli
42+
ver=${OPENAPI_GENERATOR_VERSION:-$(latest.tag $ghrepo)}
43+
44+
jar=${artifactid}-${ver}.jar
45+
cachedir=${OPENAPI_GENERATOR_DOWNLOAD_CACHE_DIR}
46+
47+
DIR=${cachedir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
48+
49+
if [ ! -d "${DIR}" ]; then
50+
mkdir -p "${DIR}"
51+
fi
52+
53+
if [ ! -f ${DIR}/${jar} ]; then
54+
repo="central::default::https://repo1.maven.org/maven2/"
55+
if [[ ${ver} =~ ^.*-SNAPSHOT$ ]]; then
56+
repo="central::default::https://oss.sonatype.org/content/repositories/snapshots"
57+
fi
58+
mvn org.apache.maven.plugins:maven-dependency-plugin:2.9:get \
59+
-DremoteRepositories=${repo} \
60+
-Dartifact=${groupid}:${artifactid}:${ver} \
61+
-Dtransitive=false \
62+
-Ddest=${DIR}/${jar}
63+
fi
64+
65+
java -ea \
66+
${JAVA_OPTS} \
67+
-Xms512M \
68+
-Xmx1024M \
69+
-server \
70+
-jar ${DIR}/${jar} "$@"

openapi-generator-cli-5.2.0.jar

22.9 MB
Binary file not shown.

server/.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

server/.openapi-generator/FILES

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.openapi-generator-ignore
2+
Dockerfile
3+
README.md
4+
api/api.go
5+
api/api_notifications_api.go
6+
api/api_notifications_api_service.go
7+
api/helpers.go
8+
api/impl.go
9+
api/logger.go
10+
api/model_id.go
11+
api/model_notification_details.go
12+
api/model_notification_socket_message.go
13+
api/model_notification_socket_message_data.go
14+
api/model_ping_response.go
15+
api/openapi.yaml
16+
api/routers.go
17+
go.mod
18+
main.go

server/.openapi-generator/VERSION

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

server/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM golang:1.10 AS build
2+
WORKDIR /go/src
3+
COPY api ./api
4+
COPY main.go .
5+
6+
ENV CGO_ENABLED=0
7+
RUN go get -d -v ./...
8+
9+
RUN go build -a -installsuffix cgo -o api .
10+
11+
FROM scratch AS runtime
12+
COPY --from=build /go/src/api ./
13+
EXPOSE 8080/tcp
14+
ENTRYPOINT ["./api"]

server/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Go API Server for api
2+
3+
A notifications proof of concept API
4+
5+
## Overview
6+
This server was generated by the [openapi-generator]
7+
(https://openapi-generator.tech) project.
8+
By using the [OpenAPI-Spec](https://github.com/OAI/OpenAPI-Specification) from a remote server, you can easily generate a server stub.
9+
-
10+
11+
To see how to make this your own, look here:
12+
13+
[README](https://openapi-generator.tech)
14+
15+
- API version: 0.1.0
16+
- Build date: 2021-07-31T18:47:44.388Z[Etc/UTC]
17+
18+
19+
### Running the server
20+
To run the server, follow these simple steps:
21+
22+
```
23+
go run main.go
24+
```
25+
26+
To run the server in a docker container
27+
```
28+
docker build --network=host -t api .
29+
```
30+
31+
Once image is built use
32+
```
33+
docker run --rm -it api
34+
```
35+
36+

server/api/api.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* User API
3+
*
4+
* A notifications proof of concept API
5+
*
6+
* API version: 0.1.0
7+
* Contact: [email protected]
8+
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
9+
*/
10+
11+
package api
12+
13+
import (
14+
"context"
15+
"net/http"
16+
)
17+
18+
// NotificationsAPIApiRouter defines the required methods for binding the api requests to a responses for the NotificationsAPIApi
19+
// The NotificationsAPIApiRouter implementation should parse necessary information from the http request,
20+
// pass the data to a NotificationsAPIApiServicer to perform the required actions, then write the service results to the http response.
21+
type NotificationsAPIApiRouter interface {
22+
AddNotification(http.ResponseWriter, *http.Request)
23+
Ping(http.ResponseWriter, *http.Request)
24+
}
25+
26+
// NotificationsAPIApiServicer defines the api actions for the NotificationsAPIApi service
27+
// This interface intended to stay up to date with the openapi yaml used to generate it,
28+
// while the service implementation can ignored with the .openapi-generator-ignore file
29+
// and updated with the logic required for the API.
30+
type NotificationsAPIApiServicer interface {
31+
AddNotification(context.Context, NotificationDetails) (ImplResponse, error)
32+
Ping(context.Context) (ImplResponse, error)
33+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* User API
3+
*
4+
* A notifications proof of concept API
5+
*
6+
* API version: 0.1.0
7+
* Contact: [email protected]
8+
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
9+
*/
10+
11+
package api
12+
13+
import (
14+
"encoding/json"
15+
"net/http"
16+
"strings"
17+
)
18+
19+
// A NotificationsAPIApiController binds http requests to an api service and writes the service results to the http response
20+
type NotificationsAPIApiController struct {
21+
service NotificationsAPIApiServicer
22+
}
23+
24+
// NewNotificationsAPIApiController creates a default api controller
25+
func NewNotificationsAPIApiController(s NotificationsAPIApiServicer) Router {
26+
return &NotificationsAPIApiController{service: s}
27+
}
28+
29+
// Routes returns all of the api route for the NotificationsAPIApiController
30+
func (c *NotificationsAPIApiController) Routes() Routes {
31+
return Routes{
32+
{
33+
"AddNotification",
34+
strings.ToUpper("Put"),
35+
"/addNotification",
36+
c.AddNotification,
37+
},
38+
{
39+
"Ping",
40+
strings.ToUpper("Get"),
41+
"/ping",
42+
c.Ping,
43+
},
44+
}
45+
}
46+
47+
// AddNotification - adds a new notification
48+
func (c *NotificationsAPIApiController) AddNotification(w http.ResponseWriter, r *http.Request) {
49+
notificationDetails := &NotificationDetails{}
50+
if err := json.NewDecoder(r.Body).Decode(&notificationDetails); err != nil {
51+
w.WriteHeader(http.StatusBadRequest)
52+
return
53+
}
54+
result, err := c.service.AddNotification(r.Context(), *notificationDetails)
55+
// If an error occurred, encode the error with the status code
56+
if err != nil {
57+
EncodeJSONResponse(err.Error(), &result.Code, w)
58+
return
59+
}
60+
// If no error, encode the body and the result code
61+
EncodeJSONResponse(result.Body, &result.Code, w)
62+
63+
}
64+
65+
// Ping - tests this api
66+
func (c *NotificationsAPIApiController) Ping(w http.ResponseWriter, r *http.Request) {
67+
result, err := c.service.Ping(r.Context())
68+
// If an error occurred, encode the error with the status code
69+
if err != nil {
70+
EncodeJSONResponse(err.Error(), &result.Code, w)
71+
return
72+
}
73+
// If no error, encode the body and the result code
74+
EncodeJSONResponse(result.Body, &result.Code, w)
75+
76+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* User API
3+
*
4+
* A notifications proof of concept API
5+
*
6+
* API version: 0.1.0
7+
* Contact: [email protected]
8+
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
9+
*/
10+
11+
package api
12+
13+
import (
14+
"context"
15+
"errors"
16+
"net/http"
17+
)
18+
19+
// NotificationsAPIApiService is a service that implents the logic for the NotificationsAPIApiServicer
20+
// This service should implement the business logic for every endpoint for the NotificationsAPIApi API.
21+
// Include any external packages or services that will be required by this service.
22+
type NotificationsAPIApiService struct {
23+
}
24+
25+
// NewNotificationsAPIApiService creates a default api service
26+
func NewNotificationsAPIApiService() NotificationsAPIApiServicer {
27+
return &NotificationsAPIApiService{}
28+
}
29+
30+
// AddNotification - adds a new notification
31+
func (s *NotificationsAPIApiService) AddNotification(ctx context.Context, notificationDetails NotificationDetails) (ImplResponse, error) {
32+
// TODO - update AddNotification with the required logic for this service method.
33+
// Add api_notifications_api_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
34+
35+
//TODO: Uncomment the next line to return response Response(201, Id{}) or use other options such as http.Ok ...
36+
//return Response(201, Id{}), nil
37+
38+
//TODO: Uncomment the next line to return response Response(400, {}) or use other options such as http.Ok ...
39+
//return Response(400, nil),nil
40+
41+
//TODO: Uncomment the next line to return response Response(500, {}) or use other options such as http.Ok ...
42+
//return Response(500, nil),nil
43+
44+
return Response(http.StatusNotImplemented, nil), errors.New("AddNotification method not implemented")
45+
}
46+
47+
// Ping - tests this api
48+
func (s *NotificationsAPIApiService) Ping(ctx context.Context) (ImplResponse, error) {
49+
// TODO - update Ping with the required logic for this service method.
50+
// Add api_notifications_api_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
51+
52+
//TODO: Uncomment the next line to return response Response(201, PingResponse{}) or use other options such as http.Ok ...
53+
//return Response(201, PingResponse{}), nil
54+
55+
return Response(http.StatusNotImplemented, nil), errors.New("Ping method not implemented")
56+
}

0 commit comments

Comments
 (0)