ParseComment parses comment for given comment string and returns error if error occurs.
(comment string, astFile *ast.File)
| 109 | |
| 110 | // ParseComment parses comment for given comment string and returns error if error occurs. |
| 111 | func (operation *Operation) ParseComment(comment string, astFile *ast.File) error { |
| 112 | commentLine := strings.TrimSpace(strings.TrimLeft(comment, "/")) |
| 113 | if len(commentLine) == 0 { |
| 114 | return nil |
| 115 | } |
| 116 | |
| 117 | fields := FieldsByAnySpace(commentLine, 2) |
| 118 | attribute := fields[0] |
| 119 | lowerAttribute := strings.ToLower(attribute) |
| 120 | var lineRemainder string |
| 121 | if len(fields) > 1 { |
| 122 | lineRemainder = fields[1] |
| 123 | } |
| 124 | switch lowerAttribute { |
| 125 | case stateAttr: |
| 126 | operation.ParseStateComment(lineRemainder) |
| 127 | case descriptionAttr: |
| 128 | operation.ParseDescriptionComment(lineRemainder) |
| 129 | case descriptionMarkdownAttr: |
| 130 | commentInfo, err := getMarkdownForTag(lineRemainder, operation.parser.markdownFileDir) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | operation.ParseDescriptionComment(string(commentInfo)) |
| 136 | case summaryAttr: |
| 137 | operation.Summary = lineRemainder |
| 138 | case idAttr: |
| 139 | operation.ID = lineRemainder |
| 140 | case tagsAttr: |
| 141 | operation.ParseTagsComment(lineRemainder) |
| 142 | case acceptAttr: |
| 143 | return operation.ParseAcceptComment(lineRemainder) |
| 144 | case produceAttr: |
| 145 | return operation.ParseProduceComment(lineRemainder) |
| 146 | case paramAttr: |
| 147 | return operation.ParseParamComment(lineRemainder, astFile) |
| 148 | case successAttr, failureAttr, responseAttr: |
| 149 | return operation.ParseResponseComment(lineRemainder, astFile) |
| 150 | case headerAttr: |
| 151 | return operation.ParseResponseHeaderComment(lineRemainder, astFile) |
| 152 | case routerAttr: |
| 153 | return operation.ParseRouterComment(lineRemainder, false) |
| 154 | case deprecatedRouterAttr: |
| 155 | return operation.ParseRouterComment(lineRemainder, true) |
| 156 | case securityAttr: |
| 157 | return operation.ParseSecurityComment(lineRemainder) |
| 158 | case deprecatedAttr: |
| 159 | operation.Deprecate() |
| 160 | case xCodeSamplesAttr: |
| 161 | return operation.ParseCodeSample(attribute, commentLine, lineRemainder) |
| 162 | default: |
| 163 | return operation.ParseMetadata(attribute, lowerAttribute, lineRemainder) |
| 164 | } |
| 165 | |
| 166 | return nil |
| 167 | } |
| 168 |