@@ -13,21 +13,21 @@ import (
13
13
)
14
14
15
15
var (
16
- // ErrGenerateSwagger throws when fails the marshalling of the swagger struct.
17
- ErrGenerateSwagger = errors .New ("fail to generate swagger " )
18
- // ErrValidatingSwagger throws when given swagger params are not correct.
19
- ErrValidatingSwagger = errors .New ("fails to validate swagger " )
16
+ // ErrGenerateOAS throws when fails the marshalling of the swagger struct.
17
+ ErrGenerateOAS = errors .New ("fail to generate openapi " )
18
+ // ErrValidatingOAS throws when given openapi params are not correct.
19
+ ErrValidatingOAS = errors .New ("fails to validate openapi " )
20
20
)
21
21
22
22
const (
23
- // DefaultJSONDocumentationPath is the path of the swagger documentation in json format.
23
+ // DefaultJSONDocumentationPath is the path of the openapi documentation in json format.
24
24
DefaultJSONDocumentationPath = "/documentation/json"
25
- // DefaultYAMLDocumentationPath is the path of the swagger documentation in yaml format.
25
+ // DefaultYAMLDocumentationPath is the path of the openapi documentation in yaml format.
26
26
DefaultYAMLDocumentationPath = "/documentation/yaml"
27
27
defaultOpenapiVersion = "3.0.0"
28
28
)
29
29
30
- // Router handle the api router and the swagger schema.
30
+ // Router handle the api router and the openapi schema.
31
31
// api router supported out of the box are:
32
32
// - gorilla mux
33
33
type Router [HandlerFunc , Route any ] struct {
@@ -55,7 +55,7 @@ type Options struct {
55
55
func NewRouter [HandlerFunc , Route any ](router apirouter.Router [HandlerFunc , Route ], options Options ) (* Router [HandlerFunc , Route ], error ) {
56
56
swagger , err := generateNewValidOpenapi (options .Openapi )
57
57
if err != nil {
58
- return nil , fmt .Errorf ("%w: %s" , ErrValidatingSwagger , err )
58
+ return nil , fmt .Errorf ("%w: %s" , ErrValidatingOAS , err )
59
59
}
60
60
61
61
var ctx = options .Context
@@ -132,18 +132,18 @@ func generateNewValidOpenapi(swagger *openapi3.T) (*openapi3.T, error) {
132
132
// expose the generated swagger
133
133
func (r Router [_ , _ ]) GenerateAndExposeOpenapi () error {
134
134
if err := r .swaggerSchema .Validate (r .context ); err != nil {
135
- return fmt .Errorf ("%w: %s" , ErrValidatingSwagger , err )
135
+ return fmt .Errorf ("%w: %s" , ErrValidatingOAS , err )
136
136
}
137
137
138
138
jsonSwagger , err := r .swaggerSchema .MarshalJSON ()
139
139
if err != nil {
140
- return fmt .Errorf ("%w json marshal: %s" , ErrGenerateSwagger , err )
140
+ return fmt .Errorf ("%w json marshal: %s" , ErrGenerateOAS , err )
141
141
}
142
142
r .router .AddRoute (http .MethodGet , r .jsonDocumentationPath , r .router .SwaggerHandler ("application/json" , jsonSwagger ))
143
143
144
144
yamlSwagger , err := yaml .JSONToYAML (jsonSwagger )
145
145
if err != nil {
146
- return fmt .Errorf ("%w yaml marshal: %s" , ErrGenerateSwagger , err )
146
+ return fmt .Errorf ("%w yaml marshal: %s" , ErrGenerateOAS , err )
147
147
}
148
148
r .router .AddRoute (http .MethodGet , r .yamlDocumentationPath , r .router .SwaggerHandler ("text/plain" , yamlSwagger ))
149
149
0 commit comments