openshift-online / ocm-api-model

Apache License 2.0
4 stars 96 forks source link

openapi: listing collections don't document returning a `kind` field #111

Open cben opened 4 years ago

cben commented 4 years ago

I notice none of the method List { blocks contain an out Kind String parameter.
And indeed the generated openapi documents kind for individual objects corresponding to method Get eg. /api/clusters_mgmt/v1/clusters/{cluster_id} but not for collection lists e.g. /api/clusters_mgmt/v1/clusters

@nimrodshn @jhernand I can send a PR to add those, will that be enough?

I see generated server code has special logic to return correct Kind, including link vs full object. Will it automatically also return kind for lists?

jhernand commented 4 years ago

Yes, the generated server code automatically returns the "kind" attribute also for lists. For example, this is the generated server code that returns the cluster list: https://github.com/openshift-online/ocm-sdk-go/blob/6997f79338819f63753b9156c9a8ecbb8537a230/clustersmgmt/v1/clusters_resource_json.go#L106-L157

And this is the part of the generator that takes care of that: https://github.com/openshift-online/ocm-api-metamodel/blob/a92c173afbff673a56219f427f20b20ab9a1778d/pkg/generators/golang/json_generator.go#L1007-L1041

I believe that what needs to be changed is the code that generates the OpenAPI specification. Most probably this method: https://github.com/openshift-online/ocm-api-metamodel/blob/a92c173afbff673a56219f427f20b20ab9a1778d/pkg/generators/openapi/openapi_generator.go#L316-L343