From e25a243c3a56d35f0e40fe8921fbf0761c5d9756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ho=C3=9F?= Date: Fri, 13 Sep 2024 05:52:25 +0200 Subject: [PATCH] switch to libopenapi MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kin-openapi sometimes produces weird output for the statefulset resource - and only for that. No clue why but libopenapi seems to be running stable. Tested this by running the code generator multiple times without getting different results Signed-off-by: Sebastian Hoß --- go.mod | 17 +- go.sum | 63 ++- tools/generator/main.go | 2 +- ...v3_namespacer.go => openapi_namespacer.go} | 0 ...cer_test.go => openapi_namespacer_test.go} | 0 ...{openapiv3_plural.go => openapi_plural.go} | 0 ...v3_converter.go => openapiv2_converter.go} | 88 ++-- ...penapiv3_filter.go => openapiv2_filter.go} | 8 +- tools/internal/generator/openapiv2_parser.go | 75 +-- .../generator/openapiv2_parser_test.go | 16 - .../generator/openapiv2_type_translator.go | 189 +++++++ .../openapiv2_validator_extractor.go | 168 ++++++ .../generator/openapiv3_type_translator.go | 148 ------ .../openapiv3_validator_extractor.go | 168 ------ .../generator/type_translator_test.go | 494 +++++++++--------- 15 files changed, 732 insertions(+), 704 deletions(-) rename tools/internal/generator/{openapiv3_namespacer.go => openapi_namespacer.go} (100%) rename tools/internal/generator/{openapiv3_namespacer_test.go => openapi_namespacer_test.go} (100%) rename tools/internal/generator/{openapiv3_plural.go => openapi_plural.go} (100%) rename tools/internal/generator/{openapiv3_converter.go => openapiv2_converter.go} (65%) rename tools/internal/generator/{openapiv3_filter.go => openapiv2_filter.go} (88%) create mode 100644 tools/internal/generator/openapiv2_type_translator.go create mode 100644 tools/internal/generator/openapiv2_validator_extractor.go delete mode 100644 tools/internal/generator/openapiv3_type_translator.go delete mode 100644 tools/internal/generator/openapiv3_validator_extractor.go diff --git a/go.mod b/go.mod index 8dcb3a21f..0e47ecd1e 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,11 @@ module github.com/metio/terraform-provider-k8s -go 1.22.0 +go 1.23.0 -toolchain go1.22.2 +toolchain go1.23.1 require ( - github.com/getkin/kin-openapi v0.127.0 github.com/gruntwork-io/terratest v0.47.1 github.com/hashicorp/terraform-plugin-docs v0.19.4 github.com/hashicorp/terraform-plugin-framework v1.11.0 @@ -16,7 +15,9 @@ require ( github.com/hashicorp/terraform-plugin-go v0.23.0 github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/iancoleman/strcase v0.3.0 + github.com/pb33f/libopenapi v0.18.1 github.com/stretchr/testify v1.9.0 + gopkg.in/yaml.v3 v3.0.1 k8s.io/apiextensions-apiserver v0.31.1 k8s.io/apimachinery v0.31.1 k8s.io/client-go v0.31.1 @@ -42,13 +43,16 @@ require ( github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go v1.44.122 // indirect + github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect + github.com/buger/jsonparser v1.1.1 // indirect github.com/chai2010/gettext-go v1.0.2 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect github.com/fatih/color v1.16.0 // indirect @@ -60,6 +64,7 @@ require ( github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.23.0 // indirect + github.com/go-test/deep v1.0.8 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect @@ -95,7 +100,6 @@ require ( github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/invopop/yaml v0.3.1 // indirect github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/josharian/intern v1.0.0 // indirect @@ -116,12 +120,10 @@ require ( github.com/moby/term v0.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect github.com/oklog/run v1.1.0 // indirect - github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -135,6 +137,8 @@ require ( github.com/ulikunitz/xz v0.5.11 // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect + github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect + github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd // indirect github.com/x448/float16 v0.8.4 // indirect github.com/xlab/treeprint v1.2.0 // indirect github.com/yuin/goldmark v1.7.1 // indirect @@ -167,7 +171,6 @@ require ( gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.31.1 // indirect k8s.io/cli-runtime v0.31.1 // indirect k8s.io/component-base v0.31.1 // indirect diff --git a/go.sum b/go.sum index e93c42722..cb3b0cc82 100644 --- a/go.sum +++ b/go.sum @@ -221,6 +221,8 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go v1.44.122 h1:p6mw01WBaNpbdP2xrisz5tIkcNwzj/HysobNoaAHjgo= github.com/aws/aws-sdk-go v1.44.122/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= @@ -231,6 +233,8 @@ github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwN github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -262,6 +266,9 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dprotaso/go-yit v0.0.0-20191028211022-135eb7262960/go.mod h1:9HQzr9D/0PGwMEbC3d5AB7oi67+h4TsQqItC1GVYG58= +github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097 h1:f5nA5Ys8RXqFXtKc0XofVRiuwNTuJzPIwTmbjLz9vj8= +github.com/dprotaso/go-yit v0.0.0-20240618133044-5a0af90af097/go.mod h1:FTAVyH6t+SlS97rv6EXRVuBDLkQqcIe/xQw9f4IFUI4= github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= @@ -286,10 +293,12 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= -github.com/getkin/kin-openapi v0.127.0 h1:Mghqi3Dhryf3F8vR370nN67pAERW+3a95vomb3MAREY= -github.com/getkin/kin-openapi v0.127.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-errors/errors v1.5.0 h1:/EuijeGOu7ckFxzhkj4CXJ8JaenxK7bKUxpPYqeLHqQ= github.com/go-errors/errors v1.5.0/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= @@ -315,6 +324,8 @@ github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= @@ -403,6 +414,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -496,6 +508,7 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc= github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= @@ -507,8 +520,6 @@ github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= -github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= @@ -584,22 +595,34 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= -github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= +github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= +github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= +github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro= github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= -github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= -github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= +github.com/pb33f/libopenapi v0.18.1 h1:Z2lWZ7A7G1u8gwx8A7IwuLwSToP8m55ZlzAagcLHh2U= +github.com/pb33f/libopenapi v0.18.1/go.mod h1:9ap4lXBHgxGyFwxtOfa+B1C3IQ0rvnqteqjJvJ11oiQ= github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= @@ -619,6 +642,7 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99 github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8= github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= @@ -654,8 +678,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tmccombs/hcl2json v0.3.3 h1:+DLNYqpWE0CsOQiEZu+OZm5ZBImake3wtITYxQ8uLFQ= github.com/tmccombs/hcl2json v0.3.3/go.mod h1:Y2chtz2x9bAeRTvSibVRVgbLJhLJXKlUeIvjeVdnm4w= -github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= -github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= @@ -666,6 +688,10 @@ github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21 github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= +github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk= +github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ= +github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd h1:dLuIF2kX9c+KknGJUdJi1Il1SDiTSK158/BB9kdgAew= +github.com/wk8/go-ordered-map/v2 v2.1.9-0.20240815153524-6ea36470d1bd/go.mod h1:DbzwytT4g/odXquuOCqroKvtxxldI4nb3nuesHF/Exo= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= @@ -769,6 +795,7 @@ golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -789,6 +816,7 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/ golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= @@ -801,6 +829,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -861,6 +890,7 @@ golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -870,7 +900,10 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -892,6 +925,7 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1001,6 +1035,7 @@ golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82u golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= @@ -1242,23 +1277,31 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20191026110619-0b21df46bc1d/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/tools/generator/main.go b/tools/generator/main.go index 664086cde..83a853a2f 100644 --- a/tools/generator/main.go +++ b/tools/generator/main.go @@ -33,7 +33,7 @@ func main() { var data []*generator.TemplateData if *parseOpenAPIv2 { openapi := generator.ParseOpenAPIv2Files(fmt.Sprintf("%s/openapi_v2/", *schemaDir)) - data = append(data, generator.ConvertOpenAPIv3(openapi)...) + data = append(data, generator.ConvertOpenAPIv2(openapi)...) } if *parseCRDv1 { crd := generator.ParseCRDv1Files(fmt.Sprintf("%s/crd_v1/", *schemaDir)) diff --git a/tools/internal/generator/openapiv3_namespacer.go b/tools/internal/generator/openapi_namespacer.go similarity index 100% rename from tools/internal/generator/openapiv3_namespacer.go rename to tools/internal/generator/openapi_namespacer.go diff --git a/tools/internal/generator/openapiv3_namespacer_test.go b/tools/internal/generator/openapi_namespacer_test.go similarity index 100% rename from tools/internal/generator/openapiv3_namespacer_test.go rename to tools/internal/generator/openapi_namespacer_test.go diff --git a/tools/internal/generator/openapiv3_plural.go b/tools/internal/generator/openapi_plural.go similarity index 100% rename from tools/internal/generator/openapiv3_plural.go rename to tools/internal/generator/openapi_plural.go diff --git a/tools/internal/generator/openapiv3_converter.go b/tools/internal/generator/openapiv2_converter.go similarity index 65% rename from tools/internal/generator/openapiv3_converter.go rename to tools/internal/generator/openapiv2_converter.go index 1ce633b32..37c93a778 100644 --- a/tools/internal/generator/openapiv3_converter.go +++ b/tools/internal/generator/openapiv2_converter.go @@ -7,43 +7,51 @@ package generator import ( "fmt" - "github.com/getkin/kin-openapi/openapi3" + "github.com/pb33f/libopenapi/datamodel/high/base" + v2high "github.com/pb33f/libopenapi/datamodel/high/v2" "k8s.io/utils/strings/slices" "sort" "strings" ) -func ConvertOpenAPIv3(schemas []map[string]*openapi3.SchemaRef) []*TemplateData { +func ConvertOpenAPIv2(schemas []v2high.Swagger) []*TemplateData { data := make([]*TemplateData, 0) for _, schema := range schemas { - for name, definition := range schema { - if supportedOpenAPIv3Object(name, definition) { + for name, definition := range schema.Definitions.Definitions.FromNewest() { + if supportedOpenAPIv2Object(name, definition) { namespaced := isNamespacedObject(name) - templateData := openAPIv3AsTemplateData(definition, namespaced) - data = append(data, templateData) + if templateData := openAPIv2AsTemplateData(definition, namespaced); templateData != nil { + data = append(data, templateData) + } } } } return data } -func openAPIv3AsTemplateData(definition *openapi3.SchemaRef, namespaced bool) *TemplateData { +func openAPIv2AsTemplateData(definition *base.SchemaProxy, namespaced bool) *TemplateData { var group string var version string var kind string - if gvkExt, ok := definition.Value.Extensions["x-kubernetes-group-version-kind"]; ok { - raw := gvkExt.([]interface{}) - gvk := raw[0].(map[string]interface{}) - group = gvk["group"].(string) - version = gvk["version"].(string) - kind = gvk["kind"].(string) + if node, present := definition.Schema().Extensions.Get("x-kubernetes-group-version-kind"); present { + var gvk []map[string]string + err := node.Decode(&gvk) + if err != nil { + fmt.Println(err) + return nil + } + group = gvk[0]["group"] + version = gvk[0]["version"] + kind = gvk[0]["kind"] + } else { + return nil } - schema := definition.Value + schema := definition.Schema() // remove manually managed or otherwise ignored properties - delete(schema.Properties, "metadata") - delete(schema.Properties, "status") - delete(schema.Properties, "apiVersion") - delete(schema.Properties, "kind") + schema.Properties.Delete("metadata") + schema.Properties.Delete("status") + schema.Properties.Delete("apiVersion") + schema.Properties.Delete("kind") imports := AdditionalImports{} typeName := resourceTypeName(group, kind, version) @@ -88,16 +96,16 @@ func openAPIv3AsTemplateData(definition *openapi3.SchemaRef, namespaced bool) *T TerraformModelType: terraformModelType(group, kind, version), AdditionalImports: imports, - Properties: openAPIv3Properties(schema, &imports, "", typeName), + Properties: openAPIv2Properties(schema, &imports, "", typeName), } } -func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, path string, terraformResourceName string) []*Property { +func openAPIv2Properties(schema *base.Schema, imports *AdditionalImports, path string, terraformResourceName string) []*Property { props := make([]*Property, 0) if schema != nil { - for name, prop := range schema.Properties { - if prop.Value != nil { + for name, prop := range schema.Properties.FromNewest() { + if prop.Schema() != nil { propPath := propertyPath(path, name) if ignored, ok := ignoredAttributes[terraformResourceName]; ok { if slices.Contains(ignored, propPath) { @@ -105,19 +113,21 @@ func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, pa } } + schemaType := prop.Schema().Type[0] + var nestedProperties []*Property - if prop.Value.Type.Is(openapi3.TypeArray) && prop.Value.Items != nil && prop.Value.Items.Value != nil && prop.Value.Items.Value.Type.Is(openapi3.TypeObject) { - nestedProperties = openAPIv3Properties(prop.Value.Items.Value, imports, propPath, terraformResourceName) - } else if prop.Value.Type.Is(openapi3.TypeObject) && prop.Value.AdditionalProperties.Schema != nil && prop.Value.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeObject) { - nestedProperties = openAPIv3Properties(prop.Value.AdditionalProperties.Schema.Value, imports, propPath, terraformResourceName) + if schemaType == "array" && prop.Schema().Items != nil && prop.Schema().Items.IsA() && prop.Schema().Items.A.Schema().Type[0] == "object" { + nestedProperties = openAPIv2Properties(prop.Schema().Items.A.Schema(), imports, propPath, terraformResourceName) + } else if schemaType == "object" && prop.Schema().AdditionalProperties != nil && prop.Schema().AdditionalProperties.IsA() && prop.Schema().AdditionalProperties.A.Schema().Type[0] == "object" { + nestedProperties = openAPIv2Properties(prop.Schema().AdditionalProperties.A.Schema(), imports, propPath, terraformResourceName) } else { - nestedProperties = openAPIv3Properties(prop.Value, imports, propPath, terraformResourceName) + nestedProperties = openAPIv2Properties(prop.Schema(), imports, propPath, terraformResourceName) } - attributeType, valueType, elementType, goType, customType := translateTypeWith(&openapiv3TypeTranslator{property: prop.Value}, terraformResourceName, propPath) + attributeType, valueType, elementType, goType, customType := translateTypeWith(&openapiv2TypeTranslator{property: prop.Schema()}, terraformResourceName, propPath) - validators := validatorsFor(&openapiv3ValidatorExtractor{ - property: prop.Value, + validators := validatorsFor(&openapiv2ValidatorExtractor{ + property: prop.Schema(), imports: imports, }, terraformResourceName, propPath, imports) @@ -135,7 +145,7 @@ func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, pa TerraformElementType: elementType, TerraformCustomType: customType, TerraformValueType: valueType, - Description: description(prop.Value.Description), + Description: description(prop.Schema().Description), Required: slices.Contains(schema.Required, name), Optional: !slices.Contains(schema.Required, name), Computed: false, @@ -152,11 +162,11 @@ func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, pa return props[i].Name < props[j].Name }) - if schema.MinProps > 0 && schema.MaxProps != nil { - min := schema.MinProps - max := schema.MaxProps + if schema.MinProperties != nil && schema.MaxProperties != nil { + minProperties := *schema.MinProperties + maxProperties := schema.MaxProperties - if min == 1 && *max == 1 { + if minProperties == 1 && *maxProperties == 1 { for _, outer := range props { var pathExpressions []string for _, inner := range props { @@ -170,10 +180,10 @@ func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, pa imports.Path = true } } - } else if schema.MinProps > 0 && schema.MaxProps == nil { - min := schema.MinProps + } else if schema.MinProperties != nil && schema.MaxProperties == nil { + minProperties := *schema.MinProperties - if min == 1 { + if minProperties == 1 { for _, outer := range props { var pathExpressions []string for _, inner := range props { @@ -186,7 +196,7 @@ func openAPIv3Properties(schema *openapi3.Schema, imports *AdditionalImports, pa addValidatorImports(outer, imports) imports.Path = true } - } else if min > 1 && min == uint64(len(props)) { + } else if minProperties > 1 && minProperties == int64(len(props)) { for _, prop := range props { prop.Required = true prop.Optional = false diff --git a/tools/internal/generator/openapiv3_filter.go b/tools/internal/generator/openapiv2_filter.go similarity index 88% rename from tools/internal/generator/openapiv3_filter.go rename to tools/internal/generator/openapiv2_filter.go index f7498ab67..dd3af3e4b 100644 --- a/tools/internal/generator/openapiv3_filter.go +++ b/tools/internal/generator/openapiv2_filter.go @@ -6,7 +6,7 @@ package generator import ( - "github.com/getkin/kin-openapi/openapi3" + "github.com/pb33f/libopenapi/datamodel/high/base" "k8s.io/utils/strings/slices" "strings" ) @@ -56,10 +56,10 @@ var supportedKubernetesApiObjects = []string{ "io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.APIService", } -func supportedOpenAPIv3Object(name string, definition *openapi3.SchemaRef) bool { +func supportedOpenAPIv2Object(name string, definition *base.SchemaProxy) bool { if !strings.HasPrefix(name, "io.k8s") || slices.Contains(supportedKubernetesApiObjects, name) { - if _, ok := definition.Value.Extensions["x-kubernetes-group-version-kind"]; ok { - if len(definition.Value.Properties) > 0 { + if gvk := definition.Schema().Extensions.GetOrZero("x-kubernetes-group-version-kind"); gvk != nil { + if definition.Schema().Properties.Len() > 0 { return true } } diff --git a/tools/internal/generator/openapiv2_parser.go b/tools/internal/generator/openapiv2_parser.go index 56cb414cc..da04fe90e 100644 --- a/tools/internal/generator/openapiv2_parser.go +++ b/tools/internal/generator/openapiv2_parser.go @@ -6,46 +6,37 @@ package generator import ( - "encoding/json" - "github.com/getkin/kin-openapi/openapi2" - "github.com/getkin/kin-openapi/openapi2conv" - "github.com/getkin/kin-openapi/openapi3" + "fmt" + "github.com/pb33f/libopenapi" + v2high "github.com/pb33f/libopenapi/datamodel/high/v2" "io/fs" "log" - "net/url" "os" "path/filepath" "strings" ) -var openapi3Loader *openapi3.Loader - -func init() { - openapi3Loader = openapi3.NewLoader() - openapi3Loader.IsExternalRefsAllowed = true - openapi3Loader.ReadFromURIFunc = func(loader *openapi3.Loader, uri *url.URL) ([]byte, error) { - return os.ReadFile(uri.Path) - } -} - -func ParseOpenAPIv2Files(basePath string) []map[string]*openapi3.SchemaRef { - schemas := make([]map[string]*openapi3.SchemaRef, 0) +func ParseOpenAPIv2Files(basePath string) []v2high.Swagger { + schemas := make([]v2high.Swagger, 0) err := filepath.WalkDir(basePath, func(path string, d fs.DirEntry, err error) error { if !d.IsDir() && strings.HasSuffix(path, ".json") { - openapiv2, parseErr := parseOpenAPIv2(path) - if parseErr != nil { - return parseErr + fileContent, readErr := os.ReadFile(path) + if readErr != nil { + return readErr } - openapiv3, conversionErr := convertV2toV3(openapiv2) - if conversionErr != nil { - return conversionErr + document, docErr := libopenapi.NewDocument(fileContent) + if docErr != nil { + return docErr } - resolveErr := resolveReferences(path, openapiv3) - if resolveErr != nil { - return resolveErr + docModel, errors := document.BuildV2Model() + if len(errors) > 0 { + for i := range errors { + fmt.Printf("error: %e\n", errors[i]) + } + panic(fmt.Sprintf("cannot create v3 model from document: %d errors reported", len(errors))) } - schemas = append(schemas, openapiv3.Components.Schemas) + schemas = append(schemas, docModel.Model) } return nil }) @@ -55,33 +46,3 @@ func ParseOpenAPIv2Files(basePath string) []map[string]*openapi3.SchemaRef { return schemas } - -func parseOpenAPIv2(filePath string) (*openapi2.T, error) { - input, err := os.ReadFile(filePath) - if err != nil { - return nil, err - } - var doc openapi2.T - err = json.Unmarshal(input, &doc) - if err != nil { - return nil, err - } - return &doc, nil - -} - -func resolveReferences(filePath string, v3 *openapi3.T) error { - err := openapi3Loader.ResolveRefsIn(v3, &url.URL{Path: filePath}) - if err != nil { - return err - } - return nil -} - -func convertV2toV3(doc *openapi2.T) (*openapi3.T, error) { - v3, err := openapi2conv.ToV3(doc) - if err != nil { - return nil, err - } - return v3, nil -} diff --git a/tools/internal/generator/openapiv2_parser_test.go b/tools/internal/generator/openapiv2_parser_test.go index 634be62b0..459cd11b7 100644 --- a/tools/internal/generator/openapiv2_parser_test.go +++ b/tools/internal/generator/openapiv2_parser_test.go @@ -14,19 +14,3 @@ func TestParseOpenAPIv2Files(t *testing.T) { assert.Greater(t, len(openapiv2Schemas), 0) } - -func TestKubernetesSchema(t *testing.T) { - openapiv2Schemas := ParseOpenAPIv2Files("../../../schemas/openapi_v2/") - kubernetesSchema := openapiv2Schemas[0] - statefulSet := kubernetesSchema["io.k8s.api.apps.v1.StatefulSet"] - spec := statefulSet.Value.Properties["spec"].Value - properties := spec.Properties - volumeClaimTemplates := properties["volumeClaimTemplates"].Value - templateProps := volumeClaimTemplates.Items.Value.Properties - templateSpec := templateProps["spec"].Value - templateSpecProps := templateSpec.Properties - - assert.Equal(t, 11, len(properties), "properties") - assert.Equal(t, 5, len(templateProps), "templateProps") - assert.Equal(t, 9, len(templateSpecProps), "templateSpecProps") -} diff --git a/tools/internal/generator/openapiv2_type_translator.go b/tools/internal/generator/openapiv2_type_translator.go new file mode 100644 index 000000000..71668c6af --- /dev/null +++ b/tools/internal/generator/openapiv2_type_translator.go @@ -0,0 +1,189 @@ +/* + * SPDX-FileCopyrightText: The terraform-provider-k8s Authors + * SPDX-License-Identifier: 0BSD + */ + +package generator + +import ( + "github.com/pb33f/libopenapi/datamodel/high/base" +) + +var _ typeTranslator = (*openapiv2TypeTranslator)(nil) + +type openapiv2TypeTranslator struct { + property *base.Schema +} + +func (t *openapiv2TypeTranslator) hasNoType() bool { + return t.property.Type == nil || len(t.property.Type) == 0 +} + +func (t *openapiv2TypeTranslator) isIntOrString() bool { + if t.property.Extensions != nil { + _, ok := t.property.Extensions.Get("x-kubernetes-int-or-string") + return ok || len(t.property.Type) > 0 && t.property.Type[0] == "string" && t.property.Format == "int-or-string" + } + return false +} + +func (t *openapiv2TypeTranslator) isBoolean() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "boolean" +} + +func (t *openapiv2TypeTranslator) isString() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "string" +} + +func (t *openapiv2TypeTranslator) isInteger() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "integer" +} + +func (t *openapiv2TypeTranslator) isNumber() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "number" +} + +func (t *openapiv2TypeTranslator) isFloat() bool { + return t.property.Format == "float" || t.property.Format == "double" +} + +func (t *openapiv2TypeTranslator) isArray() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "array" +} + +func (t *openapiv2TypeTranslator) isObject() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "object" +} + +func (t *openapiv2TypeTranslator) hasUnknownFields() bool { + if t.property.Extensions != nil { + _, ok := t.property.Extensions.Get("x-kubernetes-preserve-unknown-fields") + return ok + } + return false +} + +func (t *openapiv2TypeTranslator) hasProperties() bool { + return t.property.Properties != nil && t.property.Properties.Len() > 0 +} + +func (t *openapiv2TypeTranslator) hasOneOf() bool { + return len(t.property.OneOf) > 0 +} + +func (t *openapiv2TypeTranslator) isOneOfArray() bool { + for _, oneOf := range t.property.OneOf { + if oneOf.Schema().Type[0] == "array" { + return true + } + } + return false +} + +func (t *openapiv2TypeTranslator) isOneOfBoolean() bool { + for _, oneOf := range t.property.OneOf { + if oneOf.Schema().Type[0] == "boolean" { + return true + } + } + return false +} + +func (t *openapiv2TypeTranslator) isObjectWithAdditionalStringProperties() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "object" && + t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().Type[0] == "string" +} + +func (t *openapiv2TypeTranslator) isObjectWithAdditionalObjectProperties() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "object" && + t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().Type[0] == "object" +} + +func (t *openapiv2TypeTranslator) isObjectWithAdditionalArrayProperties() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "object" && + t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().Type[0] == "array" +} + +func (t *openapiv2TypeTranslator) isArrayWithObjectItems() bool { + return len(t.property.Type) > 0 && t.property.Type[0] == "array" && + t.property.Items != nil && + t.property.Items.IsA() && + t.property.Items.A.Schema().Type[0] == "object" +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveStringItems() bool { + return t.property.AdditionalProperties.A.Schema().Items != nil && + t.property.AdditionalProperties.A.Schema().Items.IsA() && + t.property.AdditionalProperties.A.Schema().Items.A.Schema().Type[0] == "string" +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveProperties() bool { + return t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A != nil && + t.property.AdditionalProperties.A.Schema() != nil && + t.property.AdditionalProperties.A.Schema().Properties != nil && + t.property.AdditionalProperties.A.Schema().Properties.Len() > 0 +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveUnknownFields() bool { + if t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A != nil && + t.property.AdditionalProperties.A.Schema() != nil && + t.property.AdditionalProperties.A.Schema().Extensions != nil { + _, ok := t.property.AdditionalProperties.A.Schema().Extensions.Get("x-kubernetes-preserve-unknown-fields") + return ok + } + return false +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveAdditionalStringProperties() bool { + return t.property.AdditionalProperties.A.Schema().AdditionalProperties != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Type[0] == "string" +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveAdditionalArrayProperties() bool { + return t.property.AdditionalProperties.A.Schema().AdditionalProperties != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Type[0] == "array" +} + +func (t *openapiv2TypeTranslator) additionalPropertiesHaveAdditionalPropertiesWithStringItems() bool { + return t.property.AdditionalProperties != nil && + t.property.AdditionalProperties.IsA() && + t.property.AdditionalProperties.A != nil && + t.property.AdditionalProperties.A.Schema() != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.IsA() && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema() != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Items != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Items.IsA() && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Items.A != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Items.A.Schema() != nil && + t.property.AdditionalProperties.A.Schema().AdditionalProperties.A.Schema().Items.A.Schema().Type[0] == "string" +} + +func (t *openapiv2TypeTranslator) itemsHaveUnknownFields() bool { + if t.property.Items != nil && t.property.Items.IsA() { + if t.property.Items.A.Schema().Extensions != nil { + _, ok := t.property.Items.A.Schema().Extensions.Get("x-kubernetes-preserve-unknown-fields") + return ok + } + } + return false +} + +func (t *openapiv2TypeTranslator) itemsHaveAdditionalStringProperties() bool { + return t.property.Items.A.Schema().AdditionalProperties != nil && + t.property.Items.A.Schema().AdditionalProperties.IsA() && + t.property.Items.A.Schema().AdditionalProperties.A.Schema().Type[0] == "string" +} diff --git a/tools/internal/generator/openapiv2_validator_extractor.go b/tools/internal/generator/openapiv2_validator_extractor.go new file mode 100644 index 000000000..70dc91dec --- /dev/null +++ b/tools/internal/generator/openapiv2_validator_extractor.go @@ -0,0 +1,168 @@ +/* + * SPDX-FileCopyrightText: The terraform-provider-k8s Authors + * SPDX-License-Identifier: 0BSD + */ + +package generator + +import ( + "fmt" + "github.com/pb33f/libopenapi/datamodel/high/base" + "gopkg.in/yaml.v3" + "strconv" +) + +var _ validatorExtractor = (*openapiv2ValidatorExtractor)(nil) + +type openapiv2ValidatorExtractor struct { + property *base.Schema + imports *AdditionalImports +} + +func (v *openapiv2ValidatorExtractor) integerWithMinimum() string { + if v.property.Type[0] == "integer" && v.property.Minimum != nil { + v.imports.Int64Validator = true + minimum := *v.property.Minimum + if v.property.ExclusiveMinimum.IsA() && v.property.ExclusiveMinimum.A { + minimum = minimum + float64(1) + } + return fmt.Sprintf("int64validator.AtLeast(%v)", minimum) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) integerWithMaximum() string { + if v.property.Type[0] == "integer" && v.property.Maximum != nil { + v.imports.Int64Validator = true + maximum := *v.property.Maximum + if v.property.ExclusiveMaximum.IsA() && v.property.ExclusiveMaximum.A { + maximum = maximum - float64(1) + } + return fmt.Sprintf("int64validator.AtMost(%v)", maximum) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) integerWithEnums() string { + if v.property.Type[0] == "integer" && len(v.property.Enum) > 0 { + v.imports.Int64Validator = true + enums := openapiv2IntEnums(v.property.Enum) + return fmt.Sprintf("int64validator.OneOf(%v)", concatEnums(enums)) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) numberWithMinimum() string { + if v.property.Type[0] == "number" && v.property.Minimum != nil { + v.imports.Float64Validator = true + minimum := *v.property.Minimum + if v.property.ExclusiveMinimum.IsA() && v.property.ExclusiveMinimum.A { + minimum = minimum + float64(1) + } + return fmt.Sprintf("float64validator.AtLeast(%v)", minimum) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) numberWithMaximum() string { + if v.property.Type[0] == "number" && v.property.Maximum != nil { + v.imports.Float64Validator = true + maximum := *v.property.Maximum + if v.property.ExclusiveMaximum.IsA() && v.property.ExclusiveMaximum.A { + maximum = maximum - float64(1) + } + return fmt.Sprintf("float64validator.AtMost(%v)", maximum) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) numberWithEnums() string { + if v.property.Type[0] == "number" && len(v.property.Enum) > 0 { + v.imports.Float64Validator = true + enums := openapiv2FloatEnums(v.property.Enum) + return fmt.Sprintf("float64validator.OneOf(%v)", concatEnums(enums)) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithByteFormat() string { + if v.property.Type[0] == "string" && v.property.Format == "byte" { + return "validators.Base64Validator()" + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithDateTimeFormat() string { + if v.property.Type[0] == "string" && v.property.Format == "date-time" { + return "validators.DateTime64Validator()" + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithMinimumLength() string { + if v.property.Type[0] == "string" && v.property.MinLength != nil { + v.imports.StringValidator = true + return fmt.Sprintf("stringvalidator.LengthAtLeast(%v)", v.property.MinLength) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithMaximumLength() string { + if v.property.Type[0] == "string" && v.property.MaxLength != nil { + v.imports.StringValidator = true + return fmt.Sprintf("stringvalidator.LengthAtMost(%v)", *v.property.MaxLength) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithEnums() string { + if v.property.Type[0] == "string" && len(v.property.Enum) > 0 { + v.imports.StringValidator = true + enums := openapiv2StringEnums(v.property.Enum) + return fmt.Sprintf("stringvalidator.OneOf(%s)", concatEnums(enums)) + } + return "" +} + +func (v *openapiv2ValidatorExtractor) stringWithPattern() string { + if v.property.Type[0] == "string" && v.property.Pattern != "" { + v.imports.Regexp = true + v.imports.StringValidator = true + return fmt.Sprintf(`stringvalidator.RegexMatches(regexp.MustCompile(%s), "")`, escapeRegexPattern(v.property.Pattern)) + } + return "" +} + +func openapiv2IntEnums(enums []*yaml.Node) []int64 { + var values []int64 + + for _, val := range enums { + if number, err := strconv.ParseInt(val.Value, 10, 64); err != nil { + values = append(values, number) + } + } + + return values +} + +func openapiv2FloatEnums(enums []*yaml.Node) []float64 { + var values []float64 + + for _, val := range enums { + if number, err := strconv.ParseFloat(val.Value, 10); err != nil { + values = append(values, number) + } + } + + return values +} + +func openapiv2StringEnums(enums []*yaml.Node) []string { + var values []string + + for _, val := range enums { + values = append(values, val.Value) + } + + return values +} diff --git a/tools/internal/generator/openapiv3_type_translator.go b/tools/internal/generator/openapiv3_type_translator.go deleted file mode 100644 index 745a5ddfc..000000000 --- a/tools/internal/generator/openapiv3_type_translator.go +++ /dev/null @@ -1,148 +0,0 @@ -/* - * SPDX-FileCopyrightText: The terraform-provider-k8s Authors - * SPDX-License-Identifier: 0BSD - */ - -package generator - -import ( - "github.com/getkin/kin-openapi/openapi3" -) - -var _ typeTranslator = (*openapiv3TypeTranslator)(nil) - -type openapiv3TypeTranslator struct { - property *openapi3.Schema -} - -func (t *openapiv3TypeTranslator) hasNoType() bool { - return t.property.Type == nil || len(t.property.Type.Slice()) == 0 -} - -func (t *openapiv3TypeTranslator) isIntOrString() bool { - _, ok := t.property.Extensions["x-kubernetes-int-or-string"] - return ok || t.property.Type.Is(openapi3.TypeString) && t.property.Format == "int-or-string" -} - -func (t *openapiv3TypeTranslator) isBoolean() bool { - return t.property.Type.Is(openapi3.TypeBoolean) -} - -func (t *openapiv3TypeTranslator) isString() bool { - return t.property.Type.Is(openapi3.TypeString) -} - -func (t *openapiv3TypeTranslator) isInteger() bool { - return t.property.Type.Is(openapi3.TypeInteger) -} - -func (t *openapiv3TypeTranslator) isNumber() bool { - return t.property.Type.Is(openapi3.TypeNumber) -} - -func (t *openapiv3TypeTranslator) isFloat() bool { - return t.property.Format == "float" || t.property.Format == "double" -} - -func (t *openapiv3TypeTranslator) isArray() bool { - return t.property.Type.Is(openapi3.TypeArray) -} - -func (t *openapiv3TypeTranslator) isObject() bool { - return t.property.Type.Is(openapi3.TypeObject) -} - -func (t *openapiv3TypeTranslator) hasUnknownFields() bool { - _, ok := t.property.Extensions["x-kubernetes-preserve-unknown-fields"] - return ok -} - -func (t *openapiv3TypeTranslator) hasProperties() bool { - return len(t.property.Properties) > 0 -} - -func (t *openapiv3TypeTranslator) hasOneOf() bool { - return len(t.property.OneOf) > 0 -} - -func (t *openapiv3TypeTranslator) isOneOfArray() bool { - for _, oneOf := range t.property.OneOf { - if oneOf.Value.Type.Is(openapi3.TypeArray) { - return true - } - } - return false -} - -func (t *openapiv3TypeTranslator) isOneOfBoolean() bool { - for _, oneOf := range t.property.OneOf { - if oneOf.Value.Type.Is(openapi3.TypeBoolean) { - return true - } - } - return false -} - -func (t *openapiv3TypeTranslator) isObjectWithAdditionalStringProperties() bool { - return t.property.Type.Is(openapi3.TypeObject) && - t.property.AdditionalProperties.Schema != nil && - t.property.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeString) -} - -func (t *openapiv3TypeTranslator) isObjectWithAdditionalObjectProperties() bool { - return t.property.Type.Is(openapi3.TypeObject) && - t.property.AdditionalProperties.Schema != nil && - t.property.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeObject) -} - -func (t *openapiv3TypeTranslator) isObjectWithAdditionalArrayProperties() bool { - return t.property.Type.Is(openapi3.TypeObject) && - t.property.AdditionalProperties.Schema != nil && - t.property.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeArray) -} - -func (t *openapiv3TypeTranslator) isArrayWithObjectItems() bool { - return t.property.Type.Is(openapi3.TypeArray) && - t.property.Items != nil && - t.property.Items.Value != nil && - t.property.Items.Value.Type.Is(openapi3.TypeObject) -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveStringItems() bool { - return t.property.AdditionalProperties.Schema.Value.Items != nil && - t.property.AdditionalProperties.Schema.Value.Items.Value.Type.Is(openapi3.TypeString) -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveProperties() bool { - return len(t.property.AdditionalProperties.Schema.Value.Properties) > 0 -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveUnknownFields() bool { - _, ok := t.property.AdditionalProperties.Schema.Value.Extensions["x-kubernetes-preserve-unknown-fields"] - return ok -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveAdditionalStringProperties() bool { - return t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema != nil && - t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeString) -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveAdditionalArrayProperties() bool { - return t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema != nil && - t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeArray) -} - -func (t *openapiv3TypeTranslator) additionalPropertiesHaveAdditionalPropertiesWithStringItems() bool { - return t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema.Value.Items != nil && - t.property.AdditionalProperties.Schema.Value.AdditionalProperties.Schema.Value.Items.Value.Type.Is(openapi3.TypeString) -} - -func (t *openapiv3TypeTranslator) itemsHaveUnknownFields() bool { - _, ok := t.property.Items.Value.Extensions["x-kubernetes-preserve-unknown-fields"] - return ok -} - -func (t *openapiv3TypeTranslator) itemsHaveAdditionalStringProperties() bool { - return t.property.Items.Value.AdditionalProperties.Schema != nil && - t.property.Items.Value.AdditionalProperties.Schema.Value.Type.Is(openapi3.TypeString) -} diff --git a/tools/internal/generator/openapiv3_validator_extractor.go b/tools/internal/generator/openapiv3_validator_extractor.go deleted file mode 100644 index e3ae36996..000000000 --- a/tools/internal/generator/openapiv3_validator_extractor.go +++ /dev/null @@ -1,168 +0,0 @@ -/* - * SPDX-FileCopyrightText: The terraform-provider-k8s Authors - * SPDX-License-Identifier: 0BSD - */ - -package generator - -import ( - "fmt" - "github.com/getkin/kin-openapi/openapi3" -) - -var _ validatorExtractor = (*openapiv3ValidatorExtractor)(nil) - -type openapiv3ValidatorExtractor struct { - property *openapi3.Schema - imports *AdditionalImports -} - -func (v *openapiv3ValidatorExtractor) integerWithMinimum() string { - if v.property.Type.Is(openapi3.TypeInteger) && v.property.Min != nil { - v.imports.Int64Validator = true - min := *v.property.Min - if v.property.ExclusiveMin { - min = min + float64(1) - } - return fmt.Sprintf("int64validator.AtLeast(%v)", min) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) integerWithMaximum() string { - if v.property.Type.Is(openapi3.TypeInteger) && v.property.Max != nil { - v.imports.Int64Validator = true - max := *v.property.Max - if v.property.ExclusiveMax { - max = max - float64(1) - } - return fmt.Sprintf("int64validator.AtMost(%v)", max) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) integerWithEnums() string { - if v.property.Type.Is(openapi3.TypeInteger) && len(v.property.Enum) > 0 { - v.imports.Int64Validator = true - enums := openapiIntEnums(v.property.Enum) - return fmt.Sprintf("int64validator.OneOf(%v)", concatEnums(enums)) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) numberWithMinimum() string { - if v.property.Type.Is(openapi3.TypeNumber) && v.property.Min != nil { - v.imports.Float64Validator = true - min := *v.property.Min - if v.property.ExclusiveMin { - min = min + float64(1) - } - return fmt.Sprintf("float64validator.AtLeast(%v)", min) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) numberWithMaximum() string { - if v.property.Type.Is(openapi3.TypeNumber) && v.property.Max != nil { - v.imports.Float64Validator = true - max := *v.property.Max - if v.property.ExclusiveMax { - max = max - float64(1) - } - return fmt.Sprintf("float64validator.AtMost(%v)", max) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) numberWithEnums() string { - if v.property.Type.Is(openapi3.TypeNumber) && len(v.property.Enum) > 0 { - v.imports.Float64Validator = true - enums := openapiFloatEnums(v.property.Enum) - return fmt.Sprintf("float64validator.OneOf(%v)", concatEnums(enums)) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithByteFormat() string { - if v.property.Type.Is(openapi3.TypeString) && v.property.Format == "byte" { - return "validators.Base64Validator()" - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithDateTimeFormat() string { - if v.property.Type.Is(openapi3.TypeString) && v.property.Format == "date-time" { - return "validators.DateTime64Validator()" - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithMinimumLength() string { - if v.property.Type.Is(openapi3.TypeString) && v.property.MinLength != 0 { - v.imports.StringValidator = true - return fmt.Sprintf("stringvalidator.LengthAtLeast(%v)", v.property.MinLength) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithMaximumLength() string { - if v.property.Type.Is(openapi3.TypeString) && v.property.MaxLength != nil { - v.imports.StringValidator = true - return fmt.Sprintf("stringvalidator.LengthAtMost(%v)", *v.property.MaxLength) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithEnums() string { - if v.property.Type.Is(openapi3.TypeString) && len(v.property.Enum) > 0 { - v.imports.StringValidator = true - enums := openapiStringEnums(v.property.Enum) - return fmt.Sprintf("stringvalidator.OneOf(%s)", concatEnums(enums)) - } - return "" -} - -func (v *openapiv3ValidatorExtractor) stringWithPattern() string { - if v.property.Type.Is(openapi3.TypeString) && v.property.Pattern != "" { - v.imports.Regexp = true - v.imports.StringValidator = true - return fmt.Sprintf(`stringvalidator.RegexMatches(regexp.MustCompile(%s), "")`, escapeRegexPattern(v.property.Pattern)) - } - return "" -} - -func openapiIntEnums(enums []interface{}) []int64 { - var values []int64 - - for _, val := range enums { - if number, ok := val.(int64); ok { - values = append(values, number) - } - } - - return values -} - -func openapiFloatEnums(enums []interface{}) []float64 { - var values []float64 - - for _, val := range enums { - if number, ok := val.(float64); ok { - values = append(values, number) - } - } - - return values -} - -func openapiStringEnums(enums []interface{}) []string { - var values []string - - for _, val := range enums { - if str, ok := val.(string); ok { - values = append(values, str) - } - } - - return values -} diff --git a/tools/internal/generator/type_translator_test.go b/tools/internal/generator/type_translator_test.go index 472597f14..f61b6ed2f 100644 --- a/tools/internal/generator/type_translator_test.go +++ b/tools/internal/generator/type_translator_test.go @@ -5,8 +5,10 @@ package generator import ( - "github.com/getkin/kin-openapi/openapi3" + "github.com/pb33f/libopenapi/datamodel/high/base" + "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "testing" ) @@ -488,9 +490,9 @@ func TestTranslateTypeWith(t *testing.T) { customType: "", }, - "OpenAPIv3/empty": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{}, + "OpenAPIv2/empty": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{}, }, attributeType: "UNKNOWN", elementType: "UNKNOWN", @@ -498,10 +500,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "UNKNOWN", customType: "UNKNOWN", }, - "OpenAPIv3/string": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, + "OpenAPIv2/string": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"string"}, }, }, attributeType: "schema.StringAttribute", @@ -510,10 +512,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "string", customType: "", }, - "OpenAPIv3/boolean": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"boolean"}, + "OpenAPIv2/boolean": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"boolean"}, }, }, attributeType: "schema.BoolAttribute", @@ -522,10 +524,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "bool", customType: "", }, - "OpenAPIv3/integer": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"integer"}, + "OpenAPIv2/integer": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"integer"}, }, }, attributeType: "schema.Int64Attribute", @@ -534,10 +536,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "int64", customType: "", }, - "OpenAPIv3/number": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"number"}, + "OpenAPIv2/number": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"number"}, }, }, attributeType: "schema.Float64Attribute", @@ -546,10 +548,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "float64", customType: "", }, - "OpenAPIv3/float-float": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"number"}, + "OpenAPIv2/float-float": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"number"}, Format: "float", }, }, @@ -559,10 +561,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "float64", customType: "", }, - "OpenAPIv3/float-double": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"number"}, + "OpenAPIv2/float-double": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"number"}, Format: "double", }, }, @@ -572,10 +574,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "float64", customType: "", }, - "OpenAPIv3/array": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, + "OpenAPIv2/array": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"array"}, }, }, attributeType: "schema.ListAttribute", @@ -584,10 +586,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "[]string", customType: "", }, - "OpenAPIv3/object": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, + "OpenAPIv2/object": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, }, }, attributeType: "schema.MapAttribute", @@ -596,13 +598,11 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]string", customType: "", }, - "OpenAPIv3/object-with-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - Properties: openapi3.Schemas{ - "first": {}, - }, + "OpenAPIv2/object-with-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + Properties: orderedmap.FromPairs(orderedmap.NewPair("first", &base.SchemaProxy{})), }, }, attributeType: "schema.SingleNestedAttribute", @@ -611,14 +611,14 @@ func TestTranslateTypeWith(t *testing.T) { goType: "struct", customType: "", }, - "OpenAPIv3/array-of-objects": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - Items: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - }, + "OpenAPIv2/array-of-objects": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"array"}, + Items: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{Type: []string{"object"}}), + B: false, }, }, }, @@ -628,17 +628,17 @@ func TestTranslateTypeWith(t *testing.T) { goType: "[]struct", customType: "", }, - "OpenAPIv3/array-of-objects-with-unknown-fields": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - Items: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - Extensions: map[string]interface{}{ - "x-kubernetes-preserve-unknown-fields": "true", - }, - }, + "OpenAPIv2/array-of-objects-with-unknown-fields": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"array"}, + Items: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-preserve-unknown-fields", &yaml.Node{Value: "true"})), + }), + B: false, }, }, }, @@ -648,21 +648,23 @@ func TestTranslateTypeWith(t *testing.T) { goType: "[]map[string]string", customType: "", }, - "OpenAPIv3/array-of-objects-with-additional-string-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - Items: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, + "OpenAPIv2/array-of-objects-with-additional-string-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"array"}, + Items: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), + B: false, }, - }, + }), + B: false, }, }, }, @@ -672,16 +674,16 @@ func TestTranslateTypeWith(t *testing.T) { goType: "[]map[string]string", customType: "", }, - "OpenAPIv3/object-with-additional-array-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - }, - }, + "OpenAPIv2/object-with-additional-array-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"array"}, + }), + B: false, }, }, }, @@ -691,21 +693,23 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]string", customType: "", }, - "OpenAPIv3/object-with-additional-array-properties-having-string-items": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - Items: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, + "OpenAPIv2/object-with-additional-array-properties-having-string-items": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"array"}, + Items: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), + B: false, }, - }, + }), + B: false, }, }, }, @@ -715,16 +719,16 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string][]string", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - }, - }, + "OpenAPIv2/object-with-additional-object-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + }), + B: false, }, }, }, @@ -734,23 +738,23 @@ func TestTranslateTypeWith(t *testing.T) { goType: "struct", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties-having-additional-string-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, - }, + "OpenAPIv2/object-with-additional-object-properties-having-additional-string-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), + B: false, }, - }, + }), + B: false, }, }, }, @@ -760,23 +764,23 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]map[string]string", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties-having-additional-array-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - }, - }, - }, + "OpenAPIv2/object-with-additional-object-properties-having-additional-array-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"array"}, + }), + B: false, }, - }, + }), + B: false, }, }, }, @@ -786,19 +790,17 @@ func TestTranslateTypeWith(t *testing.T) { goType: "struct", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties-having-unknown-fields": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - Extensions: map[string]interface{}{ - "x-kubernetes-preserve-unknown-fields": "true", - }, - }, - }, + "OpenAPIv2/object-with-additional-object-properties-having-unknown-fields": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-preserve-unknown-fields", &yaml.Node{Value: "true"})), + }), + B: false, }, }, }, @@ -808,22 +810,18 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]string", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties-having-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - Extensions: map[string]interface{}{ - "x-kubernetes-preserve-unknown-fields": "true", - }, - Properties: openapi3.Schemas{ - "firs": {}, - }, - }, - }, + "OpenAPIv2/object-with-additional-object-properties-having-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-preserve-unknown-fields", &yaml.Node{Value: "true"})), + Properties: orderedmap.FromPairs(orderedmap.NewPair("first", base.CreateSchemaProxy(&base.Schema{}))), + }), + B: false, }, }, }, @@ -833,28 +831,30 @@ func TestTranslateTypeWith(t *testing.T) { goType: "struct", customType: "", }, - "OpenAPIv3/object-with-additional-object-properties-having-additional-array-properties-with-string-items": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - Items: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, - }, + "OpenAPIv2/object-with-additional-object-properties-having-additional-array-properties-with-string-items": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"array"}, + Items: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), + B: false, }, - }, + }), + B: false, }, - }, + }), + B: false, }, }, }, @@ -864,16 +864,16 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]map[string][]string", customType: "", }, - "OpenAPIv3/object-with-additional-string-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"object"}, - AdditionalProperties: openapi3.AdditionalProperties{ - Schema: &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, + "OpenAPIv2/object-with-additional-string-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"object"}, + AdditionalProperties: &base.DynamicValue[*base.SchemaProxy, bool]{ + N: 0, + A: base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), + B: false, }, }, }, @@ -883,15 +883,13 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]string", customType: "", }, - "OpenAPIv3/one-of-array": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - OneOf: openapi3.SchemaRefs{ - &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"array"}, - }, - }, + "OpenAPIv2/one-of-array": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + OneOf: []*base.SchemaProxy{ + base.CreateSchemaProxy(&base.Schema{ + Type: []string{"array"}, + }), }, }, }, @@ -901,15 +899,13 @@ func TestTranslateTypeWith(t *testing.T) { goType: "[]string", customType: "", }, - "OpenAPIv3/one-of-boolean": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - OneOf: openapi3.SchemaRefs{ - &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"boolean"}, - }, - }, + "OpenAPIv2/one-of-boolean": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + OneOf: []*base.SchemaProxy{ + base.CreateSchemaProxy(&base.Schema{ + Type: []string{"boolean"}, + }), }, }, }, @@ -919,15 +915,13 @@ func TestTranslateTypeWith(t *testing.T) { goType: "bool", customType: "", }, - "OpenAPIv3/one-of-string": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - OneOf: openapi3.SchemaRefs{ - &openapi3.SchemaRef{ - Value: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, - }, - }, + "OpenAPIv2/one-of-string": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + OneOf: []*base.SchemaProxy{ + base.CreateSchemaProxy(&base.Schema{ + Type: []string{"string"}, + }), }, }, }, @@ -937,12 +931,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "UNKNOWN", customType: "UNKNOWN", }, - "OpenAPIv3/unknown-fields": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Extensions: map[string]interface{}{ - "x-kubernetes-preserve-unknown-fields": "true", - }, + "OpenAPIv2/unknown-fields": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-preserve-unknown-fields", &yaml.Node{Value: "true"})), }, }, attributeType: "schema.MapAttribute", @@ -951,15 +943,11 @@ func TestTranslateTypeWith(t *testing.T) { goType: "map[string]string", customType: "", }, - "OpenAPIv3/unknown-fields-with-properties": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Extensions: map[string]interface{}{ - "x-kubernetes-preserve-unknown-fields": "true", - }, - Properties: openapi3.Schemas{ - "firs": {}, - }, + "OpenAPIv2/unknown-fields-with-properties": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-preserve-unknown-fields", &yaml.Node{Value: "true"})), + Properties: orderedmap.FromPairs(orderedmap.NewPair("first", base.CreateSchemaProxy(&base.Schema{}))), }, }, attributeType: "schema.SingleNestedAttribute", @@ -968,12 +956,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "struct", customType: "", }, - "OpenAPIv3/int-or-string": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Extensions: map[string]interface{}{ - "x-kubernetes-int-or-string": "true", - }, + "OpenAPIv2/int-or-string": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Extensions: orderedmap.FromPairs(orderedmap.NewPair("x-kubernetes-int-or-string", &yaml.Node{Value: "true"})), }, }, attributeType: "schema.StringAttribute", @@ -982,10 +968,10 @@ func TestTranslateTypeWith(t *testing.T) { goType: "string", customType: "", }, - "OpenAPIv3/string-or-int": { - translator: &openapiv3TypeTranslator{ - property: &openapi3.Schema{ - Type: &openapi3.Types{"string"}, + "OpenAPIv2/string-or-int": { + translator: &openapiv2TypeTranslator{ + property: &base.Schema{ + Type: []string{"string"}, Format: "int-or-string", }, }, @@ -996,7 +982,7 @@ func TestTranslateTypeWith(t *testing.T) { customType: "", }, "custom-types/kyverno_io_cluster_policy_v1/spec.rules.context.apiCall.data.value": { - translator: &openapiv3TypeTranslator{}, + translator: &openapiv2TypeTranslator{}, attributeType: "schema.StringAttribute", elementType: "", valueType: "types.String",