Adjust validation to allow empty values 08/188908/13
authorAlexander Mazuruk <a.mazuruk@samsung.com>
Mon, 10 Sep 2018 18:37:07 +0000 (20:37 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Mon, 1 Oct 2018 14:34:19 +0000 (16:34 +0200)
After user input is marshalled, swagger server validates data. When
input data is enum, it was strictly validated against enum values.
There is no empty value thus user receives an error and is forced to
always set enum fields in e.g. JobFilter.Status.

Modifying generated code is a bad practice but it was not possible (to
the best of the authors knowledge) to achieve this by simply modyfing
swagger.yml and re-generating models.

Possible solutions:
- adding and using new type (which would satisfy swaggers interfaces)
- customizing code generation

Change-Id: Ifc381a12936277db9938032dadb31fe865e84ad1
Signed-off-by: Alexander Mazuruk <a.mazuruk@samsung.com>
artifact_sort_by.go
artifact_status.go
artifact_type.go
job_sort_by.go
job_status.go
sort_order.go

index 866532c..2921f0f 100644 (file)
@@ -46,7 +46,7 @@ var artifactSortByEnum []interface{}
 
 func init() {
        var res []ArtifactSortBy
-       if err := json.Unmarshal([]byte(`["ID"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["ID",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
index 2c30dab..4255c7d 100644 (file)
@@ -62,7 +62,7 @@ var artifactStatusEnum []interface{}
 
 func init() {
        var res []ArtifactStatus
-       if err := json.Unmarshal([]byte(`["DOWNLOADING","READY","FAILED","PENDING"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["DOWNLOADING","READY","FAILED","PENDING",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
index eada618..608b49f 100644 (file)
@@ -62,7 +62,7 @@ var artifactTypeEnum []interface{}
 
 func init() {
        var res []ArtifactType
-       if err := json.Unmarshal([]byte(`["IMAGE","RESULT","TEST","YAML"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["IMAGE","RESULT","TEST","YAML",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
index 93fb19b..8af2a25 100644 (file)
@@ -64,7 +64,7 @@ var jobSortByEnum []interface{}
 
 func init() {
        var res []JobSortBy
-       if err := json.Unmarshal([]byte(`["ID","CreatedDate","UpdatedDate","JobStatus"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["ID","CreatedDate","UpdatedDate","JobStatus",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
index 45e0888..88220b2 100644 (file)
@@ -82,7 +82,7 @@ var jobStatusEnum []interface{}
 
 func init() {
        var res []JobStatus
-       if err := json.Unmarshal([]byte(`["NEW","PARSING","DOWNLOADING","WAITING","RUNNING","COMPLETED","FAILED","CANCELED"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["NEW","PARSING","DOWNLOADING","WAITING","RUNNING","COMPLETED","FAILED","CANCELED",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {
index f650ceb..404d772 100644 (file)
@@ -52,7 +52,7 @@ var sortOrderEnum []interface{}
 
 func init() {
        var res []SortOrder
-       if err := json.Unmarshal([]byte(`["Ascending","Descending"]`), &res); err != nil {
+       if err := json.Unmarshal([]byte(`["Ascending","Descending",""]`), &res); err != nil {
                panic(err)
        }
        for _, v := range res {