forked from ebhomengo/niki
1
0
Fork 0
niki/vendor/github.com/go-openapi/spec/swagger.go

768 lines
12 KiB
Go
Raw Normal View History

2024-05-14 13:07:09 +00:00
// Copyright 2015 go-swagger maintainers
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Licensed under the Apache License, Version 2.0 (the "License");
2024-05-14 13:07:09 +00:00
// you may not use this file except in compliance with the License.
2024-05-14 13:07:09 +00:00
// You may obtain a copy of the License at
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// http://www.apache.org/licenses/LICENSE-2.0
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// Unless required by applicable law or agreed to in writing, software
2024-05-14 13:07:09 +00:00
// distributed under the License is distributed on an "AS IS" BASIS,
2024-05-14 13:07:09 +00:00
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2024-05-14 13:07:09 +00:00
// See the License for the specific language governing permissions and
2024-05-14 13:07:09 +00:00
// limitations under the License.
package spec
import (
"bytes"
"encoding/gob"
"encoding/json"
"fmt"
"strconv"
"github.com/go-openapi/jsonpointer"
"github.com/go-openapi/swag"
)
// Swagger this is the root document object for the API specification.
2024-05-14 13:07:09 +00:00
// It combines what previously was the Resource Listing and API Declaration (version 1.2 and earlier)
2024-05-14 13:07:09 +00:00
// together into one document.
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// For more information: http://goo.gl/8us55a#swagger-object-
2024-05-14 13:07:09 +00:00
type Swagger struct {
VendorExtensible
2024-05-14 13:07:09 +00:00
SwaggerProps
}
// JSONLookup look up a value by the json property name
2024-05-14 13:07:09 +00:00
func (s Swagger) JSONLookup(token string) (interface{}, error) {
2024-05-14 13:07:09 +00:00
if ex, ok := s.Extensions[token]; ok {
2024-05-14 13:07:09 +00:00
return &ex, nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(s.SwaggerProps, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
// MarshalJSON marshals this swagger structure to json
2024-05-14 13:07:09 +00:00
func (s Swagger) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
b1, err := json.Marshal(s.SwaggerProps)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return nil, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
b2, err := json.Marshal(s.VendorExtensible)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return nil, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return swag.ConcatJSON(b1, b2), nil
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON unmarshals a swagger spec from json
2024-05-14 13:07:09 +00:00
func (s *Swagger) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
var sw Swagger
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &sw.SwaggerProps); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &sw.VendorExtensible); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
*s = sw
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// GobEncode provides a safe gob encoder for Swagger, including extensions
2024-05-14 13:07:09 +00:00
func (s Swagger) GobEncode() ([]byte, error) {
2024-05-14 13:07:09 +00:00
var b bytes.Buffer
2024-05-14 13:07:09 +00:00
raw := struct {
Props SwaggerProps
Ext VendorExtensible
2024-05-14 13:07:09 +00:00
}{
2024-05-14 13:07:09 +00:00
Props: s.SwaggerProps,
Ext: s.VendorExtensible,
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
err := gob.NewEncoder(&b).Encode(raw)
2024-05-14 13:07:09 +00:00
return b.Bytes(), err
2024-05-14 13:07:09 +00:00
}
// GobDecode provides a safe gob decoder for Swagger, including extensions
2024-05-14 13:07:09 +00:00
func (s *Swagger) GobDecode(b []byte) error {
2024-05-14 13:07:09 +00:00
var raw struct {
Props SwaggerProps
Ext VendorExtensible
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
buf := bytes.NewBuffer(b)
2024-05-14 13:07:09 +00:00
err := gob.NewDecoder(buf).Decode(&raw)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
s.SwaggerProps = raw.Props
2024-05-14 13:07:09 +00:00
s.VendorExtensible = raw.Ext
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// SwaggerProps captures the top-level properties of an Api specification
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// NOTE: validation rules
2024-05-14 13:07:09 +00:00
// - the scheme, when present must be from [http, https, ws, wss]
2024-05-14 13:07:09 +00:00
// - BasePath must start with a leading "/"
2024-05-14 13:07:09 +00:00
// - Paths is required
2024-05-14 13:07:09 +00:00
type SwaggerProps struct {
ID string `json:"id,omitempty"`
Consumes []string `json:"consumes,omitempty"`
Produces []string `json:"produces,omitempty"`
Schemes []string `json:"schemes,omitempty"`
Swagger string `json:"swagger,omitempty"`
Info *Info `json:"info,omitempty"`
Host string `json:"host,omitempty"`
BasePath string `json:"basePath,omitempty"`
Paths *Paths `json:"paths"`
Definitions Definitions `json:"definitions,omitempty"`
Parameters map[string]Parameter `json:"parameters,omitempty"`
Responses map[string]Response `json:"responses,omitempty"`
SecurityDefinitions SecurityDefinitions `json:"securityDefinitions,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
Tags []Tag `json:"tags,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
2024-05-14 13:07:09 +00:00
}
type swaggerPropsAlias SwaggerProps
type gobSwaggerPropsAlias struct {
Security []map[string]struct {
List []string
Pad bool
2024-05-14 13:07:09 +00:00
}
Alias *swaggerPropsAlias
2024-05-14 13:07:09 +00:00
SecurityIsEmpty bool
}
// GobEncode provides a safe gob encoder for SwaggerProps, including empty security requirements
2024-05-14 13:07:09 +00:00
func (o SwaggerProps) GobEncode() ([]byte, error) {
2024-05-14 13:07:09 +00:00
raw := gobSwaggerPropsAlias{
2024-05-14 13:07:09 +00:00
Alias: (*swaggerPropsAlias)(&o),
}
var b bytes.Buffer
2024-05-14 13:07:09 +00:00
if o.Security == nil {
2024-05-14 13:07:09 +00:00
// nil security requirement
2024-05-14 13:07:09 +00:00
err := gob.NewEncoder(&b).Encode(raw)
2024-05-14 13:07:09 +00:00
return b.Bytes(), err
2024-05-14 13:07:09 +00:00
}
if len(o.Security) == 0 {
2024-05-14 13:07:09 +00:00
// empty, but non-nil security requirement
2024-05-14 13:07:09 +00:00
raw.SecurityIsEmpty = true
2024-05-14 13:07:09 +00:00
raw.Alias.Security = nil
2024-05-14 13:07:09 +00:00
err := gob.NewEncoder(&b).Encode(raw)
2024-05-14 13:07:09 +00:00
return b.Bytes(), err
2024-05-14 13:07:09 +00:00
}
raw.Security = make([]map[string]struct {
List []string
Pad bool
2024-05-14 13:07:09 +00:00
}, 0, len(o.Security))
2024-05-14 13:07:09 +00:00
for _, req := range o.Security {
2024-05-14 13:07:09 +00:00
v := make(map[string]struct {
List []string
Pad bool
2024-05-14 13:07:09 +00:00
}, len(req))
2024-05-14 13:07:09 +00:00
for k, val := range req {
2024-05-14 13:07:09 +00:00
v[k] = struct {
List []string
Pad bool
2024-05-14 13:07:09 +00:00
}{
2024-05-14 13:07:09 +00:00
List: val,
}
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
raw.Security = append(raw.Security, v)
2024-05-14 13:07:09 +00:00
}
err := gob.NewEncoder(&b).Encode(raw)
2024-05-14 13:07:09 +00:00
return b.Bytes(), err
2024-05-14 13:07:09 +00:00
}
// GobDecode provides a safe gob decoder for SwaggerProps, including empty security requirements
2024-05-14 13:07:09 +00:00
func (o *SwaggerProps) GobDecode(b []byte) error {
2024-05-14 13:07:09 +00:00
var raw gobSwaggerPropsAlias
buf := bytes.NewBuffer(b)
2024-05-14 13:07:09 +00:00
err := gob.NewDecoder(buf).Decode(&raw)
2024-05-14 13:07:09 +00:00
if err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if raw.Alias == nil {
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
switch {
2024-05-14 13:07:09 +00:00
case raw.SecurityIsEmpty:
2024-05-14 13:07:09 +00:00
// empty, but non-nil security requirement
2024-05-14 13:07:09 +00:00
raw.Alias.Security = []map[string][]string{}
2024-05-14 13:07:09 +00:00
case len(raw.Alias.Security) == 0:
2024-05-14 13:07:09 +00:00
// nil security requirement
2024-05-14 13:07:09 +00:00
raw.Alias.Security = nil
2024-05-14 13:07:09 +00:00
default:
2024-05-14 13:07:09 +00:00
raw.Alias.Security = make([]map[string][]string, 0, len(raw.Security))
2024-05-14 13:07:09 +00:00
for _, req := range raw.Security {
2024-05-14 13:07:09 +00:00
v := make(map[string][]string, len(req))
2024-05-14 13:07:09 +00:00
for k, val := range req {
2024-05-14 13:07:09 +00:00
v[k] = make([]string, 0, len(val.List))
2024-05-14 13:07:09 +00:00
v[k] = append(v[k], val.List...)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
raw.Alias.Security = append(raw.Alias.Security, v)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}
*o = *(*SwaggerProps)(raw.Alias)
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// Dependencies represent a dependencies property
2024-05-14 13:07:09 +00:00
type Dependencies map[string]SchemaOrStringArray
// SchemaOrBool represents a schema or boolean value, is biased towards true for the boolean property
2024-05-14 13:07:09 +00:00
type SchemaOrBool struct {
Allows bool
2024-05-14 13:07:09 +00:00
Schema *Schema
}
// JSONLookup implements an interface to customize json pointer lookup
2024-05-14 13:07:09 +00:00
func (s SchemaOrBool) JSONLookup(token string) (interface{}, error) {
2024-05-14 13:07:09 +00:00
if token == "allows" {
2024-05-14 13:07:09 +00:00
return s.Allows, nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(s.Schema, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
var jsTrue = []byte("true")
2024-05-14 13:07:09 +00:00
var jsFalse = []byte("false")
// MarshalJSON convert this object to JSON
2024-05-14 13:07:09 +00:00
func (s SchemaOrBool) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
if s.Schema != nil {
2024-05-14 13:07:09 +00:00
return json.Marshal(s.Schema)
2024-05-14 13:07:09 +00:00
}
if s.Schema == nil && !s.Allows {
2024-05-14 13:07:09 +00:00
return jsFalse, nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return jsTrue, nil
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON converts this bool or schema object from a JSON structure
2024-05-14 13:07:09 +00:00
func (s *SchemaOrBool) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
var nw SchemaOrBool
2024-05-14 13:07:09 +00:00
if len(data) > 0 {
2024-05-14 13:07:09 +00:00
if data[0] == '{' {
2024-05-14 13:07:09 +00:00
var sch Schema
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &sch); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
nw.Schema = &sch
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
nw.Allows = !bytes.Equal(data, []byte("false"))
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
*s = nw
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// SchemaOrStringArray represents a schema or a string array
2024-05-14 13:07:09 +00:00
type SchemaOrStringArray struct {
Schema *Schema
2024-05-14 13:07:09 +00:00
Property []string
}
// JSONLookup implements an interface to customize json pointer lookup
2024-05-14 13:07:09 +00:00
func (s SchemaOrStringArray) JSONLookup(token string) (interface{}, error) {
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(s.Schema, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
// MarshalJSON converts this schema object or array into JSON structure
2024-05-14 13:07:09 +00:00
func (s SchemaOrStringArray) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
if len(s.Property) > 0 {
2024-05-14 13:07:09 +00:00
return json.Marshal(s.Property)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if s.Schema != nil {
2024-05-14 13:07:09 +00:00
return json.Marshal(s.Schema)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return []byte("null"), nil
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON converts this schema object or array from a JSON structure
2024-05-14 13:07:09 +00:00
func (s *SchemaOrStringArray) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
var first byte
2024-05-14 13:07:09 +00:00
if len(data) > 1 {
2024-05-14 13:07:09 +00:00
first = data[0]
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
var nw SchemaOrStringArray
2024-05-14 13:07:09 +00:00
if first == '{' {
2024-05-14 13:07:09 +00:00
var sch Schema
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &sch); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
nw.Schema = &sch
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if first == '[' {
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &nw.Property); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
*s = nw
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// Definitions contains the models explicitly defined in this spec
2024-05-14 13:07:09 +00:00
// An object to hold data types that can be consumed and produced by operations.
2024-05-14 13:07:09 +00:00
// These data types can be primitives, arrays or models.
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// For more information: http://goo.gl/8us55a#definitionsObject
2024-05-14 13:07:09 +00:00
type Definitions map[string]Schema
// SecurityDefinitions a declaration of the security schemes available to be used in the specification.
2024-05-14 13:07:09 +00:00
// This does not enforce the security schemes on the operations and only serves to provide
2024-05-14 13:07:09 +00:00
// the relevant details for each scheme.
2024-05-14 13:07:09 +00:00
//
2024-05-14 13:07:09 +00:00
// For more information: http://goo.gl/8us55a#securityDefinitionsObject
2024-05-14 13:07:09 +00:00
type SecurityDefinitions map[string]*SecurityScheme
// StringOrArray represents a value that can either be a string
2024-05-14 13:07:09 +00:00
// or an array of strings. Mainly here for serialization purposes
2024-05-14 13:07:09 +00:00
type StringOrArray []string
// Contains returns true when the value is contained in the slice
2024-05-14 13:07:09 +00:00
func (s StringOrArray) Contains(value string) bool {
2024-05-14 13:07:09 +00:00
for _, str := range s {
2024-05-14 13:07:09 +00:00
if str == value {
2024-05-14 13:07:09 +00:00
return true
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return false
2024-05-14 13:07:09 +00:00
}
// JSONLookup implements an interface to customize json pointer lookup
2024-05-14 13:07:09 +00:00
func (s SchemaOrArray) JSONLookup(token string) (interface{}, error) {
2024-05-14 13:07:09 +00:00
if _, err := strconv.Atoi(token); err == nil {
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(s.Schemas, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
r, _, err := jsonpointer.GetForToken(s.Schema, token)
2024-05-14 13:07:09 +00:00
return r, err
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON unmarshals this string or array object from a JSON array or JSON string
2024-05-14 13:07:09 +00:00
func (s *StringOrArray) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
var first byte
2024-05-14 13:07:09 +00:00
if len(data) > 1 {
2024-05-14 13:07:09 +00:00
first = data[0]
2024-05-14 13:07:09 +00:00
}
if first == '[' {
2024-05-14 13:07:09 +00:00
var parsed []string
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &parsed); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
*s = StringOrArray(parsed)
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
var single interface{}
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &single); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if single == nil {
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
switch v := single.(type) {
2024-05-14 13:07:09 +00:00
case string:
2024-05-14 13:07:09 +00:00
*s = StringOrArray([]string{v})
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
default:
2024-05-14 13:07:09 +00:00
return fmt.Errorf("only string or array is allowed, not %T", single)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}
// MarshalJSON converts this string or array to a JSON array or JSON string
2024-05-14 13:07:09 +00:00
func (s StringOrArray) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
if len(s) == 1 {
2024-05-14 13:07:09 +00:00
return json.Marshal([]string(s)[0])
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return json.Marshal([]string(s))
2024-05-14 13:07:09 +00:00
}
// SchemaOrArray represents a value that can either be a Schema
2024-05-14 13:07:09 +00:00
// or an array of Schema. Mainly here for serialization purposes
2024-05-14 13:07:09 +00:00
type SchemaOrArray struct {
Schema *Schema
2024-05-14 13:07:09 +00:00
Schemas []Schema
}
// Len returns the number of schemas in this property
2024-05-14 13:07:09 +00:00
func (s SchemaOrArray) Len() int {
2024-05-14 13:07:09 +00:00
if s.Schema != nil {
2024-05-14 13:07:09 +00:00
return 1
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return len(s.Schemas)
2024-05-14 13:07:09 +00:00
}
// ContainsType returns true when one of the schemas is of the specified type
2024-05-14 13:07:09 +00:00
func (s *SchemaOrArray) ContainsType(name string) bool {
2024-05-14 13:07:09 +00:00
if s.Schema != nil {
2024-05-14 13:07:09 +00:00
return s.Schema.Type != nil && s.Schema.Type.Contains(name)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return false
2024-05-14 13:07:09 +00:00
}
// MarshalJSON converts this schema object or array into JSON structure
2024-05-14 13:07:09 +00:00
func (s SchemaOrArray) MarshalJSON() ([]byte, error) {
2024-05-14 13:07:09 +00:00
if len(s.Schemas) > 0 {
2024-05-14 13:07:09 +00:00
return json.Marshal(s.Schemas)
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
return json.Marshal(s.Schema)
2024-05-14 13:07:09 +00:00
}
// UnmarshalJSON converts this schema object or array from a JSON structure
2024-05-14 13:07:09 +00:00
func (s *SchemaOrArray) UnmarshalJSON(data []byte) error {
2024-05-14 13:07:09 +00:00
var nw SchemaOrArray
2024-05-14 13:07:09 +00:00
var first byte
2024-05-14 13:07:09 +00:00
if len(data) > 1 {
2024-05-14 13:07:09 +00:00
first = data[0]
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if first == '{' {
2024-05-14 13:07:09 +00:00
var sch Schema
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &sch); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
nw.Schema = &sch
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
if first == '[' {
2024-05-14 13:07:09 +00:00
if err := json.Unmarshal(data, &nw.Schemas); err != nil {
2024-05-14 13:07:09 +00:00
return err
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
}
2024-05-14 13:07:09 +00:00
*s = nw
2024-05-14 13:07:09 +00:00
return nil
2024-05-14 13:07:09 +00:00
}
// vim:set ft=go noet sts=2 sw=2 ts=2: