vmware / vmware-openapi-generator

VMware-openapi-generator tool generates open-api documents from vapi metamodel format.
Other
23 stars 19 forks source link

Filter query parameters model is unusable by API methods #37

Open VamshikShetty opened 5 years ago

VamshikShetty commented 5 years ago

GET method: /vcenter/cluster

Query params: filter.datacenters : list[str] filter.clusters : list[str] filter.folders : list[str] filter_names : list[str]

Definition: vcenter.cluster.filter_spec which is the representation of filter query params is never referenced in any path or definitions.

"vcenter.cluster.filter_spec": {
           "type": "object",
           "properties": {
               "clusters": {
                   "description": "Identifiers of clusters that can match the filter.\nIf unset or empty, clusters with any identifier match the filter.\nWhen clients pass a value of this structure as a parameter, the field must contain identifiers for the resource type: ClusterComputeResource. When operations return a value of this structure as a result, the field will contain identifiers for the resource type: ClusterComputeResource.",
                   "type": "array",
                   "uniqueItems": true,
                   "items": {
                       "type": "string"
                   }
               },
               "names": {
                   "description": "Names that clusters must have to match the filter (see Cluster.Info.name).\nIf unset or empty, clusters with any name match the filter.",
                   "type": "array",
                   "uniqueItems": true,
                   "items": {
                       "type": "string"
                   }
               },
               "folders": {
                   "description": "Folders that must contain the cluster for the cluster to match the filter.\nIf unset or empty, clusters in any folder match the filter.\nWhen clients pass a value of this structure as a parameter, the field must contain identifiers for the resource type: Folder. When operations return a value of this structure as a result, the field will contain identifiers for the resource type: Folder.",
                   "type": "array",
                   "uniqueItems": true,
                   "items": {
                       "type": "string"
                   }
               },
               "datacenters": {
                   "description": "Datacenters that must contain the cluster for the cluster to match the filter.\nIf unset or empty, clusters in any datacenter match the filter.\nWhen clients pass a value of this structure as a parameter, the field must contain identifiers for the resource type: Datacenter. When operations return a value of this structure as a result, the field will contain identifiers for the resource type: Datacenter.",
                   "type": "array",
                   "uniqueItems": true,
                   "items": {
                       "type": "string"
                   }
               }
           }
       }

This definition creates a model which is not usable by the API method itself.

Python Example of this issue:

If a list of datacenter Id is passed to VcenterClusterFilterSpec model, example: vmsw_vsphere.vcenter.VcenterClusterFilterSpec(datacenters=["datacenter-34"]) then output object's to_dict() function produces: { 'folders': None, 'clusters': None, 'names': None, 'datacenters': ['datacenter-34'] }

But to be used by its own corresponding API method it needs to pass { "filter_datacenters":["datacenter-34"], "filter_clusters":[], "filter_folders":[], "filter_names":[] } Given auto generated model of query params is of no use in API methods hence it needs to be removed or updated with support to query params.

sreeshas commented 5 years ago

@kunal-pmj Can you take a look at this issue?

kunal-pmj commented 5 years ago

vcenter.cluster.filter_spec and other similar specs should not be created in the swagger definition. This is a bug