1

I am trying to use go-swagger for generating docs but the generated swagger.yaml file doesn't have properties of a response object.

Project Structure:

cmd
   -api
       -main.go
       -movies.go
internal
    -data
       -movies.go

cmd/api/movies.go

//swagger:route GET /movies movies listMovies
// Returns a list of movies 
// responses: 
//  200: moviesResponse 
func (app *application) createMovieHandler(w http.ResponseWriter, r*http.Request{                     
//code here 
}
// A list of movies
//swagger:response
type MoviesResponse struct {
    // All movies in system
    //
    //in: body
    Body    []data.Movie
}

internal/data/movies.go

type Movie struct {
ID int64 `json:"id"`
CreatedAt time.Time `json:"-"`
Title   string `json:"title"`
Year    int32 `json:"year,omitempty"`
Runtime int32 `json:"runtime,omitempty"`
Genres  []string `json:"genres,omitempty"`
Version int32 `json:"version"`
}

Generated swagger.yaml

paths:
    /movies:
        get:
            description: Returns a list of movies
            operationId: listMovies
            responses:
                "200":
                    $ref: '#/responses/moviesResponse'
            tags:
                - movies
responses:
    MoviesResponse:
        description: A list of movies
        schema:
            items: {}
            type: array

Command (at root of project) : swagger generate spec -w ./cmd/api/ -o ./swagger.yaml --scan-models

Note: I have already checked No properties generated in json file for swagger:response but didn't find anything which can help.

Tahir Ali
  • 155
  • 1
  • 2
  • 10

1 Answers1

0

I was seeing something similar, and I think it's because my local swagger command was pointing to an out of date version. You might want to try deleting your local swagger command and re-installing the latest binaries (https://goswagger.io/install.html).

pgier
  • 107
  • 1
  • 10