зеркало из https://github.com/Azure/ARO-RP.git
Add x-ms-enum type to swagger and SDK
x-ms-enum will make future modifications of the API simpler, the type is defined https://github.com/Azure/autorest/tree/master/docs/extensions#x-ms-enum Signed-off-by: Petr Kotas <pkotas@redhat.com>
This commit is contained in:
Родитель
e5abb84cec
Коммит
213abf54a6
|
@ -1,2 +1 @@
|
|||
230c7dccc589aba8861a211e1937df83e06bd8f2fffff997e4b45f17c3cfd99b swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2020-04-30/redhatopenshift.json
|
||||
40eb33b40a56cf842b704050d74eb28ea0dea59b970c1ee1afd8c647c6b5a8ac swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2020-10-31-preview/redhatopenshift.json
|
||||
be04d575d15d3e82fad72008edf7dc89548058bf9591df5e0f7152c9e148d443 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2020-10-31-preview/redhatopenshift.json
|
||||
|
|
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ clean:
|
|||
find python -type d -name __pycache__ -delete
|
||||
|
||||
client: generate
|
||||
hack/build-client.sh 2020-04-30 2020-10-31-preview
|
||||
hack/build-client.sh 2020-10-31-preview
|
||||
|
||||
generate:
|
||||
go generate ./...
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#!/bin/bash
|
||||
|
||||
function clean() {
|
||||
local API_VERSION=$1
|
||||
|
||||
rm .sha256sum
|
||||
|
||||
rm -rf pkg/client
|
||||
mkdir pkg/client
|
||||
rm -rf pkg/client/services/redhatopenshift/mgmt/"$API_VERSION"
|
||||
mkdir pkg/client/services/redhatopenshift/mgmt/"$API_VERSION"
|
||||
|
||||
rm -rf python/client
|
||||
mkdir -p python/client
|
||||
rm -rf python/client/azure/mgmt/redhatopenshift/v"${API_VERSION//-/_}"
|
||||
mkdir -p python/client/azure/mgmt/redhatopenshift/v"${API_VERSION//-/_}"
|
||||
}
|
||||
|
||||
function checksum() {
|
||||
|
@ -54,9 +56,10 @@ function generate_python() {
|
|||
>python/client/__init__.py
|
||||
}
|
||||
|
||||
clean
|
||||
|
||||
for API in "$@"
|
||||
do
|
||||
clean "${API}"
|
||||
checksum "${API}"
|
||||
generate_golang "${API}"
|
||||
generate_python "${API}"
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
//go:generate go run ../../../hack/swagger ../../../swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2020-04-30
|
||||
|
||||
package v20200430
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
|
@ -114,48 +114,3 @@ const (
|
|||
func PossibleVMSizeValues() []VMSize {
|
||||
return []VMSize{StandardD16asV4, StandardD16sV3, StandardD2sV3, StandardD32asV4, StandardD32sV3, StandardD4asV4, StandardD4sV3, StandardD8asV4, StandardD8sV3, StandardE16sV3, StandardE32sV3, StandardE4sV3, StandardE8sV3, StandardF16sV2, StandardF32sV2, StandardF4sV2, StandardF8sV2}
|
||||
}
|
||||
|
||||
// VMSize1 enumerates the values for vm size 1.
|
||||
type VMSize1 string
|
||||
|
||||
const (
|
||||
// VMSize1StandardD16asV4 ...
|
||||
VMSize1StandardD16asV4 VMSize1 = "Standard_D16as_v4"
|
||||
// VMSize1StandardD16sV3 ...
|
||||
VMSize1StandardD16sV3 VMSize1 = "Standard_D16s_v3"
|
||||
// VMSize1StandardD2sV3 ...
|
||||
VMSize1StandardD2sV3 VMSize1 = "Standard_D2s_v3"
|
||||
// VMSize1StandardD32asV4 ...
|
||||
VMSize1StandardD32asV4 VMSize1 = "Standard_D32as_v4"
|
||||
// VMSize1StandardD32sV3 ...
|
||||
VMSize1StandardD32sV3 VMSize1 = "Standard_D32s_v3"
|
||||
// VMSize1StandardD4asV4 ...
|
||||
VMSize1StandardD4asV4 VMSize1 = "Standard_D4as_v4"
|
||||
// VMSize1StandardD4sV3 ...
|
||||
VMSize1StandardD4sV3 VMSize1 = "Standard_D4s_v3"
|
||||
// VMSize1StandardD8asV4 ...
|
||||
VMSize1StandardD8asV4 VMSize1 = "Standard_D8as_v4"
|
||||
// VMSize1StandardD8sV3 ...
|
||||
VMSize1StandardD8sV3 VMSize1 = "Standard_D8s_v3"
|
||||
// VMSize1StandardE16sV3 ...
|
||||
VMSize1StandardE16sV3 VMSize1 = "Standard_E16s_v3"
|
||||
// VMSize1StandardE32sV3 ...
|
||||
VMSize1StandardE32sV3 VMSize1 = "Standard_E32s_v3"
|
||||
// VMSize1StandardE4sV3 ...
|
||||
VMSize1StandardE4sV3 VMSize1 = "Standard_E4s_v3"
|
||||
// VMSize1StandardE8sV3 ...
|
||||
VMSize1StandardE8sV3 VMSize1 = "Standard_E8s_v3"
|
||||
// VMSize1StandardF16sV2 ...
|
||||
VMSize1StandardF16sV2 VMSize1 = "Standard_F16s_v2"
|
||||
// VMSize1StandardF32sV2 ...
|
||||
VMSize1StandardF32sV2 VMSize1 = "Standard_F32s_v2"
|
||||
// VMSize1StandardF4sV2 ...
|
||||
VMSize1StandardF4sV2 VMSize1 = "Standard_F4s_v2"
|
||||
// VMSize1StandardF8sV2 ...
|
||||
VMSize1StandardF8sV2 VMSize1 = "Standard_F8s_v2"
|
||||
)
|
||||
|
||||
// PossibleVMSize1Values returns an array of possible values for the VMSize1 const type.
|
||||
func PossibleVMSize1Values() []VMSize1 {
|
||||
return []VMSize1{VMSize1StandardD16asV4, VMSize1StandardD16sV3, VMSize1StandardD2sV3, VMSize1StandardD32asV4, VMSize1StandardD32sV3, VMSize1StandardD4asV4, VMSize1StandardD4sV3, VMSize1StandardD8asV4, VMSize1StandardD8sV3, VMSize1StandardE16sV3, VMSize1StandardE32sV3, VMSize1StandardE4sV3, VMSize1StandardE8sV3, VMSize1StandardF16sV2, VMSize1StandardF32sV2, VMSize1StandardF4sV2, VMSize1StandardF8sV2}
|
||||
}
|
||||
|
|
|
@ -774,8 +774,8 @@ func (tr TrackedResource) MarshalJSON() ([]byte, error) {
|
|||
type WorkerProfile struct {
|
||||
// Name - The worker profile name. Must be "worker" (immutable).
|
||||
Name *string `json:"name,omitempty"`
|
||||
// VMSize - The size of the worker VMs (immutable). Possible values include: 'VMSize1StandardD16asV4', 'VMSize1StandardD16sV3', 'VMSize1StandardD2sV3', 'VMSize1StandardD32asV4', 'VMSize1StandardD32sV3', 'VMSize1StandardD4asV4', 'VMSize1StandardD4sV3', 'VMSize1StandardD8asV4', 'VMSize1StandardD8sV3', 'VMSize1StandardE16sV3', 'VMSize1StandardE32sV3', 'VMSize1StandardE4sV3', 'VMSize1StandardE8sV3', 'VMSize1StandardF16sV2', 'VMSize1StandardF32sV2', 'VMSize1StandardF4sV2', 'VMSize1StandardF8sV2'
|
||||
VMSize VMSize1 `json:"vmSize,omitempty"`
|
||||
// VMSize - The size of the worker VMs (immutable). Possible values include: 'StandardD16asV4', 'StandardD16sV3', 'StandardD2sV3', 'StandardD32asV4', 'StandardD32sV3', 'StandardD4asV4', 'StandardD4sV3', 'StandardD8asV4', 'StandardD8sV3', 'StandardE16sV3', 'StandardE32sV3', 'StandardE4sV3', 'StandardE8sV3', 'StandardF16sV2', 'StandardF32sV2', 'StandardF4sV2', 'StandardF8sV2'
|
||||
VMSize VMSize `json:"vmSize,omitempty"`
|
||||
// DiskSizeGB - The disk size of the worker VMs. Must be 128 or greater (immutable).
|
||||
DiskSizeGB *int32 `json:"diskSizeGB,omitempty"`
|
||||
// SubnetID - The Azure resource ID of the worker subnet (immutable).
|
||||
|
|
|
@ -71,12 +71,16 @@ func Run(outputDir string) error {
|
|||
|
||||
populateExamples(s.Paths)
|
||||
|
||||
err := define(s.Definitions, "github.com/Azure/ARO-RP/pkg/api/v20200430", "OpenShiftClusterList", "OpenShiftClusterCredentials")
|
||||
xmsEnumList := map[string]ModelAsString{
|
||||
"VMSize": true,
|
||||
}
|
||||
|
||||
err := define(s.Definitions, "github.com/Azure/ARO-RP/pkg/api/v20200430", xmsEnumList, "OpenShiftClusterList", "OpenShiftClusterCredentials")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = define(s.Definitions, "github.com/Azure/ARO-RP/pkg/api", "CloudError", "OperationList")
|
||||
err = define(s.Definitions, "github.com/Azure/ARO-RP/pkg/api", xmsEnumList, "CloudError", "OperationList")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -245,7 +245,24 @@ type Schema struct {
|
|||
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
|
||||
Example interface{} `json:"example,omitempty"`
|
||||
|
||||
ClientFlatten bool `json:"x-ms-client-flatten,omitempty"`
|
||||
ClientFlatten bool `json:"x-ms-client-flatten,omitempty"`
|
||||
XMSEnum *XMSEnum `json:"x-ms-enum,omitempty"`
|
||||
}
|
||||
|
||||
// XMSEnum is x-ms-enum swagger extension adding the ability to generate static enums
|
||||
// https://github.com/Azure/autorest/tree/master/docs/extensions#x-ms-enum
|
||||
type XMSEnum struct {
|
||||
Name string `json:"name"`
|
||||
ModelAsString bool `json:"modelAsString"`
|
||||
Values []XMSEnumValue `json:"values,omitempty"`
|
||||
}
|
||||
|
||||
// XMSEnumValue represents value for x-ms-enum
|
||||
// https://github.com/Azure/autorest/tree/master/docs/extensions#x-ms-enum
|
||||
type XMSEnumValue struct {
|
||||
Value interface{} `json:"value"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// XML represents an XML object
|
||||
|
|
|
@ -17,12 +17,15 @@ import (
|
|||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
type ModelAsString bool
|
||||
|
||||
type typeWalker struct {
|
||||
pkg *packages.Package
|
||||
enums map[types.Type][]interface{}
|
||||
pkg *packages.Package
|
||||
enums map[types.Type][]interface{}
|
||||
xmsEnumList map[string]ModelAsString
|
||||
}
|
||||
|
||||
func newTypeWalker(pkgname string) (*typeWalker, error) {
|
||||
func newTypeWalker(pkgname string, xmsEnumList map[string]ModelAsString) (*typeWalker, error) {
|
||||
pkgs, err := packages.Load(&packages.Config{Mode: packages.NeedSyntax | packages.NeedTypes | packages.NeedTypesInfo}, pkgname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -32,8 +35,9 @@ func newTypeWalker(pkgname string) (*typeWalker, error) {
|
|||
}
|
||||
|
||||
tw := &typeWalker{
|
||||
pkg: pkgs[0],
|
||||
enums: map[types.Type][]interface{}{},
|
||||
pkg: pkgs[0],
|
||||
enums: map[types.Type][]interface{}{},
|
||||
xmsEnumList: xmsEnumList,
|
||||
}
|
||||
|
||||
// populate enums: walk all types declared at package scope
|
||||
|
@ -151,6 +155,17 @@ func (tw *typeWalker) _define(definitions Definitions, t *types.Named) {
|
|||
s.Description = strings.Trim(path[len(path)-2].(*ast.GenDecl).Doc.Text(), "\n")
|
||||
s.Enum = tw.enums[t]
|
||||
|
||||
// Enum extensions allows non-breaking api changes
|
||||
// https://github.com/Azure/autorest/tree/master/docs/extensions#x-ms-enum
|
||||
c := strings.Split(t.String(), ".")
|
||||
name := c[(len(c) - 1)]
|
||||
if _, ok := tw.xmsEnumList[name]; ok {
|
||||
s.XMSEnum = &XMSEnum{
|
||||
ModelAsString: bool(tw.xmsEnumList[name]),
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
definitions[t.Obj().Name()] = s
|
||||
|
||||
for dep := range deps {
|
||||
|
@ -168,8 +183,8 @@ func (tw *typeWalker) define(definitions Definitions, name string) {
|
|||
}
|
||||
|
||||
// define adds a Definition for the named types in the given package
|
||||
func define(definitions Definitions, pkgname string, names ...string) error {
|
||||
th, err := newTypeWalker(pkgname)
|
||||
func define(definitions Definitions, pkgname string, xmsEnumList map[string]ModelAsString, names ...string) error {
|
||||
th, err := newTypeWalker(pkgname, xmsEnumList)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -61,6 +61,9 @@ except (SyntaxError, ImportError):
|
|||
from ._models import WorkerProfile
|
||||
from ._paged_models import OpenShiftClusterPaged
|
||||
from ._paged_models import OperationPaged
|
||||
from ._azure_red_hat_open_shift_client_enums import (
|
||||
VMSize,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'APIServerProfile',
|
||||
|
@ -84,4 +87,5 @@ __all__ = [
|
|||
'WorkerProfile',
|
||||
'OperationPaged',
|
||||
'OpenShiftClusterPaged',
|
||||
'VMSize',
|
||||
]
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# coding=utf-8
|
||||
# --------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft and contributors. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# Code generated by Microsoft (R) AutoRest Code Generator.
|
||||
# Changes may cause incorrect behavior and will be lost if the code is
|
||||
# regenerated.
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class VMSize(str, Enum):
|
||||
|
||||
standard_d16as_v4 = "Standard_D16as_v4"
|
||||
standard_d16s_v3 = "Standard_D16s_v3"
|
||||
standard_d2s_v3 = "Standard_D2s_v3"
|
||||
standard_d32as_v4 = "Standard_D32as_v4"
|
||||
standard_d32s_v3 = "Standard_D32s_v3"
|
||||
standard_d4as_v4 = "Standard_D4as_v4"
|
||||
standard_d4s_v3 = "Standard_D4s_v3"
|
||||
standard_d8as_v4 = "Standard_D8as_v4"
|
||||
standard_d8s_v3 = "Standard_D8s_v3"
|
||||
standard_e16s_v3 = "Standard_E16s_v3"
|
||||
standard_e32s_v3 = "Standard_E32s_v3"
|
||||
standard_e4s_v3 = "Standard_E4s_v3"
|
||||
standard_e8s_v3 = "Standard_E8s_v3"
|
||||
standard_f16s_v2 = "Standard_F16s_v2"
|
||||
standard_f32s_v2 = "Standard_F32s_v2"
|
||||
standard_f4s_v2 = "Standard_F4s_v2"
|
||||
standard_f8s_v2 = "Standard_F8s_v2"
|
|
@ -294,7 +294,7 @@ class MasterProfile(Model):
|
|||
'Standard_E8s_v3', 'Standard_F16s_v2', 'Standard_F32s_v2',
|
||||
'Standard_F4s_v2', 'Standard_F8s_v2'
|
||||
:type vm_size: str or
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.enum
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.VMSize
|
||||
:param subnet_id: The Azure resource ID of the master subnet (immutable).
|
||||
:type subnet_id: str
|
||||
"""
|
||||
|
@ -637,7 +637,7 @@ class WorkerProfile(Model):
|
|||
'Standard_E8s_v3', 'Standard_F16s_v2', 'Standard_F32s_v2',
|
||||
'Standard_F4s_v2', 'Standard_F8s_v2'
|
||||
:type vm_size: str or
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.enum
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.VMSize
|
||||
:param disk_size_gb: The disk size of the worker VMs. Must be 128 or
|
||||
greater (immutable).
|
||||
:type disk_size_gb: int
|
||||
|
|
|
@ -294,7 +294,7 @@ class MasterProfile(Model):
|
|||
'Standard_E8s_v3', 'Standard_F16s_v2', 'Standard_F32s_v2',
|
||||
'Standard_F4s_v2', 'Standard_F8s_v2'
|
||||
:type vm_size: str or
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.enum
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.VMSize
|
||||
:param subnet_id: The Azure resource ID of the master subnet (immutable).
|
||||
:type subnet_id: str
|
||||
"""
|
||||
|
@ -637,7 +637,7 @@ class WorkerProfile(Model):
|
|||
'Standard_E8s_v3', 'Standard_F16s_v2', 'Standard_F32s_v2',
|
||||
'Standard_F4s_v2', 'Standard_F8s_v2'
|
||||
:type vm_size: str or
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.enum
|
||||
~azure.mgmt.redhatopenshift.v2020_10_31_preview.models.VMSize
|
||||
:param disk_size_gb: The disk size of the worker VMs. Must be 128 or
|
||||
greater (immutable).
|
||||
:type disk_size_gb: int
|
||||
|
|
|
@ -735,7 +735,11 @@
|
|||
"Standard_F4s_v2",
|
||||
"Standard_F8s_v2"
|
||||
],
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"x-ms-enum": {
|
||||
"name": "VMSize",
|
||||
"modelAsString": true
|
||||
}
|
||||
},
|
||||
"Visibility": {
|
||||
"description": "Visibility represents visibility.",
|
||||
|
|
Загрузка…
Ссылка в новой задаче