Skip to content

Commit

Permalink
Exposing Components 'IdentifierRegExp' to enable customized component…
Browse files Browse the repository at this point in the history
… key #270 (#273)
  • Loading branch information
heyvister committed Nov 22, 2020
1 parent c928496 commit 254be12
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions openapi3/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,13 @@ func (components *Components) Validate(c context.Context) (err error) {

const identifierPattern = `^[a-zA-Z0-9._-]+$`

var identifierRegExp = regexp.MustCompile(identifierPattern)
// IdentifierRegExp verifies whether Component object key matches 'identifierPattern' pattern, according to OapiAPI v3.x.0.
// Hovever, to be able supporting legacy OpenAPI v2.x, there is a need to customize above pattern in orde not to fail
// converted v2-v3 validation
var IdentifierRegExp = regexp.MustCompile(identifierPattern)

func ValidateIdentifier(value string) error {
if identifierRegExp.MatchString(value) {
if IdentifierRegExp.MatchString(value) {
return nil
}
return fmt.Errorf("identifier %q is not supported by OpenAPIv3 standard (regexp: %q)", value, identifierPattern)
Expand Down

0 comments on commit 254be12

Please sign in to comment.