Changelog
v1.2.0
A bug-fix + DX release. Closes the four bugs that produced wrong specs at runtime (self-referential structs, ignored ContentType, silent bearer fallback, dormant type-change detector) and finally ships the public API the README has been documenting all along.
go get github.com/gopackx/open-swag-go@v1.2.0Breaking change
- The
Responsestruct is renamed toResponseSpecsoopenswag.Response(desc, schema)can be the constructor the README documents. Field-keyed literals insideopenswag.Responses{ ... }keep compiling unchanged — only bareopenswag.Response{...}literals need to migrate (useopenswag.Response("desc", T{})oropenswag.ResponseSpec{...}).
Fixed
- fix(schema): Self-referential structs (e.g.
type Category struct { Children []Category }) no longer cause a stack overflow during spec generation.fromReflectTypenow threads a visiting-type set; back-edges return a bounded object schema with a description note. - fix(openapi):
RequestBody.ContentTypeis now honored end-to-end.multipart/form-dataandapplication/x-www-form-urlencodedbodies appear in the spec under the correct media type instead of being silently rewritten toapplication/json. Addedpkg/spec.RequestBody.WithContent(mediaType, schema)to back the new behavior. - fix(openapi): Custom security scheme names referenced from
Endpoint.Securityare no longer silently coerced intohttp-bearer. Unknown names are now omitted fromcomponents.securitySchemesso typos surface immediately. Register custom schemes explicitly via the newConfig.Auth.Schemesfield. - fix(versioning):
compareOperationsnow produces entries forBreakingTypeChanged. Changes to a request-body field's JSONtype/formatand changes to a parameter's schema type are flagged as breaking, with migration hints. Also fixed a latent index-out-of-range bug ingetMigrationGuide(short descriptions could panic the migration formatter).
New public API
The README has documented these helpers for several versions, but the package never exposed them — Quick Start examples could not compile. They exist now:
- Request body builders:
Body(schema),BodyWithDesc(desc, schema),FormBody(schema),FormURLEncodedBody(schema)— all return*RequestBodyready to drop intoEndpoint.RequestBody. - Response constructor:
Response(desc, schema...)returns aResponseSpec. Pass the schema as the second argument or omit it for empty responses (e.g. 204 No Content). The type aliasResponses = map[int]ResponseSpecexists for the decorator-style map literal. - Parameter helpers:
PathParam,QueryParam,RequiredQueryParam,HeaderParam,CookieParam— all return aParameterready forEndpoint.Parameters. - Auth scheme helpers:
BearerAuth(name),APIKeyAuth(name, header),APIKeyQueryAuth(name, param),BasicAuth(name),CookieAuth(name, cookieName)— all return anAuthSchemefor registration viaConfig.Auth.Schemes. - Config surface:
Config.Auth AuthConfig(withPersistCredentialsandSchemesfields) plus theAuthSchemestruct. The newSecurityCookieAuthconstant joins the existingSecurity*family for the predefined-name shortcut.
Migrating from v1.1.1
-
Replace bare
openswag.Response{...}literals withopenswag.Response("desc", Schema{})oropenswag.ResponseSpec{...}. Literals insideopenswag.Responses{ ... }(or the equivalent typed map) continue to compile via Go's composite-literal type inference. -
If you were referencing custom security scheme names from
Endpoint.Securityand relying on them magically becominghttp-bearer, register them explicitly:Auth: openswag.AuthConfig{ Schemes: []openswag.AuthScheme{ openswag.BearerAuth(openswag.SecurityBearerAuth), openswag.APIKeyAuth("apiKey", "X-API-Key"), }, }, -
File-upload endpoints that previously had a
ContentType: "multipart/form-data"set onRequestBodywill now produce a different spec than before — review your generatedopenapi.jsonand update downstream clients/code generators accordingly.
v1.1.1
Cleaner specs out of the box. Examples are now opt-in: you only see them where you ask for them, and null is supported as a first-class example value. Fully backwards-compatible — no API signatures changed.
go get github.com/gopackx/open-swag-go@v1.1.1Behavior change worth flagging
- Examples are now opt-in. Auto-generated example values for primitive fields have been removed. Previously every primitive field got a placeholder (
"string",0,false, …) in the spec even without anexampletag, which produced noisy Scalar UI. Now examples appear only where you setexample:"..."on the field.
What's new
example:"null"literal — Settingexample:"null"on any field type now produces actual JSONnullin the spec (previously only worked for slices/maps). Useful for documenting nullable fields.
Fixed
- Stray
"example": nullentries no longer leak into request body schemas when no example is provided (typed-nil interface bug).
Migrating from v1.1.0
If you relied on the old auto-generated placeholders to populate the Scalar UI, add explicit example:"..." tags to the fields you want shown — see the Migration Guide for details.
v1.1.0
All 12 fixes are backwards-compatible — no public API signatures changed, only additive struct fields and behavior corrections.
go get github.com/gopackx/open-swag-go@v1.1.0Critical Fixes
- fix(spec): Fixed port-to-string conversion in
CommonServers.Localhost()andLocalhostServer()— replaced brokenstring(rune(port))withstrconv.Itoa(port). Also fixed the same pattern inintToString()inopenapi.go. - fix(schema): Example tag values are now coerced to the correct type via
ConvertExampleToType().example:"42"on anint64field now produces the integer42, not the string"42". Applied inpkg/schema/tags.go,openapi.go, andpkg/examples/generator.go. - fix(schema):
$refpointers are no longer silently dropped during schema conversion — addedRef: s.Refmapping inconvertSchema().
High Severity Fixes
- fix(schema): Embedded (anonymous) struct fields are now detected via
field.Anonymousand their properties are promoted into the parent schema. - fix(schema):
map[K]Vtypes now correctly generate{"type":"object","additionalProperties":{...}}. AddedAdditionalPropertiesfield toschema.Schemaand conversion inconvertSchema(). - fix(schema):
interface{}/anyfields now produce an empty schema{}(accepts any type) instead of{"type":"object"}. Validator updated to accept empty schemas.
Medium Severity Fixes
- fix(schema): Fields with
json:",omitempty"are no longer marked as required even ifvalidate:"required"is present. - feat(schema): Added
Nullable,ReadOnly,WriteOnly,Deprecated,MinItems,MaxItems,UniqueItems,AllOf,OneOf,AnyOffields toschema.Schemaand full conversion support inconvertSchema(). - fix(schema): Added special handling for
time.Duration→{format:"duration"},[]byte→{format:"byte"},uuid.UUID→{format:"uuid"}. - fix(schema):
json:",omitempty"(empty name part) now correctly falls back to the Go field name.
Low Severity Fixes
- fix(openapi):
buildParamsFromStructnow prefers location-specific tags (querytag for query params,pathtag for path params) before falling back to generic tags. - feat(openapi): Request body schemas now include an auto-generated
examplefield built from struct field tags and type defaults.
v1.0.0
Initial release of open-swag-go.
- 5 framework adapters: Chi, Gin, Echo, Fiber, net/http
- Authentication playground with Bearer, Basic, API Key, Cookie, and OAuth2 support
- Try-it console with environment management and request history
- Auto-generated code snippets in curl, JavaScript, Go, and Python
- Version diffing with breaking change detection and migration guides
- Schema generation from Go structs using standard tags
- Theming with Scalar UI (purple, blue, green, light themes + dark mode)
- Docs page authentication with basic auth or API key
- Smart example generation from struct field names and tags