Skip to content

Commit

Permalink
*parse correctly parameters from url.
Browse files Browse the repository at this point in the history
Signed-off-by: Software Developer <[email protected]>
  • Loading branch information
dsuhinin committed Oct 8, 2024
1 parent c3bcff4 commit 62e2993
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 403 deletions.
7 changes: 6 additions & 1 deletion magefiles/generate/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ var routeParameterRegex = regexp.MustCompile(`<[^>]+:([^>]+)>`)
// Get the safe path to use in Fiber registration.
func (e Endpoint) GetFiberPath() string {
// e.Path cannot be trusted, it could be something like /mlflow-artifacts/artifacts/<path:artifact_path>
// Which would need to converted to /mlflow-artifacts/artifacts/:path
// which would need to be converted to /mlflow-artifacts/artifacts/:path
path := routeParameterRegex.ReplaceAllStringFunc(e.Path, func(s string) string {
parts := strings.Split(s, ":")

return ":" + strings.Trim(parts[0], "< ")
})

// or it could be something like /mlflow/traces/{request_id}/tags
// which would need to be converted to /mlflow/traces/:request_id/tags
path = strings.ReplaceAll(path, "{", ":")
path = strings.ReplaceAll(path, "}", "")

return path
}

Expand Down
7 changes: 4 additions & 3 deletions magefiles/generate/query_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ func addQueryAnnotation(generatedGoFile string) error {
tagValue := field.Tag.Value

hasQuery := strings.Contains(tagValue, "query:")
hasParams := strings.Contains(tagValue, "params:")
hasValidate := strings.Contains(tagValue, "validate:")
validationKey := fmt.Sprintf("%s_%s", typeSpec.Name, field.Names[0])
validationRule, needsValidation := validations[validationKey]

if hasQuery && (!needsValidation || needsValidation && hasValidate) {
if hasParams && hasQuery && (!needsValidation || needsValidation && hasValidate) {
continue
}

// With opening ` tick
newTag := tagValue[0 : len(tagValue)-1]

matches := jsonFieldTagRegexp.FindStringSubmatch(tagValue)
if len(matches) > 0 && !hasQuery {
if len(matches) > 0 && !hasQuery && !hasParams {
// Modify the tag here
// The json annotation could be something like `json:"key,omitempty"`
// We only want the key part, the `omitempty` is not relevant for the query annotation
Expand All @@ -68,7 +69,7 @@ func addQueryAnnotation(generatedGoFile string) error {
key = strings.Split(key, ",")[0]
}
// Add query annotation
newTag += fmt.Sprintf(" query:\"%s\"", key)
newTag += fmt.Sprintf(" query:\"%s\" params:\"%s\"", key, key)
}

if needsValidation {
Expand Down
2 changes: 1 addition & 1 deletion pkg/contract/service/tracking.g.go

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

21 changes: 2 additions & 19 deletions pkg/lib/tracking.g.go

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

40 changes: 20 additions & 20 deletions pkg/protos/artifacts/mlflow_artifacts.pb.go

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

Loading

0 comments on commit 62e2993

Please sign in to comment.