Skip to content

Go 1.19 change breaks swagger #2759

@stgraber

Description

@stgraber

There's this upstream change golang/go#51082 that's meant to improve godoc by allowing for additional syntax in Go comments. Unfortunately it means that running gofmt as many projects do automatically ends up breaking the Swagger comments leading to a broken schema.

Here is the result on a single file in our codebase:

stgraber@dakara:~/data/code/lxc/lxd (stgraber/master)$ gofmt -s -w lxd/instance_delete.go
stgraber@dakara:~/data/code/lxc/lxd (stgraber/master)$ make update-api
(cd / ; go install -v -x github.com/go-swagger/go-swagger/cmd/swagger@latest)
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/cmd/swagger/@v/list
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/@v/list
# get https://proxy.golang.org/github.com/go-swagger/@v/list
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/cmd/@v/list
# get https://proxy.golang.org/github.com/@v/list: 410 Gone (0.255s)
# get https://proxy.golang.org/github.com/go-swagger/@v/list: 410 Gone (0.402s)
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/cmd/@v/list: 410 Gone (0.408s)
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/cmd/swagger/@v/list: 410 Gone (0.409s)
# get https://proxy.golang.org/github.com/go-swagger/go-swagger/@v/list: 200 OK (0.422s)
WORK=/tmp/go-build2036726384
swagger generate spec -o doc/rest-api.yaml -w ./lxd -m

stgraber@dakara:~/data/code/lxc/lxd (stgraber/master)$ git diff lxd/instance_delete.go
diff --git a/lxd/instance_delete.go b/lxd/instance_delete.go
index d28248b89..1a457eace 100644
--- a/lxd/instance_delete.go
+++ b/lxd/instance_delete.go
@@ -14,7 +14,7 @@ import (
 
 // swagger:operation DELETE /1.0/instances/{name} instances instance_delete
 //
-// Delete an instance
+// # Delete an instance
 //
 // Deletes a specific instance.
 //
@@ -23,21 +23,24 @@ import (
 // ---
 // produces:
 //   - application/json
+//
 // parameters:
 //   - in: query
 //     name: project
 //     description: Project name
 //     type: string
 //     example: default
+//
 // responses:
-//   "202":
-//     $ref: "#/responses/Operation"
-//   "400":
-//     $ref: "#/responses/BadRequest"
-//   "403":
-//     $ref: "#/responses/Forbidden"
-//   "500":
-//     $ref: "#/responses/InternalServerError"
+//
+//     "202":
+//       $ref: "#/responses/Operation"
+//     "400":
+//       $ref: "#/responses/BadRequest"
+//     "403":
+//       $ref: "#/responses/Forbidden"
+//     "500":
+//       $ref: "#/responses/InternalServerError"
 func instanceDelete(d *Daemon, r *http.Request) response.Response {
        instanceType, err := urlInstanceTypeDetect(r)
        if err != nil {

stgraber@dakara:~/data/code/lxc/lxd (stgraber/master)$ git diff HEAD doc/rest-api.yaml 
diff --git a/doc/rest-api.yaml b/doc/rest-api.yaml
index b8d69f0e2..7d9c1dd0c 100644
--- a/doc/rest-api.yaml
+++ b/doc/rest-api.yaml
@@ -7678,16 +7678,7 @@ paths:
         type: string
       produces:
       - application/json
-      responses:
-        "202":
-          $ref: '#/responses/Operation'
-        "400":
-          $ref: '#/responses/BadRequest'
-        "403":
-          $ref: '#/responses/Forbidden'
-        "500":
-          $ref: '#/responses/InternalServerError'
-      summary: Delete an instance
+      summary: '# Delete an instance'
       tags:
       - instances
     get:

I don't know if it's something that needs addressing in upstream gofmt or something that the parser in go-swagger needs to just learn to deal with, but as it stands, Go 1.19 is going to cause a whole bunch of breakage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions