I would hesitate to call this a bug in gofmt. Go released new godoc
features as part of Go 1.19, along with reformatting of comments. Those
features were entirely intentional.

The decision made in the go-swagger project to place its comments alongside
godoc comment blocks was a risky one in case of upstream changes like this
one.

That said, maybe a no-reformat directive is in order.

On Wed, Aug 17, 2022, 7:35 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>
> .
>

-- 
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/CALJzkY8xo3yw5rVHSCAtst6Jr8KtGZj9%2Bdrohib1DWBCo_bHWg%40mail.gmail.com.

Reply via email to