github.com/djarvur/go-swagger@v0.18.0/scan/doc.go (about)

     1  // Copyright 2015 go-swagger maintainers
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //    http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  /*Package scan provides a scanner for go files that produces a swagger spec document.
    16  
    17  You give it a main file and it will parse all the files that are required by that main
    18  package to produce a swagger specification.
    19  
    20  To use you can add a go:generate comment to your main file for example:
    21  
    22  		//go:generate swagger generate spec
    23  
    24  The following annotations exist:
    25  
    26  swagger:meta
    27  
    28  The swagger:meta annotation flags a file as source for metadata about the API.
    29  This is typically a doc.go file with your package documentation.
    30  
    31  You can specify a Consumes and Produces key which has a new content type on each line
    32  Schemes is a tag that is required and allows for a comma separated string composed of:
    33  http, https, ws or wss
    34  
    35  Host and BasePath can be specified but those values will be defaults,
    36  they should get substituted when serving the swagger spec.
    37  
    38  Default parameters and responses are not supported at this stage, for those you can edit the template json.
    39  
    40  swagger:strfmt [name]
    41  
    42  A swagger:strfmt annotation names a type as a string formatter. The name is mandatory and that is
    43  what will be used as format name for this particular string format.
    44  String formats should only be used for very well known formats.
    45  
    46  swagger:model [?model name]
    47  
    48  A swagger:model annotation optionally gets a model name as extra data on the line.
    49  when this appears anywhere in a comment for a struct, then that struct becomes a schema
    50  in the definitions object of swagger.
    51  
    52  The struct gets analyzed and all the collected models are added to the tree.
    53  The refs are tracked separately so that they can be renamed later on.
    54  
    55  When this annotation is found to be on an interface instead of a struct, the properties are provided
    56  through exported nullary methods.
    57  
    58  A property of an interface model can have a Discriminator: true annotation to mark that field as
    59  the field that will contain the discriminator value.
    60  
    61  swagger:route [method] [path pattern] [operation id] [?tag1 tag2 tag3]
    62  
    63  A swagger:route annotation links a path to a method.
    64  This operation gets a unique id, which is used in various places as method name.
    65  One such usage is in method names for client generation for example.
    66  
    67  Because there are many routers available, this tool does not try to parse the paths
    68  you provided to your routing library of choice. So you have to specify your path pattern
    69  yourself in valid swagger syntax.
    70  
    71  swagger:params [operationid1 operationid2]
    72  
    73  Links a struct to one or more operations. The params in the resulting swagger spec can be composed of several structs.
    74  There are no guarantees given on how property name overlaps are resolved when several structs apply to the same operation.
    75  This tag works very similarly to the swagger:model tag except that it produces valid parameter objects instead of schema
    76  objects.
    77  
    78  swagger:response [?response name]
    79  
    80  Reads a struct decorated with swagger:response and uses that information to fill up the headers and the schema for a response.
    81  A swagger:route can specify a response name for a status code and then the matching response will be used for that operation in the swagger definition.
    82  */
    83  package scan