Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/v1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ type PreciseHostname string
// scheme (e.g., "http" or "spiffe") and a scheme-specific-part. URIs that
// include an authority MUST include a fully qualified domain name or
// IP address as the host.

// <gateway:util:excludeFromCRD> The below regex is taken from the regex section in RFC 3986 with a slight modification to enforce a full URI and not relative. </gateway:util:excludeFromCRD>
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^(([^:/?#]+):)(//([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?`
Expand Down
15 changes: 15 additions & 0 deletions pkg/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,21 @@ func gatewayTweaks(channel string, props map[string]apiext.JSONSchemaProps) map[
jsonProps.Description = strings.ReplaceAll(jsonProps.Description, endTag, "")
}

// Comments within "gateway:util:excludeFromCRD" tag is not included in the generated CRD and all trailing \n operators before
// and after the tags are removed and replaced with three \n operators.
startTag = "<gateway:util:excludeFromCRD>"
endTag = "</gateway:util:excludeFromCRD>"
regexPattern = `\n*` + regexp.QuoteMeta(startTag) + `(?s:(.*?))` + regexp.QuoteMeta(endTag) + `\n*`
if strings.Contains(jsonProps.Description, "<gateway:util:excludeFromCRD>") {
re := regexp.MustCompile(regexPattern)
match := re.FindStringSubmatch(jsonProps.Description)
if len(match) != 2 {
log.Fatalf("Invalid <gateway:util:excludeFromCRD> tag for %s", name)
}
modifiedDescription := re.ReplaceAllString(jsonProps.Description, "\n\n\n")
jsonProps.Description = modifiedDescription
}

if numValid < numExpressions {
fmt.Printf("Description: %s\n", jsonProps.Description)
log.Fatalf("Found %d Gateway validation expressions, but only %d were valid", numExpressions, numValid)
Expand Down