config.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package swagger
  2. import (
  3. "net/http"
  4. "reflect"
  5. "github.com/emicklei/go-restful"
  6. )
  7. // PostBuildDeclarationMapFunc can be used to modify the api declaration map.
  8. type PostBuildDeclarationMapFunc func(apiDeclarationMap *ApiDeclarationList)
  9. // MapSchemaFormatFunc can be used to modify typeName at definition time.
  10. type MapSchemaFormatFunc func(typeName string) string
  11. // MapModelTypeNameFunc can be used to return the desired typeName for a given
  12. // type. It will return false if the default name should be used.
  13. type MapModelTypeNameFunc func(t reflect.Type) (string, bool)
  14. type Config struct {
  15. // url where the services are available, e.g. http://localhost:8080
  16. // if left empty then the basePath of Swagger is taken from the actual request
  17. WebServicesUrl string
  18. // path where the JSON api is avaiable , e.g. /apidocs
  19. ApiPath string
  20. // [optional] path where the swagger UI will be served, e.g. /swagger
  21. SwaggerPath string
  22. // [optional] location of folder containing Swagger HTML5 application index.html
  23. SwaggerFilePath string
  24. // api listing is constructed from this list of restful WebServices.
  25. WebServices []*restful.WebService
  26. // will serve all static content (scripts,pages,images)
  27. StaticHandler http.Handler
  28. // [optional] on default CORS (Cross-Origin-Resource-Sharing) is enabled.
  29. DisableCORS bool
  30. // Top-level API version. Is reflected in the resource listing.
  31. ApiVersion string
  32. // If set then call this handler after building the complete ApiDeclaration Map
  33. PostBuildHandler PostBuildDeclarationMapFunc
  34. // Swagger global info struct
  35. Info Info
  36. // [optional] If set, model builder should call this handler to get addition typename-to-swagger-format-field conversion.
  37. SchemaFormatHandler MapSchemaFormatFunc
  38. // [optional] If set, model builder should call this handler to retrieve the name for a given type.
  39. ModelTypeNameHandler MapModelTypeNameFunc
  40. }