From 44c11483ca68af7576613e75603593cf2e4ed712 Mon Sep 17 00:00:00 2001 From: Magyari Sandor Szilard Date: Wed, 28 Aug 2019 11:59:43 +0200 Subject: [PATCH] fix return type for getVersions endpoint --- api/openapi-spec/cloudinfo.json | 63 +++++++- api/openapi-spec/cloudinfo.yaml | 211 ++++++++++++++----------- internal/app/cloudinfo/api/handlers.go | 2 +- pkg/cloudinfo/types.go | 1 + 4 files changed, 183 insertions(+), 94 deletions(-) diff --git a/api/openapi-spec/cloudinfo.json b/api/openapi-spec/cloudinfo.json index 93b20c156..5fab833a0 100644 --- a/api/openapi-spec/cloudinfo.json +++ b/api/openapi-spec/cloudinfo.json @@ -434,9 +434,12 @@ ], "responses": { "200": { - "description": "VersionsResponse", + "description": "LocationVersion", "schema": { - "$ref": "#/definitions/VersionsResponse" + "type": "array", + "items": { + "$ref": "#/definitions/LocationVersion" + } } } } @@ -463,6 +466,19 @@ }, "x-go-package": "github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api" }, + "CloudInfo": { + "description": "CloudInfo is the main entry point for retrieving vm type characteristics and pricing information on different cloud providers", + "type": "object", + "properties": { + "GetContinents": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, "Continent": { "description": "Continent holds continent and regions of a cloud provider", "type": "object", @@ -669,6 +685,16 @@ }, "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" }, + "NetworkPerfMapper": { + "description": "NetworkPerfMapper operations related to mapping between virtual machines to network performance categories", + "type": "object", + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, + "ProductDetailSource": { + "description": "ProductDetailSource product details related set of operations", + "type": "object", + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, "ProductDetails": { "description": "ProductDetails extended view of the virtual machine details", "type": "object", @@ -781,6 +807,17 @@ }, "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" }, + "ProviderDescriber": { + "description": "ProviderDescriber describes a provider", + "type": "object", + "properties": { + "ProviderName": { + "description": "ProviderName returns the name of the provider", + "type": "string" + } + }, + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, "ProviderResponse": { "description": "ProviderResponse is the response used for the requested provider", "type": "object", @@ -844,6 +881,17 @@ }, "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" }, + "ServiceDescriber": { + "description": "ServiceDescriber represents a service; eg.: oke, eks\nExtend this interface with other operations if needed", + "type": "object", + "properties": { + "ServiceName": { + "description": "ServiceName abstracts the name assembly for the service", + "type": "string" + } + }, + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, "ServiceResponse": { "description": "ServiceResponse holds the list of available services", "type": "object", @@ -868,6 +916,17 @@ }, "x-go-package": "github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api" }, + "Version": { + "description": "Version represents a version", + "type": "object", + "properties": { + "versions": { + "type": "string", + "x-go-name": "Version" + } + }, + "x-go-package": "github.com/banzaicloud/cloudinfo/pkg/cloudinfo" + }, "VersionsResponse": { "description": "VersionsResponse holds the list of available versions", "type": "object", diff --git a/api/openapi-spec/cloudinfo.yaml b/api/openapi-spec/cloudinfo.yaml index 81ef6aed8..7ed13cfce 100644 --- a/api/openapi-spec/cloudinfo.yaml +++ b/api/openapi-spec/cloudinfo.yaml @@ -4,15 +4,14 @@ info: The product info application uses the cloud provider APIs to asynchronously fetch and parse instance type attributes - and prices, while storing the results in an in memory cache and making it - available as structured data through a REST API. + and prices, while storing the results in an in memory cache and making it available as structured data through a REST API. title: Product Info. contact: name: Banzai Cloud email: info@banzaicloud.com license: name: Apache 2.0 - url: 'http://www.apache.org/licenses/LICENSE-2.0.html' + url: http://www.apache.org/licenses/LICENSE-2.0.html version: 0.0.1 paths: /continents: @@ -22,12 +21,12 @@ paths: - continents operationId: getContinents responses: - '200': + "200": description: ContinentsResponse content: application/json: schema: - $ref: '#/components/schemas/ContinentsResponse' + $ref: "#/components/schemas/ContinentsResponse" /providers: get: description: Returns the supported providers @@ -35,13 +34,13 @@ paths: - providers operationId: getProviders responses: - '200': + "200": description: ProvidersResponse content: application/json: schema: - $ref: '#/components/schemas/ProvidersResponse' - '/providers/{provider}': + $ref: "#/components/schemas/ProvidersResponse" + "/providers/{provider}": get: description: Returns the requested provider tags: @@ -55,13 +54,13 @@ paths: schema: type: string responses: - '200': + "200": description: ProviderResponse content: application/json: schema: - $ref: '#/components/schemas/ProviderResponse' - '/providers/{provider}/services': + $ref: "#/components/schemas/ProviderResponse" + "/providers/{provider}/services": get: description: Provides a list with the available services for the provider tags: @@ -75,16 +74,15 @@ paths: schema: type: string responses: - '200': + "200": description: ServicesResponse content: application/json: schema: - $ref: '#/components/schemas/ServicesResponse' - '/providers/{provider}/services/{service}': + $ref: "#/components/schemas/ServicesResponse" + "/providers/{provider}/services/{service}": get: - description: >- - Provides service details for the given service on the provider in the + description: Provides service details for the given service on the provider in the given region tags: - service @@ -103,17 +101,15 @@ paths: schema: type: string responses: - '200': + "200": description: ServiceResponse content: application/json: schema: - $ref: '#/components/schemas/ServiceResponse' - '/providers/{provider}/services/{service}/continents': + $ref: "#/components/schemas/ServiceResponse" + "/providers/{provider}/services/{service}/continents": get: - description: >- - Provides the list of available continents and regions of a cloud - provider + description: Provides the list of available continents and regions of a cloud provider tags: - continents operationId: getContinentsData @@ -131,13 +127,13 @@ paths: schema: type: string responses: - '200': + "200": description: ContinentsDataResponse content: application/json: schema: - $ref: '#/components/schemas/ContinentsDataResponse' - '/providers/{provider}/services/{service}/regions': + $ref: "#/components/schemas/ContinentsDataResponse" + "/providers/{provider}/services/{service}/regions": get: description: Provides the list of available regions of a cloud provider tags: @@ -157,13 +153,13 @@ paths: schema: type: string responses: - '200': + "200": description: RegionsResponse content: application/json: schema: - $ref: '#/components/schemas/RegionsResponse' - '/providers/{provider}/services/{service}/regions/{region}': + $ref: "#/components/schemas/RegionsResponse" + "/providers/{provider}/services/{service}/regions/{region}": get: description: Provides the detailed info of a specific region of a cloud provider tags: @@ -189,18 +185,17 @@ paths: schema: type: string responses: - '200': + "200": description: GetRegionResp content: application/json: schema: - $ref: '#/components/schemas/GetRegionResp' - '/providers/{provider}/services/{service}/regions/{region}/images': + $ref: "#/components/schemas/GetRegionResp" + "/providers/{provider}/services/{service}/regions/{region}/images": get: tags: - images - summary: >- - Provides a list of available images on a given provider in a specific + summary: Provides a list of available images on a given provider in a specific region for a service. operationId: getImages parameters: @@ -233,18 +228,17 @@ paths: schema: type: string responses: - '200': + "200": description: ImagesResponse content: application/json: schema: - $ref: '#/components/schemas/ImagesResponse' - '/providers/{provider}/services/{service}/regions/{region}/products': + $ref: "#/components/schemas/ImagesResponse" + "/providers/{provider}/services/{service}/regions/{region}/products": get: tags: - products - summary: >- - Provides a list of available machine types on a given provider in a + summary: Provides a list of available machine types on a given provider in a specific region. operationId: getProducts parameters: @@ -267,18 +261,17 @@ paths: schema: type: string responses: - '200': + "200": description: ProductDetailsResponse content: application/json: schema: - $ref: '#/components/schemas/ProductDetailsResponse' - '/providers/{provider}/services/{service}/regions/{region}/versions': + $ref: "#/components/schemas/ProductDetailsResponse" + "/providers/{provider}/services/{service}/regions/{region}/versions": get: tags: - versions - summary: >- - Provides a list of available versions on a given provider in a specific + summary: Provides a list of available versions on a given provider in a specific region for a service. operationId: getVersions parameters: @@ -301,12 +294,14 @@ paths: schema: type: string responses: - '200': - description: VersionsResponse + "200": + description: LocationVersion content: application/json: schema: - $ref: '#/components/schemas/VersionsResponse' + type: array + items: + $ref: "#/components/schemas/LocationVersion" servers: - url: /api/v1 components: @@ -325,6 +320,16 @@ components: format: double x-go-name: AttributeValues x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api + CloudInfo: + description: CloudInfo is the main entry point for retrieving vm type characteristics + and pricing information on different cloud providers + type: object + properties: + GetContinents: + type: array + items: + type: string + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo Continent: description: Continent holds continent and regions of a cloud provider type: object @@ -335,16 +340,15 @@ components: regions: type: array items: - $ref: '#/components/schemas/Region' + $ref: "#/components/schemas/Region" x-go-name: Regions x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api ContinentsDataResponse: - description: >- - ContinentsDataResponse holds the list of available continents and + description: ContinentsDataResponse holds the list of available continents and regions of a cloud provider type: array items: - $ref: '#/components/schemas/Continent' + $ref: "#/components/schemas/Continent" x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api ContinentsResponse: description: ContinentsResponse holds the list of available continents @@ -353,76 +357,70 @@ components: type: string x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetAttributeValuesPathParams: - description: >- - GetAttributeValuesPathParams is a placeholder for the get attribute + description: GetAttributeValuesPathParams is a placeholder for the get attribute values route's path parameters type: object properties: attribute: - description: 'in:path' + description: in:path type: string x-go-name: Attribute provider: - description: 'in:path' + description: in:path type: string x-go-name: Provider region: - description: 'in:path' + description: in:path type: string x-go-name: Region service: - description: 'in:path' + description: in:path type: string x-go-name: Service x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetImagesQueryParams: - description: >- - GetImagesQueryParams is a placeholder for the get images query - parameters + description: GetImagesQueryParams is a placeholder for the get images query parameters type: object properties: gpu: - description: 'in:query' + description: in:query type: string x-go-name: Gpu version: - description: 'in:query' + description: in:query type: string x-go-name: Version x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetProviderPathParams: - description: >- - GetProviderPathParams is a placeholder for the providers related route + description: GetProviderPathParams is a placeholder for the providers related route path parameters type: object properties: provider: - description: 'in:path' + description: in:path type: string x-go-name: Provider x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetRegionPathParams: - description: >- - GetRegionPathParams is a placeholder for the regions related route path + description: GetRegionPathParams is a placeholder for the regions related route path parameters type: object properties: provider: - description: 'in:path' + description: in:path type: string x-go-name: Provider region: - description: 'in:path' + description: in:path type: string x-go-name: Region service: - description: 'in:path' + description: in:path type: string x-go-name: Service x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetRegionResp: - description: >- - GetRegionResp holds the detailed description of a specific region of a + description: GetRegionResp holds the detailed description of a specific region of a cloud provider type: object properties: @@ -439,17 +437,16 @@ components: x-go-name: Zones x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api GetServicesPathParams: - description: >- - GetServicesPathParams is a placeholder for the services related route + description: GetServicesPathParams is a placeholder for the services related route path parameters type: object properties: provider: - description: 'in:path' + description: in:path type: string x-go-name: Provider service: - description: 'in:path' + description: in:path type: string x-go-name: Service x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api @@ -474,7 +471,7 @@ components: images: type: array items: - $ref: '#/components/schemas/Image' + $ref: "#/components/schemas/Image" x-go-name: Images x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api LocationVersion: @@ -493,6 +490,15 @@ components: type: string x-go-name: Versions x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo + NetworkPerfMapper: + description: NetworkPerfMapper operations related to mapping between virtual + machines to network performance categories + type: object + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo + ProductDetailSource: + description: ProductDetailSource product details related set of operations + type: object + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo ProductDetails: description: ProductDetails extended view of the virtual machine details type: object @@ -514,8 +520,7 @@ components: format: double x-go-name: Cpus currentGen: - description: >- - CurrentGen signals whether the instance type generation is the + description: CurrentGen signals whether the instance type generation is the current one. Only applies for amazon type: boolean x-go-name: CurrentGen @@ -540,7 +545,7 @@ components: spotPrice: type: array items: - $ref: '#/components/schemas/ZonePrice' + $ref: "#/components/schemas/ZonePrice" x-go-name: SpotPrice type: type: string @@ -556,16 +561,14 @@ components: type: object properties: products: - description: >- - Products represents a slice of products for a given provider (VMs + description: Products represents a slice of products for a given provider (VMs with attributes and process) type: array items: - $ref: '#/components/schemas/ProductDetails' + $ref: "#/components/schemas/ProductDetails" x-go-name: Products scrapingTime: - description: >- - ScrapingTime represents scraping time for a given provider in + description: ScrapingTime represents scraping time for a given provider in milliseconds type: string x-go-name: ScrapingTime @@ -580,15 +583,23 @@ components: services: type: array items: - $ref: '#/components/schemas/Service' + $ref: "#/components/schemas/Service" x-go-name: Services x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo + ProviderDescriber: + description: ProviderDescriber describes a provider + type: object + properties: + ProviderName: + description: ProviderName returns the name of the provider + type: string + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo ProviderResponse: description: ProviderResponse is the response used for the requested provider type: object properties: provider: - $ref: '#/components/schemas/Provider' + $ref: "#/components/schemas/Provider" x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api ProvidersResponse: description: ProvidersResponse is the response used for the supported providers @@ -597,7 +608,7 @@ components: providers: type: array items: - $ref: '#/components/schemas/Provider' + $ref: "#/components/schemas/Provider" x-go-name: Providers x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api Region: @@ -615,7 +626,7 @@ components: description: RegionsResponse holds the list of available regions of a cloud provider type: array items: - $ref: '#/components/schemas/Region' + $ref: "#/components/schemas/Region" x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api Service: description: it's intended to implement the ServiceDescriber interface @@ -629,12 +640,22 @@ components: type: string x-go-name: Service x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo + ServiceDescriber: + description: |- + ServiceDescriber represents a service; eg.: oke, eks + Extend this interface with other operations if needed + type: object + properties: + ServiceName: + description: ServiceName abstracts the name assembly for the service + type: string + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo ServiceResponse: description: ServiceResponse holds the list of available services type: object properties: service: - $ref: '#/components/schemas/Service' + $ref: "#/components/schemas/Service" x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api ServicesResponse: description: ServicesResponse holds the list of available services @@ -643,9 +664,17 @@ components: services: type: array items: - $ref: '#/components/schemas/Service' + $ref: "#/components/schemas/Service" x-go-name: Services x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api + Version: + description: Version represents a version + type: object + properties: + versions: + type: string + x-go-name: Version + x-go-package: github.com/banzaicloud/cloudinfo/pkg/cloudinfo VersionsResponse: description: VersionsResponse holds the list of available versions type: object @@ -653,7 +682,7 @@ components: versions: type: array items: - $ref: '#/components/schemas/LocationVersion' + $ref: "#/components/schemas/LocationVersion" x-go-name: Versions x-go-package: github.com/banzaicloud/cloudinfo/internal/app/cloudinfo/api ZonePrice: diff --git a/internal/app/cloudinfo/api/handlers.go b/internal/app/cloudinfo/api/handlers.go index 6df27115a..e73fff720 100644 --- a/internal/app/cloudinfo/api/handlers.go +++ b/internal/app/cloudinfo/api/handlers.go @@ -474,7 +474,7 @@ func (r *RouteHandler) getImages() gin.HandlerFunc { // Security: // // Responses: -// 200: VersionsResponse +// 200: []LocationVersion func (r *RouteHandler) getVersions() gin.HandlerFunc { return func(c *gin.Context) { pathParams := GetRegionPathParams{} diff --git a/pkg/cloudinfo/types.go b/pkg/cloudinfo/types.go index 8f549b7a0..8d0219e5f 100644 --- a/pkg/cloudinfo/types.go +++ b/pkg/cloudinfo/types.go @@ -100,6 +100,7 @@ func newZonePrice(zone string, price float64) *ZonePrice { } // LocationVersion struct for displaying version information per location +// swagger:model LocationVersion type LocationVersion struct { Location string `json:"location"` Versions []string `json:"versions"`