| 107 | } |
| 108 | |
| 109 | func (d *DocLoader) AddPrefixInAll(prefix string) error { |
| 110 | prefix = strings.TrimSpace(prefix) |
| 111 | if prefix == "" || d.openAPI3Doc == nil || d.openAPI3Doc.Paths == nil { |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | prefix = fmt.Sprintf("/%s/", strings.Trim(prefix, "/")) |
| 116 | for path, item := range d.openAPI3Doc.Paths.Map() { |
| 117 | path = strings.TrimSpace(path) |
| 118 | if strings.HasPrefix(path, prefix) { |
| 119 | continue |
| 120 | } |
| 121 | newPath := fmt.Sprintf("%s%s", prefix, strings.TrimPrefix(path, "/")) |
| 122 | d.openAPI3Doc.Paths.Delete(path) |
| 123 | d.openAPI3Doc.Paths.Set(newPath, item) |
| 124 | } |
| 125 | return nil |
| 126 | } |
| 127 | |
| 128 | func (d *DocLoader) Marshal() ([]byte, error) { |
| 129 | result, err := d.openAPI3Doc.MarshalYAML() |