-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
Problem statement
I'm trying to generate a spec for annotated Go code. But in all structures, all fields are ignored during generation.
Steps to reproduce
- Create main package
main.go:
// Package petstore Petstore API.
//
// the purpose of this application is to provide an application
// that is using plain go code to define an API
//
// This should demonstrate all the possible comment annotations
// that are available to turn go code into a fully compliant swagger 2.0 spec
//
// Terms Of Service:
//
// there are no TOS at this moment, use at your own risk we take no responsibility
//
// Schemes: http, https
// Host: localhost
// BasePath: /v2
// Version: 0.0.1
// License: MIT http://opensource.org/licenses/MIT
// Contact: John Doe<john.doe@example.com> http://john.doe.com
//
// Consumes:
// - application/json
//
// Produces:
// - application/json
//
// swagger:meta
package main
import (
"time"
)
func main() {
}
// swagger:model pet
type Pet struct {
// The id of the pet.
//
// required: true
ID int64 `json:"id"`
// The name of the pet.
//
// required: true
// pattern: \w[\w-]+
// minimum length: 3
// maximum length: 50
Name string `json:"name"`
// The photo urls for the pet.
// This only accepts jpeg or png images.
//
// items pattern: \.(jpe?g|png)$
PhotoURLs []string `json:"photoUrls,omitempty"`
// The pet's birthday
//
// swagger:strfmt date
Birthday time.Time `json:"birthday"`
}
- Gen spec
swagger generate spec -o ./swagger.json --scan-models - Result spec
{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"swagger": "2.0",
"info": {
"description": "the purpose of this application is to provide an application\nthat is using plain go code to define an API\n\nThis should demonstrate all the possible comment annotations\nthat are available to turn go code into a fully compliant swagger 2.0 spec",
"title": "Petstore API.",
"termsOfService": "there are no TOS at this moment, use at your own risk we take no responsibility",
"contact": {
"name": "John Doe",
"url": "http://john.doe.com",
"email": "john.doe@example.com"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
},
"version": "0.0.1"
},
"host": "localhost",
"basePath": "/v2",
"paths": {},
"definitions": {
"pet": {
"x-go-name": "Pet",
"x-go-package": "pet"
}
}
}
Environment
swagger version: 0.30.2
go version: 1.16.3
OS: Ubuntu 18.04
Metadata
Metadata
Assignees
Labels
No labels