Skip to content

Commit 318efea

Browse files
authored
Merge pull request #110 from yangcao77/805-fix-v2index-sample
only apply filter if value is set
2 parents f06d84c + af1c47a commit 318efea

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

index/server/pkg/server/endpoint.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -331,34 +331,36 @@ func buildIndexAPIResponse(c *gin.Context, wantV1Index bool) {
331331
} else {
332332
minSchemaVersion := c.Query("minSchemaVersion")
333333
maxSchemaVersion := c.Query("maxSchemaVersion")
334-
// check if schema version filters are in valid format.
335-
// should only include major and minor version. e.g. 2.1
336-
if minSchemaVersion != "" {
337-
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, minSchemaVersion)
338-
if !matched || err != nil {
339-
c.JSON(http.StatusInternalServerError, gin.H{
340-
"status": fmt.Sprintf("minSchemaVersion %s is not valid, should only include major and minor version. %v", minSchemaVersion, err),
341-
})
342-
return
334+
if maxSchemaVersion != "" || minSchemaVersion != "" {
335+
// check if schema version filters are in valid format.
336+
// should only include major and minor version. e.g. 2.1
337+
if minSchemaVersion != "" {
338+
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, minSchemaVersion)
339+
if !matched || err != nil {
340+
c.JSON(http.StatusInternalServerError, gin.H{
341+
"status": fmt.Sprintf("minSchemaVersion %s is not valid, should only include major and minor version. %v", minSchemaVersion, err),
342+
})
343+
return
344+
}
343345
}
344-
}
345-
if maxSchemaVersion != "" {
346-
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, maxSchemaVersion)
347-
if !matched || err != nil {
346+
if maxSchemaVersion != "" {
347+
matched, err := regexp.MatchString(`^([2-9])\.([0-9]+)$`, maxSchemaVersion)
348+
if !matched || err != nil {
349+
c.JSON(http.StatusInternalServerError, gin.H{
350+
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, should only include major and minor version. %v", maxSchemaVersion, err),
351+
})
352+
return
353+
}
354+
}
355+
356+
index, err = util.FilterDevfileSchemaVersion(index, minSchemaVersion, maxSchemaVersion)
357+
if err != nil {
348358
c.JSON(http.StatusInternalServerError, gin.H{
349-
"status": fmt.Sprintf("maxSchemaVersion %s is not valid, should only include major and minor version. %v", maxSchemaVersion, err),
359+
"status": fmt.Sprintf("failed to apply schema version filter: %v", err),
350360
})
351361
return
352362
}
353363
}
354-
355-
index, err = util.FilterDevfileSchemaVersion(index, minSchemaVersion, maxSchemaVersion)
356-
if err != nil {
357-
c.JSON(http.StatusInternalServerError, gin.H{
358-
"status": fmt.Sprintf("failed to apply schema version filter: %v", err),
359-
})
360-
return
361-
}
362364
}
363365
// Filter the index if archs has been requested
364366
if len(archs) > 0 {

0 commit comments

Comments
 (0)