ApplyPattern handles the POST /patterns/:name/apply route @Summary Apply pattern with variables @Description Apply a pattern with variable substitution @Tags patterns @Accept json @Produce json @Param name path string true "Pattern name" @Param request body PatternApplyRequest true "Pattern applicat
(c *gin.Context)
| 96 | // @Security ApiKeyAuth |
| 97 | // @Router /patterns/{name}/apply [post] |
| 98 | func (h *PatternsHandler) ApplyPattern(c *gin.Context) { |
| 99 | name := c.Param("name") |
| 100 | if rejectUnsafePatternName(c, name) { |
| 101 | return |
| 102 | } |
| 103 | |
| 104 | var request PatternApplyRequest |
| 105 | if err := c.ShouldBindJSON(&request); err != nil { |
| 106 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | // Merge query parameters with request body variables (body takes precedence) |
| 111 | variables := make(map[string]string) |
| 112 | for key, values := range c.Request.URL.Query() { |
| 113 | if len(values) > 0 { |
| 114 | variables[key] = values[0] |
| 115 | } |
| 116 | } |
| 117 | maps.Copy(variables, request.Variables) |
| 118 | |
| 119 | pattern, err := h.patterns.GetApplyVariables(name, variables, request.Input) |
| 120 | if err != nil { |
| 121 | storageError(c, err) |
| 122 | return |
| 123 | } |
| 124 | c.JSON(http.StatusOK, pattern) |
| 125 | } |
nothing calls this directly
no test coverage detected