go-swagger

command
v0.0.0-...-37abd50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 2 Imported by: 0

README

swagger cmd

This command runs the go test bench with swagger.

generated code

In addition to the code that go-swagger generates, we have a regen command which generates additional code and swagger.yml. This is done to retain a single source of truth across all frameworks and to minimize the complexity of future enhancements. The intent is to

  • retain a single source of truth across all frameworks
  • decouple frameworks and vulnerabilities, such that addition of either requires minimal or no changes to existing code.
direct editing of swagger.yml

Warning Only use this for experiments, not for PRs to Contrast-Security-OSS/go-test-bench. PRs should update the generator or its inputs.

Do not run ./regen if you have edits to swagger.yml (or ../../pkg/serveswagger/generatedInit.go) that you wish to keep, as it will overwrite both files. Instead, run swagger directly:

cd cmd/go-swagger/restapi
swagger generate server --target ../../go-swagger --name SwaggerBench --spec ../swagger.yml --principal 'interface{}' --exclude-main

Note Swagger itself will still overwrite any changes to the .go files that are marked do not edit and that were generated by swagger - any changes to those files would need to wait unti after swagger ran.

updating spec and code with regen (preferred method)

Additions, deletions, or changes to any common.Route will require use of ./regen. Doing so will overwrite

  • swagger.yml
  • swagger's generated go code (cmd/go-swagger/restapi/...)
  • its own generated go code (pkg/serveswagger/generatedInit.go)

Run regen via go generate ./.... Alternately, cd cmd/go-swagger/restapi; go run ../regen/regen.go.

what does regen do?

in order:

  • loads route data
  • generates swagger.yml
    • standard swagger spec file
    • derived from template under regen/data
  • runs swagger to re-generate code
  • generates generatedInit.go
    • boilerplate, derived from template under regen/data
    • contains one function, generatedInit(), which is called from serveswagger.Setup()
    • ties our one-size-fits-all route handler serveswagger.RouteHandler() to each swagger endpoint

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Command regen generates go-swagger yaml and handlers from route data.
Command regen generates go-swagger yaml and handlers from route data.
Package restapi swagger-bench
Package restapi swagger-bench

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL