Add swagger.json API ref and refactor code base 27/31127/2
authorShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Fri, 9 Feb 2018 22:16:04 +0000 (14:16 -0800)
committerShashank Kumar Shankar <shashank.kumar.shankar@intel.com>
Fri, 9 Feb 2018 22:20:42 +0000 (14:20 -0800)
This patch adds the API reference in the form of
swagger.json and refactors codebase to help in building
process using a Makefile.

Change-Id: I1ce11de6daf8defb563d8b6f319f05711057413b
Issue-ID: MUSIC-23
Signed-off-by: Shashank Kumar Shankar <shashank.kumar.shankar@intel.com>
15 files changed:
src/dkv/Gopkg.lock [moved from Gopkg.lock with 100% similarity]
src/dkv/Gopkg.toml [moved from Gopkg.toml with 100% similarity]
src/dkv/Makefile [new file with mode: 0644]
src/dkv/api/consulConnection.go [moved from api/consulConnection.go with 100% similarity]
src/dkv/api/consulConnection_test.go [moved from api/consulConnection_test.go with 100% similarity]
src/dkv/api/endpointViews.go [moved from api/endpointViews.go with 100% similarity]
src/dkv/api/endpointViews_test.go [moved from api/endpointViews_test.go with 100% similarity]
src/dkv/api/propertiesReader.go [moved from api/propertiesReader.go with 100% similarity]
src/dkv/api/propertiesReader_test.go [moved from api/propertiesReader_test.go with 97% similarity]
src/dkv/api/utils.go [moved from api/utils.go with 100% similarity]
src/dkv/api/utils_test.go [moved from api/utils_test.go with 97% similarity]
src/dkv/configurations/sampleAAIConfig.properties [moved from configurations/sampleAAIConfig.properties with 100% similarity]
src/dkv/configurations/sampleAPPCConfig.properties [moved from configurations/sampleAPPCConfig.properties with 100% similarity]
src/dkv/main.go [moved from main.go with 97% similarity]
swagger.json [new file with mode: 0644]

similarity index 100%
rename from Gopkg.lock
rename to src/dkv/Gopkg.lock
similarity index 100%
rename from Gopkg.toml
rename to src/dkv/Gopkg.toml
diff --git a/src/dkv/Makefile b/src/dkv/Makefile
new file mode 100644 (file)
index 0000000..5b7d979
--- /dev/null
@@ -0,0 +1,26 @@
+GOPATH := $(shell realpath "$(PWD)/../../")
+BINARY=dkv
+DEPENDENCIES := github.com/golang/dep/cmd/dep
+
+export GOPATH ...
+
+all: build test
+deploy: build test
+
+build: deps format
+       echo $(GOPATH)
+       $(GOPATH)/bin/dep ensure
+       go build -o $(GOPATH)/target/$(BINARY) -v main.go
+
+clean:
+       go clean
+       rm -f $(GOPATH)/target/$(BINARY)
+
+test:
+       go test -v ./api/...
+
+format:
+       go fmt ./api/...
+
+deps:
+       go get -u $(DEPENDENCIES)
similarity index 97%
rename from api/propertiesReader_test.go
rename to src/dkv/api/propertiesReader_test.go
index c564be5..342542a 100644 (file)
@@ -16,4 +16,4 @@
 
 package api
 
-// TODO(sshank)
\ No newline at end of file
+// TODO(sshank)
similarity index 100%
rename from api/utils.go
rename to src/dkv/api/utils.go
similarity index 97%
rename from api/utils_test.go
rename to src/dkv/api/utils_test.go
index c564be5..342542a 100644 (file)
@@ -16,4 +16,4 @@
 
 package api
 
-// TODO(sshank)
\ No newline at end of file
+// TODO(sshank)
similarity index 97%
rename from main.go
rename to src/dkv/main.go
index 59d9634..65a300a 100644 (file)
--- a/main.go
@@ -18,7 +18,7 @@ package main
 
 import (
        "github.com/gorilla/mux"
-       "distributed-kv-store/api"
+       "dkv/api"
        "log"
        "net/http"
 )
diff --git a/swagger.json b/swagger.json
new file mode 100644 (file)
index 0000000..364bcd3
--- /dev/null
@@ -0,0 +1,96 @@
+swagger: "2.0"
+info:
+  description: "API reference for Distributed Key Value store."
+  version: "1.0.0"
+  title: "API reference for Distributed Key Value store"
+  contact:
+    email: "shashank.kumar.shankar@intel.com"
+    url: "https://wiki.onap.org/display/DW/Distributed+KV+Store"
+  license:
+    name: "Apache 2.0"
+    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
+basePath: "/v1"
+schemes:
+- "http"
+paths:
+  /loadconfigs:
+    post:
+      tags:
+      - "load configuration"
+      summary: "Load Key Values by reading configs into Consul"
+      description: ""
+      consumes:
+      - "application/json"
+      produces:
+      - "application/json"
+      parameters:
+      - in: "body"
+        name: "body"
+        description: "Load configuration from file system to be added into Consul"
+        required: true
+        schema:
+          $ref: "#/definitions/LoadRequest"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/LoadResponse"
+  /getconfigs:
+    get:
+      tags:
+      - "get all keys"
+      summary: "Get all keys present in Consul."
+      description: "Returns a list of keys present in Consul."
+      produces:
+      - "application/json"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/Gets"
+  /getconfig/{key}:
+    get:
+      tags:
+      - "get single key"
+      summary: "Get value for specific key present in Consul."
+      description: "Returns a key and value present in Consul."
+      produces:
+      - "application/json"
+      parameters:
+      - name: "key"
+        in: "path"
+        description: "Key used to query"
+        required: true
+        type: "string"
+      responses:
+        200:
+          description: "successful operation"
+          schema:
+            $ref: "#/definitions/Get"
+definitions:
+  LoadRequest:
+    type: "object"
+    properties:
+      type:
+        $ref: "#/definitions/Type"
+  Type:
+    type: "object"
+    properties:
+      file_path:
+        type: "string"
+  LoadResponse:
+    type: "object"
+    properties:
+      response:
+        type: "string"
+  Gets:
+    type: "object"
+    properties:
+      response:
+        items:
+          type: "string"
+  Get:
+    type: "object"
+    properties:
+      response:
+        type: "string"