-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Change the api spec from swagger to openapi 3.0.0 - Adapt the makefile to use openapi generator - Adapt the petstore model, renamed to subscriber
- Loading branch information
Showing
34 changed files
with
600 additions
and
1,719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,8 +63,7 @@ test/**/*.tar | |
test/**/*.[wj]ar | ||
**/helm-build/ | ||
|
||
# bob | ||
.bob | ||
buildgen/ | ||
|
||
**/.vagrant/ | ||
**/.venv/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
blacklist: | ||
- GPL-2.0 | ||
|
||
whitelist: | ||
- Apache-2.0 | ||
- MIT | ||
- BSD-3-Clause | ||
|
||
exceptions: | ||
- github.com/jessevdk/go-flags | ||
- github.com/pmezard/go-difflib/difflib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
openapi: "3.0.0" | ||
info: | ||
version: 1.0.0 | ||
title: Madrush API | ||
license: | ||
name: MIT | ||
servers: | ||
- url: http://madrush.io/v1 | ||
paths: | ||
/subscribers: | ||
get: | ||
summary: List all subscribers | ||
operationId: listSubscribers | ||
tags: | ||
- subscribers | ||
parameters: | ||
- name: limit | ||
in: query | ||
description: How many items to return at one time (max 100) | ||
required: false | ||
schema: | ||
type: integer | ||
format: int32 | ||
responses: | ||
'200': | ||
description: A paged array of subscribers | ||
headers: | ||
x-next: | ||
description: A link to the next page of responses | ||
schema: | ||
type: string | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Subscribers" | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
post: | ||
summary: Create a subscriber | ||
operationId: createSubscriber | ||
tags: | ||
- subscriber | ||
responses: | ||
'201': | ||
description: Null response | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
/subscriber/{id}: | ||
get: | ||
summary: Info for a specific subscriber | ||
operationId: showSubscriberById | ||
tags: | ||
- subscriber | ||
parameters: | ||
- name: id | ||
in: path | ||
required: true | ||
description: The id of the subscriber to retrieve | ||
schema: | ||
type: string | ||
responses: | ||
'200': | ||
description: Expected response to a valid request | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Subscriber" | ||
default: | ||
description: unexpected error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/Error" | ||
components: | ||
schemas: | ||
Subscriber: | ||
type: object | ||
required: | ||
- id | ||
- name | ||
properties: | ||
id: | ||
type: integer | ||
format: int64 | ||
name: | ||
type: string | ||
tag: | ||
type: string | ||
Subscribers: | ||
type: array | ||
items: | ||
$ref: "#/components/schemas/Subscriber" | ||
Error: | ||
type: object | ||
required: | ||
- code | ||
- message | ||
properties: | ||
code: | ||
type: integer | ||
format: int32 | ||
message: | ||
type: string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,31 @@ | ||
/* | ||
* Madrush API | ||
* | ||
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/ennc0d3/madrush/pkg/swagger/server/restapi" | ||
"github.com/ennc0d3/madrush/pkg/swagger/server/restapi/operations" | ||
"github.com/go-openapi/loads" | ||
"github.com/go-openapi/runtime/middleware" | ||
openapi "github.com/ennc0d3/madrush/internal/api" | ||
) | ||
|
||
func serve() { | ||
// Initialize Swagger | ||
swaggerSpec, err := loads.Analyzed(restapi.SwaggerJSON, "") | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
api := operations.NewMadrushAPI(swaggerSpec) | ||
server := restapi.NewServer(api) | ||
defer func() { | ||
if err := server.Shutdown(); err != nil { | ||
log.Fatal(err) | ||
} | ||
}() | ||
server.Port = 8307 | ||
|
||
api.CheckHealthHandler = operations.CheckHealthHandlerFunc(Health) | ||
api.GetHelloUserHandler = operations.GetHelloUserHandlerFunc(GetHelloUser) | ||
|
||
// Start listening using having the handlers and port | ||
// already set up. | ||
if err := server.Serve(); err != nil { | ||
log.Fatalln(err) | ||
} | ||
func main() { | ||
log.Printf("Server started") | ||
|
||
} | ||
SubscriberApiService := openapi.NewSubscriberApiService() | ||
SubscriberApiController := openapi.NewSubscriberApiController(SubscriberApiService) | ||
|
||
//Health route returns OK | ||
func Health(operations.CheckHealthParams) middleware.Responder { | ||
return operations.NewCheckHealthOK().WithPayload("OK") | ||
} | ||
SubscribersApiService := openapi.NewSubscribersApiService() | ||
SubscribersApiController := openapi.NewSubscribersApiController(SubscribersApiService) | ||
|
||
//GetHelloUser returns Hello + your name | ||
func GetHelloUser(user operations.GetHelloUserParams) middleware.Responder { | ||
return operations.NewGetHelloUserOK().WithPayload("Hello " + user.User + "!") | ||
} | ||
router := openapi.NewRouter(SubscriberApiController, SubscribersApiController) | ||
|
||
func main() { | ||
serve() | ||
log.Fatal(http.ListenAndServe(":8080", router)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM golang:1.10 AS build | ||
WORKDIR /go/src | ||
COPY go ./go | ||
COPY main.go . | ||
|
||
ENV CGO_ENABLED=0 | ||
RUN go get -d -v ./... | ||
|
||
RUN go build -a -installsuffix cgo -o openapi . | ||
|
||
FROM scratch AS runtime | ||
COPY --from=build /go/src/openapi ./ | ||
EXPOSE 8080/tcp | ||
ENTRYPOINT ["./openapi"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.