As K. Alex Mills noted gofmt was intentionally enhanced which you can see in the release notes: https://go.dev/blog/go1.19. Specifically, the new support for lists is what's causing you heartburn. See https://go.dev/doc/comment for details. Note this text in that document:
Analysis in 2022 found that only 3% of doc comments in public Go modules > were reformatted at all by the draft Go 1.19 gofmt. Limiting ourselves to > those comments, about 87% of gofmt’s reformattings preserved the structure > that a person would infer from reading the comment; about 6% were tripped > up by these kinds of unindented lists, unindented multiline shell commands, > and unindented brace-delimited code blocks. It seems to me the go-swagger project will need to adapt to the new rules for how Go doc comments are handled by gofmt. On Wed, Aug 17, 2022 at 5:36 PM crod...@gmail.com <crodr...@gmail.com> wrote: > Hi, > > I have a codebase which uses go-swagger > <https://github.com/go-swagger/go-swagger> to parse comments in Go files > and generate swagger documentation. > > I recently upgraded to Go 1.19, and found that gofmt’s behavior formats > comments in a way which breaks go-swagger. > > For example this code: > > package somepackage > import ( > "encoding/json" > "fmt" > "io" > "net/http" > "strconv" > "time" > > ) > // SomeFunc do something//// swagger:operation POST /api/v1/somefunc > someFunc//// Do something//// ---// x-codeSamples:// - lang: 'curl'// > source: |// curl -u "${LOGIN}:${PASSWORD}" -d '{"key": "value"}' -X > POST "https://{host}/api/v1/somefunc"// curl -u > "${LOGIN}:${PASSWORD}" -d '{"key2": "value2"}' -X POST > "https://{host}/api/v1/somefunc"// responses:// '200':// description: > "Some func"// examples:// application/json:// key: "value"// > '400':// $ref: "#/responses/ErrorResponse"// '503':// $ref: > "#/responses/ErrorResponse"func SomeFunct(rw http.ResponseWriter, req > *http.Request) { > /// do something > } > > Gets reformatted as: > > package somepackage > > import ( > "encoding/json" > "fmt" > "io" > "net/http" > "strconv" > "time" > ) > > // SomeFunc do something > // > // swagger:operation POST /api/v1/somefunc someFunc > // > // # Do something > // > // --- > // x-codeSamples: > // - lang: 'curl' > // source: | > // curl -u "${LOGIN}:${PASSWORD}" -d '{"key": "value"}' -X POST > "https://{host}/api/v1/somefunc" > // curl -u "${LOGIN}:${PASSWORD}" -d '{"key2": "value2"}' -X POST > "https://{host}/api/v1/somefunc" > // > // responses: > // > // '200': > // description: "Some func" > // examples: > // application/json: > // key: "value" > // '400': > // $ref: "#/responses/ErrorResponse" > // '503': > // $ref: "#/responses/ErrorResponse" > func SomeFunct(rw http.ResponseWriter, req *http.Request) { > /// do something > } > > Specifically the lines under source: | > get re-indented in such a way > that the YAML is invalid, and go-swagger fails to process this file. > > This issue has been raised in the go-swagger community: > https://github.com/go-swagger/go-swagger/issues/2759 > > but I don’t think this can be worked around in go-swagger, since > go-swagger parses the .go files after they have been formatted by gofmt > and written to disk. > > Can anyone suggest a possible workaround, or a bugfix to gofmt? > Thanks. > > — > Craig > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/d6abf372-4cb1-4070-8a62-d4c6c6ba6bcen%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/d6abf372-4cb1-4070-8a62-d4c6c6ba6bcen%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD9-2%2B6bgb0wjV7V9fJXaCf7KdRssih832Vc5SaCaspxzw%40mail.gmail.com.