Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
VERSION ?= v0.3

docker:
docker build -t dhontecillas/liveapichecker:latest -t dhontecillas/liveapichecker:v0.1 .
docker build -t dhontecillas/liveapichecker:latest -t dhontecillas/liveapichecker:$(VERSION) .
docker image prune --filter label=stage=builder

dockeralpine:
docker build -f Dockerfile.alpine -t dhontecillas/liveapichecker-alpine:latest -t dhontecillas/liveapichecker-alpine:v0.1 .
docker build -f Dockerfile.alpine -t dhontecillas/liveapichecker-alpine:latest -t dhontecillas/liveapichecker-alpine:$(VERSION) .
docker image prune --filter label=stage=builder

dockerpushalpine:
docker push dhontecillas/liveapichecker-alpine:latest
docker push dhontecillas/liveapichecker-alpine:$(VERSION)
31 changes: 23 additions & 8 deletions cmd/liveapichecker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ func main() {
v.AutomaticEnv()
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

fmt.Printf("*******************************************\n")
fmt.Printf("* Live API Checker v0.3 *\n")
fmt.Printf("*******************************************\n")

fileName := v.GetString(OpenAPIFileKey)
if len(fileName) == 0 {
panic("cannot read OPENAPI_FILE filename")
panic(fmt.Sprintf("cannot read %d filename", OpenAPIFileKey))
}

forwardTo := v.GetString(ForwardToKey)
if len(forwardTo) == 0 {
panic("cannot read forward to")
panic(fmt.Sprintf("cannot read forward to config %s", ForwardToKey))
}
fmt.Printf("checking %s against %s\n", fileName, forwardTo)

Expand All @@ -50,9 +54,15 @@ func main() {
var dumpCovFn func()
outFile := v.GetString(ReportFileKey)
if len(outFile) > 0 {
fmt.Printf("\nReport filename: %s\n", outFile)
dumpCovFn = func() {
wd, _ := os.Getwd()
fmt.Printf("\ndumping results to %s (%s)\n", outFile, wd)
covChecker.DumpResultsToFile(outFile)
}
defer dumpCovFn()
} else {
fmt.Printf("\ncannot read report file name: %s\n", ReportFileKey)
}
var reportsSrv *http.Server
reportsAddress := v.GetString(ReportServerAddress)
Expand All @@ -79,13 +89,18 @@ func main() {
signal.Notify(sigChan, os.Interrupt)
<-sigChan

fmt.Printf("*******************************************\n")
fmt.Printf("* STARTING SHUTDOWN *\n")
fmt.Printf("* Live API Checker v0.3 *\n")
fmt.Printf("*******************************************\n")

go shutdownServer(reportsSrv)
shutdownServer(proxySrv)
shutdownServer(reportsSrv)

if dumpCovFn != nil {
fmt.Printf("post shutdown cleanup\n")
dumpCovFn()
}
fmt.Printf("*******************************************\n")
fmt.Printf("* SHUTDOWN FINISHED *\n")
fmt.Printf("* Live API Checker v0.3 *\n")
fmt.Printf("*******************************************\n")
}

func launchServer(hfn http.Handler, address string) *http.Server {
Expand All @@ -96,7 +111,7 @@ func launchServer(hfn http.Handler, address string) *http.Server {
go func() {
if err := srv.ListenAndServe(); err != nil {
if err == http.ErrServerClosed {
fmt.Printf("shutting down...\n")
fmt.Printf("shutting down... %#v\n", srv)
} else {
fmt.Printf("error %s\nSHUTTING DOWN", err.Error())
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ require (
github.com/go-openapi/spec v0.19.14
github.com/go-openapi/strfmt v0.19.11
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0 // indirect
)
109 changes: 109 additions & 0 deletions pkg/analyzer/analyzer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package analyzer_test

var (
testSwagger string = `
swagger: "2.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
host: petstore.swagger.io
basePath: /v1
schemes:
- http
consumes:
- application/json
produces:
- application/json
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
type: integer
format: int32
responses:
"200":
description: A paged array of pets
headers:
x-next:
type: string
description: A link to the next page of responses
schema:
$ref: '#/definitions/Pets'
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
type: string
responses:
"200":
description: Expected response to a valid request
schema:
$ref: '#/definitions/Pets'
default:
description: unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
Pet:
type: "object"
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: '#/definitions/Pet'
Error:
type: "object"
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
`
)
Loading