MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / AddPrefixInAll

Method AddPrefixInAll

service/api-doc/service.go:109–126  ·  view source on GitHub ↗
(prefix string)

Source from the content-addressed store, hash-verified

107}
108
109func (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
128func (d *DocLoader) Marshal() ([]byte, error) {
129 result, err := d.openAPI3Doc.MarshalYAML()

Callers 1

UpdateDocMethod · 0.95

Calls 3

MapMethod · 0.65
DeleteMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected