MCPcopy Index your code
hub / github.com/go-openapi/swag

github.com/go-openapi/swag @v0.27.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.27.0 ↗ · + Follow
967 symbols 3,258 edges 145 files 470 documented · 49% 438 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Swag

Tests Coverage CI vuln scan CodeQL

Release Go Report Card CodeFactor Grade License

GoDoc Discord Channel go version Top language Commits since latest release


A bunch of helper functions for go-openapi and go-swagger projects.

You may also use it standalone for your projects.

NOTE swag is one of the foundational building blocks of the go-openapi initiative.

Most repositories in github.com/go-openapi/... depend on it in some way. And so does our CLI tool github.com/go-swagger/go-swagger, as well as the code generated by this tool.

Announcements

  • 2025-12-19 : new community chat on discord
  • a new discord community channel is available to be notified of changes and support users

You may join the discord community by clicking the invite link on the discord badge (also above). Discord Channel

Status

API is stable.

Import this library in your project

go get github.com/go-openapi/swag/{module}

Or for backward compatibility:

go get github.com/go-openapi/swag

Contents

go-openapi/swag exposes a collection of relatively independent modules.

Moving forward, no additional feature will be added to the swag API directly at the root package level, which remains there for backward-compatibility purposes. All exported top-level features are now deprecated.

Child modules will continue to evolve and some new ones may be added in the future.

Module Content Main features
cmdutils utilities to work with CLIs
conv type conversion utilities convert between values and pointers for any types

convert from string to builtin types (wraps strconv)

require ./typeutils (test dependency)

| | fileutils | file utilities | | | jsonname | JSON utilities (deprecated) | infer JSON names from go properties

use github.com/go-openapi/jsonpointer/jsonname instead | | jsonutils | JSON utilities | fast json concatenation

read and write JSON from and to dynamic go data structures

~require github.com/mailru/easyjson~

| | loading | file loading | load from file or http

require ./yamlutils

| | mangling | safe name generation | name mangling for go

| | netutils | networking utilities | host, port from address

| | pools | utilities to work with sync.Pools | | | stringutils | string utilities | search in slice (with case-insensitive)

split/join query parameters as arrays

| | typeutils | go types utilities | check the zero value for any type

safe check for a nil value

| | yamlutils | YAML utilities | converting YAML to JSON

loading YAML into a dynamic YAML document

maintaining the original order of keys in YAML objects

require ./jsonutils

~require github.com/mailru/easyjson~

require go.yaml.in/yaml/v3

|


Dependencies

The root module github.com/go-openapi/swag at the repo level maintains a few dependencies outside of the standard library.

  • YAML utilities depend on go.yaml.in/yaml/v3
  • JSON utilities depend on their registered adapter module:
    • by default, only the standard library is used
    • github.com/mailru/easyjson is now only a dependency for module github.com/go-openapi/swag/jsonutils/adapters/easyjson/json, for users willing to import that module.
    • integration tests and benchmarks use all the dependencies are published as their own module
  • other dependencies are test dependencies drawn from github.com/stretchr/testify

Usage

How to explicitly register a dependency at runtime?

The following would maintain how JSON utilities proposed by swag used work, up to v0.24.1.

```go import ( "github.com/go-openapi/swag/jsonutils/adapters" easyjson "github.com/go-openapi/swag/jsonutils/adapters/easyjson/json" )

func init() { easyjson.Register(adapters.Registry) } ```

Subsequent calls to jsonutils.ReadJSON() or jsonutils.WriteJSON() will switch to easyjson whenever the passed data structures implement the easyjson.Unmarshaler or easyjson.Marshaler respectively, or fallback to the standard library.

For more details, you may also look at our integration tests.


Note to contributors

All kinds of contributions are welcome.

This repo is a go mono-repo. See docs.

More general guidelines are available here.

Roadmap

See the current TODO list

Change log

See https://github.com/go-openapi/swag/releases

For pre-v0.26.0 releases, see release notes.

What coming next?

Moving forward, we want to :

  • provide an implementation of the JSON adapter based on encoding/json/v2, for go1.25 builds.
  • provide similar implementations for goccy/go-json and jsoniterator/go, and perhaps some other similar libraries may be interesting too.

Licensing

This library ships under the SPDX-License-Identifier: Apache-2.0.

Other documentation

Cutting a new release

Maintainers can cut a new release by either:

  • running this workflow
  • or pushing a semver tag
  • signed tags are preferred
  • The tag message is prepended to release notes

Extension points exported contracts — how you extend this code

Resettable (Interface)
Resettable is an interface for types that want to recycle a clean instance from a [Pool]. When T (or rather *T) impleme [14 …
pools/pools.go
OrderedMarshalAdapter (Interface)
OrderedMarshalAdapter behaves likes the standard library [json.Marshal], preserving the order of keys in objects. [5 implementers]
jsonutils/adapters/ifaces/ifaces.go
TB (Interface)
TB is the subset of [testing.TB] used by [AssertNoLeaks]. It is satisfied by *[testing.T] and *[testing.B]. A local in [1 …
pools/debug.go
Option (FuncType)
Option provides options for loading a file over HTTP or from a file.
loading/options.go
Signed (Interface)
these type constraints are redefined after golang.org/x/exp/constraints, because importing that package causes an undesi
conv/type_constraints.go
PrefixFunc (FuncType)
PrefixFunc defines a safeguard rule (that may depend on the input string), to prefix a generated go name (in [NameMangle
mangling/options.go
Filter (FuncType)
(no doc)
jsonutils/fixtures_test/harness.go
PoolSliceOption (FuncType)
PoolSliceOption alters the default settings to allocate new pooled slices
pools/pools.go

Core symbols most depended-on inside this repo

Len
called by 86
pools/pools.go
RawString
called by 64
jsonutils/adapters/stdlib/json/writer.go
RawByte
called by 50
jsonutils/adapters/stdlib/json/writer.go
Delim
called by 48
jsonutils/adapters/stdlib/json/lexer.go
Redeem
called by 41
jsonutils/adapters/ifaces/ifaces.go
Skip
called by 39
jsonutils/adapters/stdlib/json/lexer.go
isEqualFoldIgnoreSpace
called by 38
mangling/util.go
String
called by 37
jsonutils/adapters/stdlib/json/lexer.go

Shape

Function 497
Method 320
Struct 96
TypeAlias 23
Interface 21
FuncType 10

Languages

Go100%

Modules by API surface

conv_iface.go95 symbols
jsonutils/adapters/ifaces/mocks/mocks.go77 symbols
pools/pools.go31 symbols
jsonutils/fixtures_test/harness.go25 symbols
jsonutils/adapters/stdlib/json/lexer.go25 symbols
jsonutils/adapters/registry_test.go25 symbols
conv/convert_format_test.go23 symbols
jsonutils/adapters/testintegration/benchmarks/payloads_easyjson.go22 symbols
jsonutils/adapters/testintegration/integration_suite_test.go21 symbols
jsonutils/adapters/ifaces/ifaces.go21 symbols
pools/pools_test.go20 symbols
pools/debug_on.go18 symbols

For agents

$ claude mcp add swag \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact