goai_config.go 1.6 KB

12345678910111213141516171819202122232425262728293031
  1. // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
  2. //
  3. // This Source Code Form is subject to the terms of the MIT License.
  4. // If a copy of the MIT was not distributed with this file,
  5. // You can obtain one at https://github.com/gogf/gf.
  6. package goai
  7. // Config provides extra configuration feature for OpenApiV3 implements.
  8. type Config struct {
  9. ReadContentTypes []string // ReadContentTypes specifies the default MIME types for consuming if MIME types are not configured.
  10. WriteContentTypes []string // WriteContentTypes specifies the default MIME types for producing if MIME types are not configured.
  11. CommonRequest interface{} // Common request structure for all paths.
  12. CommonRequestDataField string // Common request field name to be replaced with certain business request structure. Eg: `Data`, `Request.`.
  13. CommonResponse interface{} // Common response structure for all paths.
  14. CommonResponseDataField string // Common response field name to be replaced with certain business response structure. Eg: `Data`, `Response.`.
  15. IgnorePkgPath bool // Ignores package name for schema name.
  16. }
  17. // fillWithDefaultValue fills configuration object of `oai` with default values if these are not configured.
  18. func (oai *OpenApiV3) fillWithDefaultValue() {
  19. if oai.OpenAPI == "" {
  20. oai.OpenAPI = `3.0.0`
  21. }
  22. if len(oai.Config.ReadContentTypes) == 0 {
  23. oai.Config.ReadContentTypes = defaultReadContentTypes
  24. }
  25. if len(oai.Config.WriteContentTypes) == 0 {
  26. oai.Config.WriteContentTypes = defaultWriteContentTypes
  27. }
  28. }