-
-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenAPI 3 externalDocs validation (#497)
- Loading branch information
Showing
7 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package openapi3 | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestExternalDocs_Validate(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
extDocs *ExternalDocs | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "url is missing", | ||
extDocs: &ExternalDocs{}, | ||
expectedErr: "url is required", | ||
}, | ||
{ | ||
name: "url is incorrect", | ||
extDocs: &ExternalDocs{URL: "ht tps://example.com"}, | ||
expectedErr: `url is incorrect: parse "ht tps://example.com": first path segment in URL cannot contain colon`, | ||
}, | ||
{ | ||
name: "ok", | ||
extDocs: &ExternalDocs{URL: "https://example.com"}, | ||
}, | ||
} | ||
for i := range tests { | ||
tt := tests[i] | ||
t.Run(tt.name, func(t *testing.T) { | ||
err := tt.extDocs.Validate(context.Background()) | ||
if tt.expectedErr != "" { | ||
require.EqualError(t, err, tt.expectedErr) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters