openapi20

package
v0.0.0-...-c71775b Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 2 Imported by: 0

README

OpenAPI 2.0 (Swagger) Go Package

A Go package for parsing, manipulating, and validating Swagger/OpenAPI 2.0 specifications.

Features

  • Full Swagger 2.0 (OpenAPI 2.0) specification support
  • JSON marshaling/unmarshaling with round-trip preservation
  • Boolean schema support for additionalProperties: true/false
  • Extension fields (x-*) support on all applicable types
  • Reference ($ref) support for all referenceable types
  • Zero external dependencies - uses only Go standard library

Installation

go get github.com/genelet/oas/openapi20

Usage

Parsing a Swagger Document
package main

import (
    "encoding/json"
    "os"

    "github.com/genelet/oas/openapi20"
)

func main() {
    data, _ := os.ReadFile("swagger.json")

    var swagger openapi20.Swagger
    if err := json.Unmarshal(data, &swagger); err != nil {
        panic(err)
    }

    // Access the parsed document
    println("API Title:", swagger.Info.Title)
    println("Version:", swagger.Info.Version)
    println("Host:", swagger.Host)
    println("BasePath:", swagger.BasePath)
}
Creating a Swagger Document
swagger := &openapi20.Swagger{
    Swagger: "2.0",
    Info: &openapi20.Info{
        Title:   "My API",
        Version: "1.0.0",
    },
    Host:     "api.example.com",
    BasePath: "/v1",
    Schemes:  []string{"https"},
    Consumes: []string{"application/json"},
    Produces: []string{"application/json"},
    Paths: &openapi20.Paths{
        Paths: map[string]*openapi20.PathItem{
            "/users": {
                Get: &openapi20.Operation{
                    Summary:     "List users",
                    OperationID: "listUsers",
                    Responses: &openapi20.Responses{
                        StatusCode: map[string]*openapi20.Response{
                            "200": {
                                Description: "Successful response",
                                Schema: &openapi20.Schema{
                                    Type: "array",
                                    Items: &openapi20.Schema{
                                        Ref: "#/definitions/User",
                                    },
                                },
                            },
                        },
                    },
                },
            },
        },
    },
    Definitions: map[string]*openapi20.Schema{
        "User": {
            Type:     "object",
            Required: []string{"id", "name"},
            Properties: map[string]*openapi20.Schema{
                "id":   {Type: "integer", Format: "int64"},
                "name": {Type: "string"},
            },
        },
    },
}

// Marshal to JSON
data, _ := json.MarshalIndent(swagger, "", "  ")
println(string(data))
Boolean Schemas

Swagger 2.0 allows additionalProperties to be a boolean:

// Create a schema with additionalProperties: false
schema := &openapi20.Schema{
    Type: "object",
    Properties: map[string]*openapi20.Schema{
        "name": {Type: "string"},
    },
    AdditionalProperties: openapi20.NewBooleanSchema(false),
}

// Check if a schema is a boolean schema
if schema.AdditionalProperties.IsBooleanSchema() {
    value := schema.AdditionalProperties.BooleanValue()
    fmt.Printf("additionalProperties: %v\n", *value)
}
Working with References
// Create a reference
schemaRef := openapi20.NewSchemaReference("#/definitions/Pet")
paramRef := openapi20.NewParameterReference("#/parameters/limitParam")
responseRef := openapi20.NewResponseReference("#/responses/NotFound")

// Check if something is a reference
if schema.IsReference() {
    fmt.Printf("Reference: %s\n", schema.Ref)
}
Parameters

Swagger 2.0 has different parameter locations:

// Path parameter
pathParam := &openapi20.Parameter{
    Name:     "id",
    In:       "path",
    Required: true,
    Type:     "string",
}

// Query parameter
queryParam := &openapi20.Parameter{
    Name: "limit",
    In:   "query",
    Type: "integer",
}

// Body parameter (uses schema instead of type)
bodyParam := &openapi20.Parameter{
    Name:     "body",
    In:       "body",
    Required: true,
    Schema:   &openapi20.Schema{Ref: "#/definitions/Pet"},
}

// Check parameter type
if bodyParam.IsBodyParameter() {
    fmt.Println("This is a body parameter")
}
Security Definitions
swagger := &openapi20.Swagger{
    // ...
    SecurityDefinitions: map[string]*openapi20.SecurityScheme{
        "api_key": {
            Type: "apiKey",
            Name: "X-API-Key",
            In:   "header",
        },
        "basic": {
            Type:        "basic",
            Description: "Basic HTTP authentication",
        },
        "oauth2": {
            Type:             "oauth2",
            Flow:             "accessCode",
            AuthorizationUrl: "https://example.com/oauth/authorize",
            TokenUrl:         "https://example.com/oauth/token",
            Scopes: map[string]string{
                "read":  "Read access",
                "write": "Write access",
            },
        },
    },
}
Extension Fields

All types that support extensions in the Swagger spec have an Extensions field:

swagger := &openapi20.Swagger{
    Swagger: "2.0",
    Info: &openapi20.Info{
        Title:   "My API",
        Version: "1.0.0",
        Extensions: map[string]any{
            "x-logo": map[string]any{
                "url": "https://example.com/logo.png",
            },
        },
    },
    Extensions: map[string]any{
        "x-api-id": "12345",
    },
    // ...
}

Type Reference

Core Types
Type Description
Swagger Root document object
Info API metadata (title, version, description, etc.)
Contact Contact information
License License information
Paths Container for path items
PathItem Operations on a single path
Operation Single API operation
ExternalDocumentation External documentation link
Tag Tag for API documentation
Request/Response Types
Type Description
Parameter Operation parameter (path, query, header, formData, body)
Items Item type for array parameters
Header Response header
Responses Container for response definitions
Response Single response definition
Schema Types
Type Description
Schema JSON Schema subset with Swagger extensions
XML XML serialization metadata
Security Types
Type Description
SecurityScheme Security scheme definition (basic, apiKey, oauth2)
SecurityRequirement Security requirement for operations

Swagger 2.0 vs OpenAPI 3.0 Differences

This package implements Swagger 2.0 (OpenAPI 2.0). Key differences from OpenAPI 3.0:

Feature Swagger 2.0 OpenAPI 3.0
Version field swagger: "2.0" openapi: "3.0.x"
Server host, basePath, schemes servers array
Request body in: body parameter requestBody object
Content types consumes, produces content in request/response
Schemas definitions components/schemas
Parameters parameters components/parameters
Responses responses components/responses
Security securityDefinitions components/securitySchemes
Composition Only allOf allOf, oneOf, anyOf, not
File upload type: file in formData Binary string in requestBody
Discriminator String (property name) Object with mapping

Testing

# Run all tests
go test ./openapi20/...

# Run with verbose output
go test -v ./openapi20/...

# Run specific test
go test -run TestJSONRoundTrip ./openapi20/...

License

See the repository root for license information.

Documentation

Overview

Package openapi20 provides Go types for Swagger/OpenAPI Specification v2.0 Based on https://swagger.io/specification/v2/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contact

type Contact struct {
	Name       string         `json:"name,omitempty"`
	URL        string         `json:"url,omitempty"`
	Email      string         `json:"email,omitempty"`
	Extensions map[string]any `json:"-"`
}

Contact contains contact information for the API

func (Contact) MarshalJSON

func (c Contact) MarshalJSON() ([]byte, error)

func (*Contact) UnmarshalJSON

func (c *Contact) UnmarshalJSON(data []byte) error

type ExternalDocumentation

type ExternalDocumentation struct {
	Description string         `json:"description,omitempty"`
	URL         string         `json:"url"`
	Extensions  map[string]any `json:"-"`
}

ExternalDocumentation allows referencing an external resource for extended documentation

func (ExternalDocumentation) MarshalJSON

func (e ExternalDocumentation) MarshalJSON() ([]byte, error)

func (*ExternalDocumentation) UnmarshalJSON

func (e *ExternalDocumentation) UnmarshalJSON(data []byte) error
type Header struct {
	Type             string         `json:"type"` // string, number, integer, boolean, array
	Format           string         `json:"format,omitempty"`
	Description      string         `json:"description,omitempty"`
	Items            *Items         `json:"items,omitempty"`
	CollectionFormat string         `json:"collectionFormat,omitempty"`
	Default          any            `json:"default,omitempty"`
	Maximum          *float64       `json:"maximum,omitempty"`
	ExclusiveMaximum bool           `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64       `json:"minimum,omitempty"`
	ExclusiveMinimum bool           `json:"exclusiveMinimum,omitempty"`
	MaxLength        *int           `json:"maxLength,omitempty"`
	MinLength        *int           `json:"minLength,omitempty"`
	Pattern          string         `json:"pattern,omitempty"`
	MaxItems         *int           `json:"maxItems,omitempty"`
	MinItems         *int           `json:"minItems,omitempty"`
	UniqueItems      bool           `json:"uniqueItems,omitempty"`
	Enum             []any          `json:"enum,omitempty"`
	MultipleOf       *float64       `json:"multipleOf,omitempty"`
	Extensions       map[string]any `json:"-"`
}

Header represents a header in a response

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(data []byte) error

type Info

type Info struct {
	Title          string         `json:"title"`
	Version        string         `json:"version"`
	Description    string         `json:"description,omitempty"`
	TermsOfService string         `json:"termsOfService,omitempty"`
	Contact        *Contact       `json:"contact,omitempty"`
	License        *License       `json:"license,omitempty"`
	Extensions     map[string]any `json:"-"`
}

Info provides metadata about the API

func (Info) MarshalJSON

func (i Info) MarshalJSON() ([]byte, error)

func (*Info) UnmarshalJSON

func (i *Info) UnmarshalJSON(data []byte) error

type Items

type Items struct {
	Type             string         `json:"type,omitempty"` // string, number, integer, boolean, array
	Format           string         `json:"format,omitempty"`
	Items            *Items         `json:"items,omitempty"` // for nested arrays
	CollectionFormat string         `json:"collectionFormat,omitempty"`
	Default          any            `json:"default,omitempty"`
	Maximum          *float64       `json:"maximum,omitempty"`
	ExclusiveMaximum bool           `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64       `json:"minimum,omitempty"`
	ExclusiveMinimum bool           `json:"exclusiveMinimum,omitempty"`
	MaxLength        *int           `json:"maxLength,omitempty"`
	MinLength        *int           `json:"minLength,omitempty"`
	Pattern          string         `json:"pattern,omitempty"`
	MaxItems         *int           `json:"maxItems,omitempty"`
	MinItems         *int           `json:"minItems,omitempty"`
	UniqueItems      bool           `json:"uniqueItems,omitempty"`
	Enum             []any          `json:"enum,omitempty"`
	MultipleOf       *float64       `json:"multipleOf,omitempty"`
	Extensions       map[string]any `json:"-"`
}

Items describes the type of items in an array parameter Used for non-body parameters with type=array

func (Items) MarshalJSON

func (i Items) MarshalJSON() ([]byte, error)

func (*Items) UnmarshalJSON

func (i *Items) UnmarshalJSON(data []byte) error

type License

type License struct {
	Name       string         `json:"name"`
	URL        string         `json:"url,omitempty"`
	Extensions map[string]any `json:"-"`
}

License contains license information for the API

func (License) MarshalJSON

func (l License) MarshalJSON() ([]byte, error)

func (*License) UnmarshalJSON

func (l *License) UnmarshalJSON(data []byte) error

type Operation

type Operation struct {
	Tags         []string               `json:"tags,omitempty"`
	Summary      string                 `json:"summary,omitempty"`
	Description  string                 `json:"description,omitempty"`
	ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
	OperationID  string                 `json:"operationId,omitempty"`
	Consumes     []string               `json:"consumes,omitempty"`
	Produces     []string               `json:"produces,omitempty"`
	Parameters   []*Parameter           `json:"parameters,omitempty"`
	Responses    *Responses             `json:"responses"`
	Schemes      []string               `json:"schemes,omitempty"`
	Deprecated   bool                   `json:"deprecated,omitempty"`
	Security     []SecurityRequirement  `json:"security,omitempty"`
	Extensions   map[string]any         `json:"-"`
}

Operation describes a single API operation on a path

func (Operation) MarshalJSON

func (o Operation) MarshalJSON() ([]byte, error)

func (*Operation) UnmarshalJSON

func (o *Operation) UnmarshalJSON(data []byte) error

type Parameter

type Parameter struct {
	// Reference field
	Ref string `json:"$ref,omitempty"`

	// Common fields
	Name        string `json:"name,omitempty"`
	In          string `json:"in,omitempty"` // query, header, path, formData, body
	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`

	// Body parameter fields
	Schema *Schema `json:"schema,omitempty"`

	// Non-body parameter fields
	Type             string         `json:"type,omitempty"` // string, number, integer, boolean, array, file
	Format           string         `json:"format,omitempty"`
	AllowEmptyValue  bool           `json:"allowEmptyValue,omitempty"`
	Items            *Items         `json:"items,omitempty"`
	CollectionFormat string         `json:"collectionFormat,omitempty"` // csv, ssv, tsv, pipes, multi
	Default          any            `json:"default,omitempty"`
	Maximum          *float64       `json:"maximum,omitempty"`
	ExclusiveMaximum bool           `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64       `json:"minimum,omitempty"`
	ExclusiveMinimum bool           `json:"exclusiveMinimum,omitempty"`
	MaxLength        *int           `json:"maxLength,omitempty"`
	MinLength        *int           `json:"minLength,omitempty"`
	Pattern          string         `json:"pattern,omitempty"`
	MaxItems         *int           `json:"maxItems,omitempty"`
	MinItems         *int           `json:"minItems,omitempty"`
	UniqueItems      bool           `json:"uniqueItems,omitempty"`
	Enum             []any          `json:"enum,omitempty"`
	MultipleOf       *float64       `json:"multipleOf,omitempty"`
	Extensions       map[string]any `json:"-"`
}

Parameter describes a single operation parameter. In Swagger 2.0, parameters can be: - Body parameters (in=body, with schema) - Non-body parameters (in=query/header/path/formData, with type, format, items, etc.)

func NewParameterReference

func NewParameterReference(ref string) *Parameter

NewParameterReference creates a parameter that is actually a reference

func (*Parameter) IsBodyParameter

func (p *Parameter) IsBodyParameter() bool

IsBodyParameter returns true if this is a body parameter

func (*Parameter) IsReference

func (p *Parameter) IsReference() bool

IsReference checks if this parameter is actually a reference ($ref)

func (Parameter) MarshalJSON

func (p Parameter) MarshalJSON() ([]byte, error)

func (*Parameter) UnmarshalJSON

func (p *Parameter) UnmarshalJSON(data []byte) error

type PathItem

type PathItem struct {
	Ref        string         `json:"$ref,omitempty"`
	Get        *Operation     `json:"get,omitempty"`
	Put        *Operation     `json:"put,omitempty"`
	Post       *Operation     `json:"post,omitempty"`
	Delete     *Operation     `json:"delete,omitempty"`
	Options    *Operation     `json:"options,omitempty"`
	Head       *Operation     `json:"head,omitempty"`
	Patch      *Operation     `json:"patch,omitempty"`
	Parameters []*Parameter   `json:"parameters,omitempty"`
	Extensions map[string]any `json:"-"`
}

PathItem describes the operations available on a single path

func (*PathItem) GetRef

func (pi *PathItem) GetRef() string

GetRef returns the $ref value

func (*PathItem) HasRef

func (pi *PathItem) HasRef() bool

HasRef returns true if this PathItem has a $ref

func (PathItem) MarshalJSON

func (pi PathItem) MarshalJSON() ([]byte, error)

func (*PathItem) UnmarshalJSON

func (pi *PathItem) UnmarshalJSON(data []byte) error

type Paths

type Paths struct {
	Paths      map[string]*PathItem `json:"-"`
	Extensions map[string]any       `json:"-"`
}

Paths holds the relative paths to the individual endpoints and their operations

func (*Paths) Get

func (p *Paths) Get(path string) *PathItem

Get returns the PathItem for the given path

func (Paths) MarshalJSON

func (p Paths) MarshalJSON() ([]byte, error)

func (*Paths) Set

func (p *Paths) Set(path string, item *PathItem)

Set sets the PathItem for the given path

func (*Paths) UnmarshalJSON

func (p *Paths) UnmarshalJSON(data []byte) error

type Response

type Response struct {
	// Reference field
	Ref string `json:"$ref,omitempty"`

	// Response fields
	Description string             `json:"description,omitempty"`
	Schema      *Schema            `json:"schema,omitempty"`
	Headers     map[string]*Header `json:"headers,omitempty"`
	Examples    map[string]any     `json:"examples,omitempty"`
	Extensions  map[string]any     `json:"-"`
}

Response describes a single response from an API Operation

func NewResponseReference

func NewResponseReference(ref string) *Response

NewResponseReference creates a response that is actually a reference

func (*Response) IsReference

func (r *Response) IsReference() bool

IsReference checks if this response is actually a reference ($ref)

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

type Responses

type Responses struct {
	Default    *Response            `json:"-"`
	StatusCode map[string]*Response `json:"-"`
	Extensions map[string]any       `json:"-"`
}

Responses is a container for the expected responses of an operation

func (Responses) MarshalJSON

func (r Responses) MarshalJSON() ([]byte, error)

func (*Responses) UnmarshalJSON

func (r *Responses) UnmarshalJSON(data []byte) error

type Schema

type Schema struct {

	// Reference
	Ref string `json:"$ref,omitempty"`

	// JSON Schema keywords
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Default     any    `json:"default,omitempty"`
	Format      string `json:"format,omitempty"`

	// Type - can be string or array of strings in Swagger 2.0
	Type string `json:"type,omitempty"`

	// Enum and validation
	Enum []any `json:"enum,omitempty"`

	// Numeric validation
	MultipleOf       *float64 `json:"multipleOf,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty"`
	ExclusiveMaximum bool     `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	ExclusiveMinimum bool     `json:"exclusiveMinimum,omitempty"`

	// String validation
	MaxLength *int   `json:"maxLength,omitempty"`
	MinLength *int   `json:"minLength,omitempty"`
	Pattern   string `json:"pattern,omitempty"`

	// Array validation
	MaxItems    *int    `json:"maxItems,omitempty"`
	MinItems    *int    `json:"minItems,omitempty"`
	UniqueItems bool    `json:"uniqueItems,omitempty"`
	Items       *Schema `json:"items,omitempty"`

	// Object validation
	MaxProperties        *int               `json:"maxProperties,omitempty"`
	MinProperties        *int               `json:"minProperties,omitempty"`
	Required             []string           `json:"required,omitempty"`
	Properties           map[string]*Schema `json:"properties,omitempty"`
	AdditionalProperties *Schema            `json:"additionalProperties,omitempty"` // Can be boolean schema

	// Composition keywords - Swagger 2.0 only supports allOf
	AllOf []*Schema `json:"allOf,omitempty"`

	// Swagger 2.0 specific
	Discriminator string                 `json:"discriminator,omitempty"` // Property name (string in 2.0, object in 3.0)
	ReadOnly      bool                   `json:"readOnly,omitempty"`
	XML           *XML                   `json:"xml,omitempty"`
	ExternalDocs  *ExternalDocumentation `json:"externalDocs,omitempty"`
	Example       any                    `json:"example,omitempty"`

	Extensions map[string]any `json:"-"`
	// contains filtered or unexported fields
}

Schema represents a JSON Schema subset for Swagger 2.0. This type supports both object schemas and boolean schemas (true/false). In Swagger 2.0, additionalProperties can be a boolean or a schema object.

func NewBooleanSchema

func NewBooleanSchema(value bool) *Schema

NewBooleanSchema creates a boolean schema

func NewSchemaReference

func NewSchemaReference(ref string) *Schema

NewSchemaReference creates a schema that is actually a reference

func (*Schema) BooleanValue

func (s *Schema) BooleanValue() *bool

BooleanValue returns the boolean value if this is a boolean schema

func (*Schema) IsBooleanSchema

func (s *Schema) IsBooleanSchema() bool

IsBooleanSchema returns true if this is a boolean schema (true or false)

func (*Schema) IsReference

func (s *Schema) IsReference() bool

IsReference checks if this schema is actually a reference ($ref)

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

type SecurityRequirement

type SecurityRequirement map[string][]string

SecurityRequirement lists the required security schemes to execute an operation. Each key is a security scheme name, and the value is a list of required scopes.

type SecurityScheme

type SecurityScheme struct {
	// Type of security scheme: basic, apiKey, or oauth2
	Type string `json:"type"`

	// Description of the security scheme
	Description string `json:"description,omitempty"`

	// apiKey specific fields
	Name string `json:"name,omitempty"` // Name of the header or query parameter
	In   string `json:"in,omitempty"`   // Location: "header" or "query"

	// oauth2 specific fields
	Flow             string            `json:"flow,omitempty"`             // implicit, password, application, accessCode
	AuthorizationUrl string            `json:"authorizationUrl,omitempty"` // Required for implicit and accessCode flows
	TokenUrl         string            `json:"tokenUrl,omitempty"`         // Required for password, application, and accessCode flows
	Scopes           map[string]string `json:"scopes,omitempty"`           // Available scopes for OAuth2

	Extensions map[string]any `json:"-"`
}

SecurityScheme defines a security scheme in Swagger 2.0. Types can be: "basic", "apiKey", or "oauth2"

func (*SecurityScheme) IsAPIKey

func (ss *SecurityScheme) IsAPIKey() bool

IsAPIKey returns true if this is an API key authentication scheme

func (*SecurityScheme) IsBasic

func (ss *SecurityScheme) IsBasic() bool

IsBasic returns true if this is a basic authentication scheme

func (*SecurityScheme) IsOAuth2

func (ss *SecurityScheme) IsOAuth2() bool

IsOAuth2 returns true if this is an OAuth2 authentication scheme

func (SecurityScheme) MarshalJSON

func (ss SecurityScheme) MarshalJSON() ([]byte, error)

func (*SecurityScheme) UnmarshalJSON

func (ss *SecurityScheme) UnmarshalJSON(data []byte) error

type Swagger

type Swagger struct {
	Swagger             string                     `json:"swagger"`
	Info                *Info                      `json:"info"`
	Host                string                     `json:"host,omitempty"`
	BasePath            string                     `json:"basePath,omitempty"`
	Schemes             []string                   `json:"schemes,omitempty"`
	Consumes            []string                   `json:"consumes,omitempty"`
	Produces            []string                   `json:"produces,omitempty"`
	Paths               *Paths                     `json:"paths"`
	Definitions         map[string]*Schema         `json:"definitions,omitempty"`
	Parameters          map[string]*Parameter      `json:"parameters,omitempty"`
	Responses           map[string]*Response       `json:"responses,omitempty"`
	SecurityDefinitions map[string]*SecurityScheme `json:"securityDefinitions,omitempty"`
	Security            []SecurityRequirement      `json:"security,omitempty"`
	Tags                []*Tag                     `json:"tags,omitempty"`
	ExternalDocs        *ExternalDocumentation     `json:"externalDocs,omitempty"`
	Extensions          map[string]any             `json:"-"`
}

Swagger is the root object of a Swagger 2.0 document

func (Swagger) MarshalJSON

func (s Swagger) MarshalJSON() ([]byte, error)

func (*Swagger) UnmarshalJSON

func (s *Swagger) UnmarshalJSON(data []byte) error

type Tag

type Tag struct {
	Name         string                 `json:"name"`
	Description  string                 `json:"description,omitempty"`
	ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
	Extensions   map[string]any         `json:"-"`
}

Tag adds metadata to a single tag that is used by the Operation Object

func (Tag) MarshalJSON

func (t Tag) MarshalJSON() ([]byte, error)

func (*Tag) UnmarshalJSON

func (t *Tag) UnmarshalJSON(data []byte) error

type XML

type XML struct {
	Name       string         `json:"name,omitempty"`
	Namespace  string         `json:"namespace,omitempty"`
	Prefix     string         `json:"prefix,omitempty"`
	Attribute  bool           `json:"attribute,omitempty"`
	Wrapped    bool           `json:"wrapped,omitempty"`
	Extensions map[string]any `json:"-"`
}

XML provides metadata for XML representation

func (XML) MarshalJSON

func (x XML) MarshalJSON() ([]byte, error)

func (*XML) UnmarshalJSON

func (x *XML) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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