Skip to content

Commit

Permalink
update server struct
Browse files Browse the repository at this point in the history
Co-authored-by: juliens <[email protected]>
  • Loading branch information
lbenguigui and juliens authored Apr 29, 2024
1 parent 27fa94c commit e6cfb0e
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
8 changes: 6 additions & 2 deletions pkg/apis/hub/v1alpha1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ type OpenAPISpec struct {
type Override struct {
// +kubebuilder:validation:MaxItems=100
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:XValidation:message="must be a valid URL",rule="self.all(x, isURL(x))"
Servers []string `json:"servers"`
Servers []Server `json:"servers"`
}

type Server struct {
// +kubebuilder:validation:XValidation:message="must be a valid URL",rule="isURL(self)"
URL string `json:"url"`
}

// OperationSet gives a name to a set of matching OpenAPI operations.
Expand Down
13 changes: 9 additions & 4 deletions pkg/apis/hub/v1alpha1/crd/hub.traefik.io_apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,18 @@ spec:
properties:
servers:
items:
type: string
properties:
url:
type: string
x-kubernetes-validations:
- message: must be a valid URL
rule: isURL(self)
required:
- url
type: object
maxItems: 100
minItems: 1
type: array
x-kubernetes-validations:
- message: must be a valid URL
rule: self.all(x, isURL(x))
required:
- servers
type: object
Expand Down
13 changes: 9 additions & 4 deletions pkg/apis/hub/v1alpha1/crd/hub.traefik.io_apiversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,18 @@ spec:
properties:
servers:
items:
type: string
properties:
url:
type: string
x-kubernetes-validations:
- message: must be a valid URL
rule: isURL(self)
required:
- url
type: object
maxItems: 100
minItems: 1
type: array
x-kubernetes-validations:
- message: must be a valid URL
rule: self.all(x, isURL(x))
required:
- servers
type: object
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions pkg/validation/v1alpha1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,22 @@ spec:
path: /foo/..`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "spec.openApiSpec.path", BadValue: "string", Detail: "cannot contains '../'"}},
},
{
desc: "override server url is broken",
manifest: []byte(`
apiVersion: hub.traefik.io/v1alpha1
kind: API
metadata:
name: my-api
namespace: my-ns
spec:
openApiSpec:
path: /foo
override:
servers:
- url: aaa`),
wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "spec.openApiSpec.override.servers[0].url", BadValue: "string", Detail: "must be a valid URL"}},
},
{
desc: "valid: openApiSpec path with segment starting with ..",
manifest: []byte(`
Expand Down

0 comments on commit e6cfb0e

Please sign in to comment.