Improve Swagger DMaaP Mediator Producer 90/7590/2
authorelinuxhenrik <henrik.b.andersson@est.tech>
Wed, 19 Jan 2022 15:51:36 +0000 (16:51 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 20 Jan 2022 09:36:45 +0000 (10:36 +0100)
Issue-ID: NONRTRIC-702
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
Change-Id: Ib0a1c5c31b21b14174b48af9c0b577014cb88e36

12 files changed:
dmaap-mediator-producer/api/docs.go [moved from dmaap-mediator-producer/docs/docs.go with 67% similarity]
dmaap-mediator-producer/api/swagger.json [moved from dmaap-mediator-producer/docs/swagger.json with 62% similarity]
dmaap-mediator-producer/api/swagger.yaml [moved from dmaap-mediator-producer/docs/swagger.yaml with 55% similarity]
dmaap-mediator-producer/generate_swagger_docs.sh
dmaap-mediator-producer/go.mod
dmaap-mediator-producer/internal/jobs/jobs.go
dmaap-mediator-producer/internal/server/server.go
dmaap-mediator-producer/internal/server/server_test.go
dmaap-mediator-producer/main.go
dmaap-mediator-producer/main_test.go
docs/api-docs.rst
docs/conf.py

similarity index 67%
rename from dmaap-mediator-producer/docs/docs.go
rename to dmaap-mediator-producer/api/docs.go
index 823df03..dbfc42b 100644 (file)
@@ -1,6 +1,6 @@
-// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
+// Package api GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
 // This file was generated by swaggo/swag
-package docs
+package api
 
 import (
        "bytes"
@@ -53,9 +53,15 @@ var doc = `{
                         "description": ""
                     },
                     "400": {
-                        "description": "Bad Request",
+                        "description": "Problem as defined in https://tools.ietf.org/html/rfc7807",
                         "schema": {
-                            "type": "string"
+                            "$ref": "#/definitions/ErrorInfo"
+                        },
+                        "headers": {
+                            "Content-Type": {
+                                "type": "string",
+                                "description": "application/problem+json"
+                            }
                         }
                     }
                 }
@@ -64,13 +70,19 @@ var doc = `{
         "/health_check": {
             "get": {
                 "description": "Get the status of the producer. Will show if the producer has registered in ICS.",
+                "produces": [
+                    "application/json"
+                ],
                 "tags": [
                     "Data producer (callbacks)"
                 ],
                 "summary": "Get status",
                 "responses": {
                     "200": {
-                        "description": ""
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/"
+                        }
                     }
                 }
             }
@@ -92,7 +104,7 @@ var doc = `{
                         "in": "body",
                         "required": true,
                         "schema": {
-                            "$ref": "#/definitions/jobs.JobInfo"
+                            "$ref": "#/definitions/JobInfo"
                         }
                     }
                 ],
@@ -101,9 +113,15 @@ var doc = `{
                         "description": ""
                     },
                     "400": {
-                        "description": "Bad Request",
+                        "description": "Problem as defined in https://tools.ietf.org/html/rfc7807",
                         "schema": {
-                            "type": "string"
+                            "$ref": "#/definitions/ErrorInfo"
+                        },
+                        "headers": {
+                            "Content-Type": {
+                                "type": "string",
+                                "description": "application/problem+json"
+                            }
                         }
                     }
                 }
@@ -148,7 +166,17 @@ var doc = `{
         }
     },
     "definitions": {
-        "jobs.BufferTimeout": {
+        "": {
+            "type": "object",
+            "properties": {
+                "registeredStatus": {
+                    "description": "The registration status of the producer in Information Coordinator Service. Either ` + "`" + `registered` + "`" + ` or ` + "`" + `not registered` + "`" + `",
+                    "type": "string",
+                    "example": "registered"
+                }
+            }
+        },
+        "BufferTimeout": {
             "type": "object",
             "properties": {
                 "maxSize": {
@@ -159,11 +187,38 @@ var doc = `{
                 }
             }
         },
-        "jobs.JobInfo": {
+        "ErrorInfo": {
+            "type": "object",
+            "properties": {
+                "detail": {
+                    "description": "A human-readable explanation specific to this occurrence of the problem.",
+                    "type": "string",
+                    "example": "Info job type not found"
+                },
+                "instance": {
+                    "description": "A URI reference that identifies the specific occurrence of the problem.",
+                    "type": "string"
+                },
+                "status": {
+                    "description": "The HTTP status code generated by the origin server for this occurrence of the problem.",
+                    "type": "integer",
+                    "example": 400
+                },
+                "title": {
+                    "description": "A short, human-readable summary of the problem type.",
+                    "type": "string"
+                },
+                "type": {
+                    "description": "A URI reference that identifies the problem type.",
+                    "type": "string"
+                }
+            }
+        },
+        "JobInfo": {
             "type": "object",
             "properties": {
                 "info_job_data": {
-                    "$ref": "#/definitions/jobs.Parameters"
+                    "$ref": "#/definitions/Parameters"
                 },
                 "info_job_identity": {
                     "type": "string"
@@ -182,11 +237,11 @@ var doc = `{
                 }
             }
         },
-        "jobs.Parameters": {
+        "Parameters": {
             "type": "object",
             "properties": {
                 "bufferTimeout": {
-                    "$ref": "#/definitions/jobs.BufferTimeout"
+                    "$ref": "#/definitions/BufferTimeout"
                 }
             }
         }
similarity index 62%
rename from dmaap-mediator-producer/docs/swagger.json
rename to dmaap-mediator-producer/api/swagger.json
index 11e030e..8910022 100644 (file)
                         "description": ""
                     },
                     "400": {
-                        "description": "Bad Request",
+                        "description": "Problem as defined in https://tools.ietf.org/html/rfc7807",
                         "schema": {
-                            "type": "string"
+                            "$ref": "#/definitions/ErrorInfo"
+                        },
+                        "headers": {
+                            "Content-Type": {
+                                "type": "string",
+                                "description": "application/problem+json"
+                            }
                         }
                     }
                 }
         "/health_check": {
             "get": {
                 "description": "Get the status of the producer. Will show if the producer has registered in ICS.",
+                "produces": [
+                    "application/json"
+                ],
                 "tags": [
                     "Data producer (callbacks)"
                 ],
                 "summary": "Get status",
                 "responses": {
                     "200": {
-                        "description": ""
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/"
+                        }
                     }
                 }
             }
@@ -75,7 +87,7 @@
                         "in": "body",
                         "required": true,
                         "schema": {
-                            "$ref": "#/definitions/jobs.JobInfo"
+                            "$ref": "#/definitions/JobInfo"
                         }
                     }
                 ],
                         "description": ""
                     },
                     "400": {
-                        "description": "Bad Request",
+                        "description": "Problem as defined in https://tools.ietf.org/html/rfc7807",
                         "schema": {
-                            "type": "string"
+                            "$ref": "#/definitions/ErrorInfo"
+                        },
+                        "headers": {
+                            "Content-Type": {
+                                "type": "string",
+                                "description": "application/problem+json"
+                            }
                         }
                     }
                 }
         }
     },
     "definitions": {
-        "jobs.BufferTimeout": {
+        "": {
+            "type": "object",
+            "properties": {
+                "registeredStatus": {
+                    "description": "The registration status of the producer in Information Coordinator Service. Either `registered` or `not registered`",
+                    "type": "string",
+                    "example": "registered"
+                }
+            }
+        },
+        "BufferTimeout": {
             "type": "object",
             "properties": {
                 "maxSize": {
                 }
             }
         },
-        "jobs.JobInfo": {
+        "ErrorInfo": {
+            "type": "object",
+            "properties": {
+                "detail": {
+                    "description": "A human-readable explanation specific to this occurrence of the problem.",
+                    "type": "string",
+                    "example": "Info job type not found"
+                },
+                "instance": {
+                    "description": "A URI reference that identifies the specific occurrence of the problem.",
+                    "type": "string"
+                },
+                "status": {
+                    "description": "The HTTP status code generated by the origin server for this occurrence of the problem.",
+                    "type": "integer",
+                    "example": 400
+                },
+                "title": {
+                    "description": "A short, human-readable summary of the problem type.",
+                    "type": "string"
+                },
+                "type": {
+                    "description": "A URI reference that identifies the problem type.",
+                    "type": "string"
+                }
+            }
+        },
+        "JobInfo": {
             "type": "object",
             "properties": {
                 "info_job_data": {
-                    "$ref": "#/definitions/jobs.Parameters"
+                    "$ref": "#/definitions/Parameters"
                 },
                 "info_job_identity": {
                     "type": "string"
                 }
             }
         },
-        "jobs.Parameters": {
+        "Parameters": {
             "type": "object",
             "properties": {
                 "bufferTimeout": {
-                    "$ref": "#/definitions/jobs.BufferTimeout"
+                    "$ref": "#/definitions/BufferTimeout"
                 }
             }
         }
similarity index 55%
rename from dmaap-mediator-producer/docs/swagger.yaml
rename to dmaap-mediator-producer/api/swagger.yaml
index 501b062..adf70a8 100644 (file)
@@ -1,15 +1,46 @@
 definitions:
-  jobs.BufferTimeout:
+  "":
+    properties:
+      registeredStatus:
+        description: The registration status of the producer in Information Coordinator
+          Service. Either `registered` or `not registered`
+        example: registered
+        type: string
+    type: object
+  BufferTimeout:
     properties:
       maxSize:
         type: integer
       maxTimeMiliseconds:
         type: integer
     type: object
-  jobs.JobInfo:
+  ErrorInfo:
+    properties:
+      detail:
+        description: A human-readable explanation specific to this occurrence of the
+          problem.
+        example: Info job type not found
+        type: string
+      instance:
+        description: A URI reference that identifies the specific occurrence of the
+          problem.
+        type: string
+      status:
+        description: The HTTP status code generated by the origin server for this
+          occurrence of the problem.
+        example: 400
+        type: integer
+      title:
+        description: A short, human-readable summary of the problem type.
+        type: string
+      type:
+        description: A URI reference that identifies the problem type.
+        type: string
+    type: object
+  JobInfo:
     properties:
       info_job_data:
-        $ref: '#/definitions/jobs.Parameters'
+        $ref: '#/definitions/Parameters'
       info_job_identity:
         type: string
       info_type_identity:
@@ -21,10 +52,10 @@ definitions:
       target_uri:
         type: string
     type: object
-  jobs.Parameters:
+  Parameters:
     properties:
       bufferTimeout:
-        $ref: '#/definitions/jobs.BufferTimeout'
+        $ref: '#/definitions/BufferTimeout'
     type: object
 info:
   contact: {}
@@ -51,9 +82,13 @@ paths:
         "200":
           description: ""
         "400":
-          description: Bad Request
+          description: Problem as defined in https://tools.ietf.org/html/rfc7807
+          headers:
+            Content-Type:
+              description: application/problem+json
+              type: string
           schema:
-            type: string
+            $ref: '#/definitions/ErrorInfo'
       summary: Set log level
       tags:
       - Admin
@@ -61,9 +96,13 @@ paths:
     get:
       description: Get the status of the producer. Will show if the producer has registered
         in ICS.
+      produces:
+      - application/json
       responses:
         "200":
-          description: ""
+          description: OK
+          schema:
+            $ref: '#/definitions/'
       summary: Get status
       tags:
       - Data producer (callbacks)
@@ -78,14 +117,18 @@ paths:
         name: user
         required: true
         schema:
-          $ref: '#/definitions/jobs.JobInfo'
+          $ref: '#/definitions/JobInfo'
       responses:
         "200":
           description: ""
         "400":
-          description: Bad Request
+          description: Problem as defined in https://tools.ietf.org/html/rfc7807
+          headers:
+            Content-Type:
+              description: application/problem+json
+              type: string
           schema:
-            type: string
+            $ref: '#/definitions/ErrorInfo'
       summary: Add info job
       tags:
       - Data producer (callbacks)
index 63bc20d..8a13f30 100755 (executable)
@@ -17,4 +17,6 @@
 #
 ##############################################################################
 
-swag init
\ No newline at end of file
+go get -u github.com/swaggo/swag/cmd/swag
+swag init --output api
+swag fmt
\ No newline at end of file
index 1a03578..ea7b361 100644 (file)
@@ -3,17 +3,19 @@ module oransc.org/nonrtric/dmaapmediatorproducer
 go 1.17
 
 require (
+       github.com/confluentinc/confluent-kafka-go v1.8.2
        github.com/gorilla/mux v1.8.0
        github.com/hashicorp/go-retryablehttp v0.7.0
        github.com/sirupsen/logrus v1.8.1
        github.com/stretchr/testify v1.7.0
+       github.com/swaggo/http-swagger v1.1.2
+       github.com/swaggo/swag v1.7.8
 )
 
 require (
        github.com/KyleBanks/depth v1.2.1 // indirect
        github.com/PuerkitoBio/purell v1.1.1 // indirect
        github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
-       github.com/confluentinc/confluent-kafka-go v1.8.2 // indirect
        github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
        github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/ghodss/yaml v1.0.0 // indirect
@@ -29,8 +31,6 @@ require (
        github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
        github.com/stretchr/objx v0.1.0 // indirect
        github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect
-       github.com/swaggo/http-swagger v1.1.2 // indirect
-       github.com/swaggo/swag v1.7.8 // indirect
        github.com/urfave/cli/v2 v2.3.0 // indirect
        golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
        golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
index c84e277..86bfe05 100644 (file)
@@ -51,7 +51,7 @@ type JobInfo struct {
        InfoJobData      Parameters `json:"info_job_data"`
        InfoTypeIdentity string     `json:"info_type_identity"`
        sourceType       sourceType
-}
+} // @name JobInfo
 
 type JobTypesManager interface {
        LoadTypesFromConfiguration(types []config.TypeDefinition) []config.TypeDefinition
@@ -327,12 +327,12 @@ func newJob(j JobInfo, c restclient.HTTPClient) job {
 
 type Parameters struct {
        BufferTimeout BufferTimeout `json:"bufferTimeout"`
-}
+} // @name Parameters
 
 type BufferTimeout struct {
        MaxSize            int   `json:"maxSize"`
        MaxTimeMiliseconds int64 `json:"maxTimeMiliseconds"`
-}
+} // @name BufferTimeout
 
 func (j *job) start() {
        if j.isJobBuffered() {
index bc4a1da..46bc2a2 100644 (file)
@@ -38,6 +38,19 @@ const deleteJobPath = AddJobPath + "/{" + jobIdToken + "}"
 const logLevelToken = "level"
 const logAdminPath = "/admin/log"
 
+type ErrorInfo struct {
+       // A URI reference that identifies the problem type.
+       Type string `json:"type" swaggertype:"string"`
+       // A short, human-readable summary of the problem type.
+       Title string `json:"title" swaggertype:"string"`
+       // The HTTP status code generated by the origin server for this occurrence of the problem.
+       Status int `json:"status" swaggertype:"integer" example:"400"`
+       // A human-readable explanation specific to this occurrence of the problem.
+       Detail string `json:"detail" swaggertype:"string" example:"Info job type not found"`
+       // A URI reference that identifies the specific occurrence of the problem.
+       Instance string `json:"instance" swaggertype:"string"`
+} // @name ErrorInfo
+
 type ProducerCallbackHandler struct {
        jobsManager jobs.JobsManager
 }
@@ -66,21 +79,23 @@ func NewRouter(jm jobs.JobsManager, hcf func(http.ResponseWriter, *http.Request)
 // @Accept       json
 // @Param        user  body  jobs.JobInfo  true  "Info job data"
 // @Success      200
-// @Failure      400  {string}  Cause  of  error
+// @Failure      400  {object}  ErrorInfo     "Problem as defined in https://tools.ietf.org/html/rfc7807"
+// @Header       400  {string}  Content-Type  "application/problem+json"
 // @Router       /info_job [post]
 func (h *ProducerCallbackHandler) addInfoJobHandler(w http.ResponseWriter, r *http.Request) {
        b, readErr := ioutil.ReadAll(r.Body)
        if readErr != nil {
-               http.Error(w, fmt.Sprintf("Unable to read body due to: %v", readErr), http.StatusBadRequest)
+               returnError(fmt.Sprintf("Unable to read body due to: %v", readErr), w)
                return
        }
        jobInfo := jobs.JobInfo{}
        if unmarshalErr := json.Unmarshal(b, &jobInfo); unmarshalErr != nil {
-               http.Error(w, fmt.Sprintf("Invalid json body. Cause: %v", unmarshalErr), http.StatusBadRequest)
+               returnError(fmt.Sprintf("Invalid json body. Cause: %v", unmarshalErr), w)
                return
        }
        if err := h.jobsManager.AddJobFromRESTCall(jobInfo); err != nil {
-               http.Error(w, fmt.Sprintf("Invalid job info. Cause: %v", err), http.StatusBadRequest)
+               returnError(fmt.Sprintf("Invalid job info. Cause: %v", err), w)
+               return
        }
 }
 
@@ -106,7 +121,8 @@ func (h *ProducerCallbackHandler) deleteInfoJobHandler(w http.ResponseWriter, r
 // @Tags         Admin
 // @Param        level  query  string  false  "string enums"  Enums(Error, Warn, Info, Debug)
 // @Success      200
-// @Failure      400  {string}  Cause  of  error
+// @Failure      400  {object}  ErrorInfo     "Problem as defined in https://tools.ietf.org/html/rfc7807"
+// @Header       400  {string}  Content-Type  "application/problem+json"
 // @Router       /admin/log [put]
 func (h *ProducerCallbackHandler) setLogLevel(w http.ResponseWriter, r *http.Request) {
        query := r.URL.Query()
@@ -114,7 +130,7 @@ func (h *ProducerCallbackHandler) setLogLevel(w http.ResponseWriter, r *http.Req
        if loglevel, err := log.ParseLevel(logLevelStr); err == nil {
                log.SetLevel(loglevel)
        } else {
-               http.Error(w, fmt.Sprintf("Invalid log level: %v. Log level will not be changed!", logLevelStr), http.StatusBadRequest)
+               returnError(fmt.Sprintf("Invalid log level: %v. Log level will not be changed!", logLevelStr), w)
                return
        }
 }
@@ -130,3 +146,13 @@ type methodNotAllowedHandler struct{}
 func (h *methodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
        http.Error(w, "Method is not supported.", http.StatusMethodNotAllowed)
 }
+
+func returnError(msg string, w http.ResponseWriter) {
+       errInfo := ErrorInfo{
+               Status: http.StatusBadRequest,
+               Detail: msg,
+       }
+       w.Header().Add("Content-Type", "application/problem+json")
+       w.WriteHeader(http.StatusBadRequest)
+       json.NewEncoder(w).Encode(errInfo)
+}
index 6fe4d7a..dbe503d 100644 (file)
@@ -96,10 +96,10 @@ func TestAddInfoJobToJobsHandler(t *testing.T) {
                mockReturn error
        }
        tests := []struct {
-               name         string
-               args         args
-               wantedStatus int
-               wantedBody   string
+               name            string
+               args            args
+               wantedStatus    int
+               wantedErrorInfo *ErrorInfo
        }{
                {
                        name: "AddInfoJobToJobsHandler with correct job, should return OK",
@@ -124,7 +124,10 @@ func TestAddInfoJobToJobsHandler(t *testing.T) {
                                mockReturn: errors.New("error"),
                        },
                        wantedStatus: http.StatusBadRequest,
-                       wantedBody:   "Invalid job info. Cause: error",
+                       wantedErrorInfo: &ErrorInfo{
+                               Status: http.StatusBadRequest,
+                               Detail: "Invalid job info. Cause: error",
+                       },
                },
        }
        for _, tt := range tests {
@@ -141,7 +144,16 @@ func TestAddInfoJobToJobsHandler(t *testing.T) {
                        handler.ServeHTTP(responseRecorder, r)
 
                        assertions.Equal(tt.wantedStatus, responseRecorder.Code, tt.name)
-                       assertions.Contains(responseRecorder.Body.String(), tt.wantedBody, tt.name)
+                       if tt.wantedErrorInfo != nil {
+                               var actualErrInfo ErrorInfo
+                               err := json.Unmarshal(getBody(responseRecorder, t), &actualErrInfo)
+                               if err != nil {
+                                       t.Error("Unable to unmarshal error body", err)
+                                       t.Fail()
+                               }
+                               assertions.Equal(*tt.wantedErrorInfo, actualErrInfo, tt.name)
+                               assertions.Equal("application/problem+json", responseRecorder.Result().Header.Get("Content-Type"))
+                       }
                        jobsHandlerMock.AssertCalled(t, "AddJobFromRESTCall", tt.args.job)
                })
        }
@@ -172,10 +184,10 @@ func TestSetLogLevel(t *testing.T) {
                logLevel string
        }
        tests := []struct {
-               name         string
-               args         args
-               wantedStatus int
-               wantedBody   string
+               name            string
+               args            args
+               wantedStatus    int
+               wantedErrorInfo *ErrorInfo
        }{
                {
                        name: "Set to valid log level, should return OK",
@@ -190,7 +202,10 @@ func TestSetLogLevel(t *testing.T) {
                                logLevel: "bad",
                        },
                        wantedStatus: http.StatusBadRequest,
-                       wantedBody:   "Invalid log level: bad",
+                       wantedErrorInfo: &ErrorInfo{
+                               Detail: "Invalid log level: bad. Log level will not be changed!",
+                               Status: http.StatusBadRequest,
+                       },
                },
        }
        for _, tt := range tests {
@@ -204,7 +219,16 @@ func TestSetLogLevel(t *testing.T) {
                        handler.ServeHTTP(responseRecorder, r)
 
                        assertions.Equal(tt.wantedStatus, responseRecorder.Code, tt.name)
-                       assertions.Contains(responseRecorder.Body.String(), tt.wantedBody, tt.name)
+                       if tt.wantedErrorInfo != nil {
+                               var actualErrInfo ErrorInfo
+                               err := json.Unmarshal(getBody(responseRecorder, t), &actualErrInfo)
+                               if err != nil {
+                                       t.Error("Unable to unmarshal error body", err)
+                                       t.Fail()
+                               }
+                               assertions.Equal(*tt.wantedErrorInfo, actualErrInfo, tt.name)
+                               assertions.Equal("application/problem+json", responseRecorder.Result().Header.Get("Content-Type"))
+                       }
                })
        }
 }
@@ -222,3 +246,12 @@ func newRequest(method string, url string, jobInfo *jobs.JobInfo, t *testing.T)
                return nil
        }
 }
+
+func getBody(responseRecorder *httptest.ResponseRecorder, t *testing.T) []byte {
+       buf := new(bytes.Buffer)
+       if _, err := buf.ReadFrom(responseRecorder.Body); err != nil {
+               t.Error("Unable to read error body", err)
+               t.Fail()
+       }
+       return buf.Bytes()
+}
index ab28c6b..65a84a2 100644 (file)
@@ -22,13 +22,14 @@ package main
 
 import (
        "crypto/tls"
+       "encoding/json"
        "fmt"
        "net/http"
        "time"
 
        "github.com/gorilla/mux"
        log "github.com/sirupsen/logrus"
-       _ "oransc.org/nonrtric/dmaapmediatorproducer/docs"
+       _ "oransc.org/nonrtric/dmaapmediatorproducer/api"
        "oransc.org/nonrtric/dmaapmediatorproducer/internal/config"
        "oransc.org/nonrtric/dmaapmediatorproducer/internal/jobs"
        "oransc.org/nonrtric/dmaapmediatorproducer/internal/kafkaclient"
@@ -45,8 +46,8 @@ func init() {
        configuration = config.New()
 }
 
-// @title DMaaP Mediator Producer
-// @version 1.1.0
+// @title    DMaaP Mediator Producer
+// @version  1.1.0
 
 // @license.name  Apache 2.0
 // @license.url   http://www.apache.org/licenses/LICENSE-2.0.html
@@ -130,24 +131,32 @@ func startCallbackServer(jobsManager jobs.JobsManager, callbackAddress string) {
        }
 }
 
-// @Summary Get status
-// @Description Get the status of the producer. Will show if the producer has registered in ICS.
-// @Tags Data producer (callbacks)
-// @Success 200
-// @Router /health_check [get]
+type ProducerStatus struct {
+       // The registration status of the producer in Information Coordinator Service. Either `registered` or `not registered`
+       RegisteredStatus string `json:"registeredStatus" swaggertype:"string" example:"registered"`
+} // @name  ProducerStatus
+
+// @Summary      Get status
+// @Description  Get the status of the producer. Will show if the producer has registered in ICS.
+// @Tags         Data producer (callbacks)
+// @Produce      json
+// @Success      200  {object}  ProducerStatus
+// @Router       /health_check [get]
 func statusHandler(w http.ResponseWriter, r *http.Request) {
-       registeredStatus := "not registered"
+       status := ProducerStatus{
+               RegisteredStatus: "not registered",
+       }
        if registered {
-               registeredStatus = "registered"
+               status.RegisteredStatus = "registered"
        }
-       fmt.Fprintf(w, `{"status": "%v"}`, registeredStatus)
+       json.NewEncoder(w).Encode(status)
 }
 
-// @Summary Get Swagger Documentation
-// @Description Get the Swagger API documentation for the producer.
-// @Tags Admin
-// @Success 200
-// @Router /swagger [get]
+// @Summary      Get Swagger Documentation
+// @Description  Get the Swagger API documentation for the producer.
+// @Tags         Admin
+// @Success      200
+// @Router       /swagger [get]
 func addSwaggerHandler(r *mux.Router) {
        r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler)
 }
index 3653e9e..19851be 100644 (file)
@@ -22,6 +22,7 @@ package main
 
 import (
        "bytes"
+       "fmt"
        "io/ioutil"
        "net/http"
        "os/exec"
@@ -40,7 +41,10 @@ import (
 func TestGenerateSwaggerDocs(t *testing.T) {
        cmd := exec.Command("./generate_swagger_docs.sh")
 
-       cmd.Run()
+       err := cmd.Run()
+       if err != nil {
+               fmt.Println("Error generating Swagger:", err)
+       }
 }
 
 func TestValidateConfiguration(t *testing.T) {
index c0baa17..29207b8 100644 (file)
@@ -73,7 +73,7 @@ The API is also described in Swagger-JSON and YAML:
    :header: "API name", "|swagger-icon|", "|yaml-icon|"
    :widths: 10,5, 5
 
-   "DMaaP Mediator Producer API", ":download:`link <../dmaap-mediator-producer/docs/swagger.json>`", ":download:`link <../dmaap-mediator-producer/docs/swagger.yaml>`"
+   "DMaaP Mediator Producer API", ":download:`link <../dmaap-mediator-producer/api/swagger.json>`", ":download:`link <../dmaap-mediator-producer/api/swagger.yaml>`"
 
 Non-RT-RIC App Catalogue (Initial)
 ==================================
index d4cdb81..4ee6998 100644 (file)
@@ -37,7 +37,7 @@ redoc = [
             {
                 'name': 'DMaaP Mediator Producer API',
                 'page': 'dmaap-mediator-producer-api',
-                'spec': '../dmaap-mediator-producer/docs/swagger.json',
+                'spec': '../dmaap-mediator-producer/api/swagger.json',
                 'embed': True,
             }
         ]