@@ -12,14 +12,15 @@ import (
1212
1313const (
1414 OAS2 = "oas2"
15- OAS3 = "oas3"
15+ OAS3 = "oas3" // family format - matches all 3.x versions
16+ OAS30 = "oas3_0" // exact 3.0 only - does not match 3.1 or 3.2
1617 OAS31 = "oas3_1"
1718 OAS32 = "oas3_2"
1819)
1920
2021var OAS3_1Format = []string {OAS31 }
2122var OAS3_2Format = []string {OAS32 }
22- var AllExceptOAS3_1 = []string {OAS2 , OAS3 }
23+ var AllExceptOAS3_1 = []string {OAS2 , OAS30 } // uses OAS30 to avoid matching 3.1
2324var OAS3Format = []string {OAS3 }
2425var OAS3AllFormat = []string {OAS3 , OAS31 , OAS32 }
2526var OAS2Format = []string {OAS2 }
@@ -29,6 +30,7 @@ var AllFormats = []string{OAS3, OAS31, OAS32, OAS2}
2930// The oas3 format is treated as a "family" that covers oas3, oas3_1, and oas3_2.
3031// This allows rules with `formats: [oas3]` to match OpenAPI 3.0, 3.1, and 3.2 specs,
3132// which matches Spectral's behavior.
33+ // The oas3_0 format is an exact match for OpenAPI 3.0 only (does not match 3.1 or 3.2).
3234func FormatMatches (ruleFormat , specFormat string ) bool {
3335 if ruleFormat == specFormat {
3436 return true
@@ -37,6 +39,10 @@ func FormatMatches(ruleFormat, specFormat string) bool {
3739 if ruleFormat == OAS3 && (specFormat == OAS31 || specFormat == OAS32 ) {
3840 return true
3941 }
42+ // oas3_0 (exact 3.0) matches when spec is detected as oas3 (which means 3.0)
43+ if ruleFormat == OAS30 && specFormat == OAS3 {
44+ return true
45+ }
4046 return false
4147}
4248
0 commit comments