MCPcopy
hub / github.com/swaggo/swag / ParseCodeSample

Method ParseCodeSample

operation.go:170–192  ·  view source on GitHub ↗

ParseCodeSample parse code sample.

(attribute, _, lineRemainder string)

Source from the content-addressed store, hash-verified

168
169// ParseCodeSample parse code sample.
170func (operation *Operation) ParseCodeSample(attribute, _, lineRemainder string) error {
171 if lineRemainder == "file" {
172 data, err := getCodeExampleForSummary(operation.Summary, operation.codeExampleFilesDir)
173 if err != nil {
174 return err
175 }
176
177 var valueJSON interface{}
178
179 err = json.Unmarshal(data, &valueJSON)
180 if err != nil {
181 return fmt.Errorf("annotation %s need a valid json value", attribute)
182 }
183
184 // don't use the method provided by spec lib, because it will call toLower() on attribute names, which is wrongly
185 operation.Extensions[attribute[1:]] = valueJSON
186
187 return nil
188 }
189
190 // Fallback into existing logic
191 return operation.ParseMetadata(attribute, strings.ToLower(attribute), lineRemainder)
192}
193
194// ParseStateComment parse state comment.
195func (operation *Operation) ParseStateComment(lineRemainder string) {

Callers 1

ParseCommentMethod · 0.95

Calls 2

ParseMetadataMethod · 0.95
getCodeExampleForSummaryFunction · 0.85

Tested by

no test coverage detected