When creating a virtual Service VIA API using swagger all properties (required and optional) in a swagger are required
search cancel

When creating a virtual Service VIA API using swagger all properties (required and optional) in a swagger are required

book

Article ID: 213144

calendar_today

Updated On:

Products

Service Virtualization

Issue/Introduction

Description:

When creating a service from API (with the Service Virtualization API v3) if the request contains a JSON object, then all its properties are considered as required (they are all Arguments in the resulting VSI).

DevTest version:

10.6.0.1011 + patch DE492547

Virtual service creation:

POST /lisa-virtualize-invoke/api/v3/vses/VSE/services HTTP/1.1

Host: localhost:1505

Accept: application/json

[…]

Content-Disposition: form-data; name="config"

{

  "virtualService": {

    "version": "1",

    "name": "ExampleService",

    "description": "",

    "status": ""

  },

  "transportProtocol": {

    "typeId": "HTTP",

    "basePath": "/",

    "recordingEndpoint":{ 

        "useSSL":false,

        "host": "localhost",

        "port": "12345"

     }

  },

  "dataProtocol": {

    "forRequest": true,

    "typeId": "RESTDPH"

  }

}

 

Content-Disposition: form-data; name="deploy"

true


Content-Disposition: form-data; name="inputFile1"; filename="exampleSwagger.json"

Content-Type: application/json

(data)

 

exampleSwagger.json

{

   "openapi":"3.0.0",

   "info":{

      "title":"ExampleService",

      "description":"",

      "version":"1.0.0",

      "contact":{

         "name":"APISupport",

         "email":"[email protected]",

         "url":"https://labportale.domain.com"

      }

   },

   "externalDocs":{

      "description":"Documentazione dove viene descritto i servizi esposti",

      "url":"https://gitlab-os-lab.domain.coom/DocPaaS/ApiGateway"

   },

   "servers":[

      {

         "url":"https://http://examplebe.inail.it",

         "description":""

      }

   ],

  "paths":{

      "/example/test/service":{

         "get":{

            "tags":[

               "get"

            ],

            "summary":"",

            "description":"",

            "parameters":[

               {

                  "name":"Header1",

                  "in":"query",

                  "description":"",

                  "required":true,

                  "schema":{

                     "type":"integer",

                     "format":"int32"

                  }

               }

            ],

            "responses":{

               "200":{

                  "description":"",

                  "content":{

                     "application/json":{

                        "schema":{

                           "type":"object",

                           "properties":{

                              "Version":{

                                 "type":"integer",

                                 "format":"int64",

                                 "example":"1.0.0"

                              },

                             "Json":{

                                 "type":"object"

                              }

                           }

                        }

                     }

                  }

               }

            }

         },

         "post":{

            "tags":[

               "post"

            ],

            "summary":"",

            "parameters":[

 

            ],

            "requestBody":{

               "required":true,

               "content":{

                  "application/json":{

                     "schema":{

                        "type":"object",

                        "required": [

                            "id"

                        ],

                        "properties": {

                            "id": {

                                "type": "integer",

                                "format": "int64"

                            },

                            "name": {

                                "type": "string",

                                "example": "pippo"

                            }

                        }

                     }

                  }

               }

            },

            "responses":{

               "200":{

                  "description":"",

                  "content":{

                     "application/json":{

                        "schema":{

                           "type":"object",

                           "properties":{

                              "status":{

                                 "type":"string",

                                 "example":"200"

                              },

                              "messagge":{

                                 "type":"string",

                                 "example":"Creazioneeseguita"

                             }

                           }

                        }

                     }

                  }

               }

            }

         },

         "put":{

            "tags":[

               "UpdateClient"

            ],

           "summary":"",

            "parameters":[

 

            ],

            "requestBody":{

               "required":true,

               "content":{

                  "application/json":{

                     "schema":{

                        "type":"object",

                        "properties":{

 

                        }

                     }

                  }

               }

            },

            "responses":{

               "200":{

                  "description":"",

                  "content":{

                     "application/json":{

                        "schema":{

                           "type":"object",

                           "properties":{

                              "status":{

                                 "type":"string",

                                 "example":"200"

                              },

                              "messagge":{

                                 "type":"string",

                                 "example":"Aggiornamentoeseguito"

                              }

                           }

                        }

                     }

                  }

               }

            }

         }

      } 

   },

   "components":{

      "schemas":{

         "GeneralError":{

            "type":"object",

            "properties":{

               "status":{

                  "type":"integer",

                  "format":"int32"

               },

               "message":{

                  "type":"string"

               }

            }

         }

      },

      "responses":{

         "NotFound":{

            "description":"Client non trovato"

         },

         "IllegalInput":{

            "description":"ParametriErrati"

         },

         "GeneralError":{

            "description":"AssertionFalsified",

            "content":{

               "application/json":{

                  "schema":{

                     "$ref":"#/components/schemas/GeneralError"

                  }

               }

            }

         }

      }

   },

   "x-inail-catalog":{

      "Name":"ServiceExample",

      "Group":"example",

      "Description":"ServiceExample",

      "JWTNAME":"NOJWTNAME",

      "TipoProtezione":"FE_BE",

      "TipoAuth":[

         "OAUTHAC",

         "SSO"

      ],

      "HttpVerb":[

         "GET",

         "POST",

         "PUT",

         "DELETE"

      ],

      "CanaleBE":true,

      "CanaleInternet":true,

      "CanaleIntranet":true,

      "Security":[

         "F1",

         "B1"

      ],

      "MaximumEntries":1000,

      "MaximumEntrySize":10000000,

      "RoutingUrls":[

         {

            "Version": 1.0,

            "Routingurl":"http://examplebe.domain.com/example/test/service"

         }

      ],

      "OpenApi":{

         "Version":"1.0"

      },

      "StringaPubblicazione":"/api/example/test*"

   }

}

 

 

Virtual service call:

POST /example/test/service HTTP/1.1

Content-Type: application/json

[…]

{

  "id": 0

}

 

Expected response:

Because only the property "id" has been marked as required in the swagger, we expect the virtual service to respond with the following

{

    "messagge": "Creazioneeseguita",

    "status": "200"

}

 

Actual response:

<html>

<head>

<title>404 Not Found</title>

</head>

[…]

The virtual service cannot find the request in its service image and responds with a 404 error

 

More details:

In instead all properties are included in the request:

{

  "id": 0,

  "name": "pippo"

}

Then the virtual service responds as expected:

{

    "messagge": "Creazioneeseguita",

    "status": "200"

}

Environment

Devtest API 10.6

Component : CA Service Virtualization

Cause

Currently, in Devtest 10.6 this would require two transactions and the API is creating only a single transaction.

Resolution

I received an update from the dev /Project management team that currently this is working as designed.
Currently, the API will create a single transaction with all properties.
To have the VS handle required and option additional transactions must be created manually.