summaryrefslogtreecommitdiff
path: root/vendor/github.com/go-openapi/analysis
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-26 11:31:10 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-26 11:31:10 +0200
commitfd8a724e77123d5035d4070581dab777b4533ebb (patch)
tree0d3d20ad5c7c2177d970ead12f5108d1d3666623 /vendor/github.com/go-openapi/analysis
parent[chore] Upgrade our Go version to 1.22 (#2862) (diff)
downloadgotosocial-fd8a724e77123d5035d4070581dab777b4533ebb.tar.xz
[chore] Bump go swagger (#2871)
* bump go swagger version * bump swagger version
Diffstat (limited to 'vendor/github.com/go-openapi/analysis')
-rw-r--r--vendor/github.com/go-openapi/analysis/.golangci.yml53
-rw-r--r--vendor/github.com/go-openapi/analysis/README.md10
-rw-r--r--vendor/github.com/go-openapi/analysis/appveyor.yml32
-rw-r--r--vendor/github.com/go-openapi/analysis/doc.go10
-rw-r--r--vendor/github.com/go-openapi/analysis/flatten.go64
-rw-r--r--vendor/github.com/go-openapi/analysis/flatten_name.go39
-rw-r--r--vendor/github.com/go-openapi/analysis/flatten_options.go1
-rw-r--r--vendor/github.com/go-openapi/analysis/internal/debug/debug.go4
-rw-r--r--vendor/github.com/go-openapi/analysis/internal/flatten/replace/replace.go42
-rw-r--r--vendor/github.com/go-openapi/analysis/internal/flatten/sortref/keys.go2
-rw-r--r--vendor/github.com/go-openapi/analysis/mixin.go16
-rw-r--r--vendor/github.com/go-openapi/analysis/schema.go12
12 files changed, 153 insertions, 132 deletions
diff --git a/vendor/github.com/go-openapi/analysis/.golangci.yml b/vendor/github.com/go-openapi/analysis/.golangci.yml
index e24a6c14e..22f8d21cc 100644
--- a/vendor/github.com/go-openapi/analysis/.golangci.yml
+++ b/vendor/github.com/go-openapi/analysis/.golangci.yml
@@ -4,53 +4,58 @@ linters-settings:
golint:
min-confidence: 0
gocyclo:
- min-complexity: 40
- gocognit:
- min-complexity: 40
+ min-complexity: 45
maligned:
suggest-new: true
dupl:
- threshold: 150
+ threshold: 200
goconst:
min-len: 2
- min-occurrences: 4
+ min-occurrences: 3
linters:
enable-all: true
disable:
- maligned
+ - unparam
- lll
- - gochecknoglobals
- gochecknoinits
- # scopelint is useful, but also reports false positives
- # that unfortunately can't be disabled. So we disable the
- # linter rather than changing code that works.
- # see: https://github.com/kyoh86/scopelint/issues/4
- - scopelint
+ - gochecknoglobals
+ - funlen
- godox
- gocognit
- #- whitespace
+ - whitespace
- wsl
- - funlen
- - testpackage
- wrapcheck
- #- nlreturn
+ - testpackage
+ - nlreturn
- gomnd
- - goerr113
- exhaustivestruct
- #- errorlint
- #- nestif
- - gofumpt
+ - goerr113
+ - errorlint
+ - nestif
- godot
- - gci
- - dogsled
+ - gofumpt
- paralleltest
- tparallel
- thelper
- ifshort
- - forbidigo
- - cyclop
- - varnamelen
- exhaustruct
+ - varnamelen
+ - gci
+ - depguard
+ - errchkjson
+ - inamedparam
- nonamedreturns
+ - musttag
+ - ireturn
+ - forcetypeassert
+ - cyclop
+ # deprecated linters
+ - deadcode
+ - interfacer
+ - scopelint
+ - varcheck
+ - structcheck
+ - golint
- nosnakecase
diff --git a/vendor/github.com/go-openapi/analysis/README.md b/vendor/github.com/go-openapi/analysis/README.md
index aad6da10f..e005d4b37 100644
--- a/vendor/github.com/go-openapi/analysis/README.md
+++ b/vendor/github.com/go-openapi/analysis/README.md
@@ -1,8 +1,5 @@
-# OpenAPI initiative analysis
+# OpenAPI analysis [![Build Status](https://github.com/go-openapi/analysis/actions/workflows/go-test.yml/badge.svg)](https://github.com/go-openapi/analysis/actions?query=workflow%3A"go+test") [![codecov](https://codecov.io/gh/go-openapi/analysis/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/analysis)
-[![Build Status](https://travis-ci.org/go-openapi/analysis.svg?branch=master)](https://travis-ci.org/go-openapi/analysis)
-[![Build status](https://ci.appveyor.com/api/projects/status/x377t5o9ennm847o/branch/master?svg=true)](https://ci.appveyor.com/project/casualjim/go-openapi/analysis/branch/master)
-[![codecov](https://codecov.io/gh/go-openapi/analysis/branch/master/graph/badge.svg)](https://codecov.io/gh/go-openapi/analysis)
[![Slack Status](https://slackin.goswagger.io/badge.svg)](https://slackin.goswagger.io)
[![license](http://img.shields.io/badge/license-Apache%20v2-orange.svg)](https://raw.githubusercontent.com/go-openapi/analysis/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/go-openapi/analysis.svg)](https://pkg.go.dev/github.com/go-openapi/analysis)
@@ -13,12 +10,12 @@ A foundational library to analyze an OAI specification document for easier reaso
## What's inside?
-* A analyzer providing methods to walk the functional content of a specification
+* An analyzer providing methods to walk the functional content of a specification
* A spec flattener producing a self-contained document bundle, while preserving `$ref`s
* A spec merger ("mixin") to merge several spec documents into a primary spec
* A spec "fixer" ensuring that response descriptions are non empty
-[Documentation](https://godoc.org/github.com/go-openapi/analysis)
+[Documentation](https://pkg.go.dev/github.com/go-openapi/analysis)
## FAQ
@@ -28,4 +25,3 @@ A foundational library to analyze an OAI specification document for easier reaso
> This package currently only supports OpenAPI 2.0 (aka Swagger 2.0).
> There is no plan to make it evolve toward supporting OpenAPI 3.x.
> This [discussion thread](https://github.com/go-openapi/spec/issues/21) relates the full story.
->
diff --git a/vendor/github.com/go-openapi/analysis/appveyor.yml b/vendor/github.com/go-openapi/analysis/appveyor.yml
deleted file mode 100644
index c2f6fd733..000000000
--- a/vendor/github.com/go-openapi/analysis/appveyor.yml
+++ /dev/null
@@ -1,32 +0,0 @@
-version: "0.1.{build}"
-
-clone_folder: C:\go-openapi\analysis
-shallow_clone: true # for startup speed
-pull_requests:
- do_not_increment_build_number: true
-
-#skip_tags: true
-#skip_branch_with_pr: true
-
-# appveyor.yml
-build: off
-
-environment:
- GOPATH: c:\gopath
-
-stack: go 1.16
-
-test_script:
- - go test -v -timeout 20m ./...
-
-deploy: off
-
-notifications:
- - provider: Slack
- incoming_webhook: https://hooks.slack.com/services/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
- auth_token:
- secure: Sf7kZf7ZGbnwWUMpffHwMu5A0cHkLK2MYY32LNTPj4+/3qC3Ghl7+9v4TSLOqOlCwdRNjOGblAq7s+GDJed6/xgRQl1JtCi1klzZNrYX4q01pgTPvvGcwbBkIYgeMaPeIRcK9OZnud7sRXdttozgTOpytps2U6Js32ip7uj5mHSg2ub0FwoSJwlS6dbezZ8+eDhoha0F/guY99BEwx8Bd+zROrT2TFGsSGOFGN6wFc7moCqTHO/YkWib13a2QNXqOxCCVBy/lt76Wp+JkeFppjHlzs/2lP3EAk13RIUAaesdEUHvIHrzCyNJEd3/+KO2DzsWOYfpktd+KBCvgaYOsoo7ubdT3IROeAegZdCgo/6xgCEsmFc9ZcqCfN5yNx2A+BZ2Vwmpws+bQ1E1+B5HDzzaiLcYfG4X2O210QVGVDLWsv1jqD+uPYeHY2WRfh5ZsIUFvaqgUEnwHwrK44/8REAhQavt1QAj5uJpsRd7CkRVPWRNK+yIky+wgbVUFEchRNmS55E7QWf+W4+4QZkQi7vUTMc9nbTUu2Es9NfvfudOpM2wZbn98fjpb/qq/nRv6Bk+ca+7XD5/IgNLMbWp2ouDdzbiHLCOfDUiHiDJhLfFZx9Bwo7ZwfzeOlbrQX66bx7xRKYmOe4DLrXhNcpbsMa8qbfxlZRCmYbubB/Y8h4=
- channel: bots
- on_build_success: false
- on_build_failure: true
- on_build_status_changed: true
diff --git a/vendor/github.com/go-openapi/analysis/doc.go b/vendor/github.com/go-openapi/analysis/doc.go
index d5294c095..e8d9f9b13 100644
--- a/vendor/github.com/go-openapi/analysis/doc.go
+++ b/vendor/github.com/go-openapi/analysis/doc.go
@@ -16,27 +16,27 @@
Package analysis provides methods to work with a Swagger specification document from
package go-openapi/spec.
-Analyzing a specification
+## Analyzing a specification
An analysed specification object (type Spec) provides methods to work with swagger definition.
-Flattening or expanding a specification
+## Flattening or expanding a specification
Flattening a specification bundles all remote $ref in the main spec document.
Depending on flattening options, additional preprocessing may take place:
- full flattening: replacing all inline complex constructs by a named entry in #/definitions
- expand: replace all $ref's in the document by their expanded content
-Merging several specifications
+## Merging several specifications
Mixin several specifications merges all Swagger constructs, and warns about found conflicts.
-Fixing a specification
+## Fixing a specification
Unmarshalling a specification with golang json unmarshalling may lead to
some unwanted result on present but empty fields.
-Analyzing a Swagger schema
+## Analyzing a Swagger schema
Swagger schemas are analyzed to determine their complexity and qualify their content.
*/
diff --git a/vendor/github.com/go-openapi/analysis/flatten.go b/vendor/github.com/go-openapi/analysis/flatten.go
index 0576220fb..ebedcc9df 100644
--- a/vendor/github.com/go-openapi/analysis/flatten.go
+++ b/vendor/github.com/go-openapi/analysis/flatten.go
@@ -62,28 +62,26 @@ func newContext() *context {
//
// There is a minimal and a full flattening mode.
//
-//
// Minimally flattening a spec means:
-// - Expanding parameters, responses, path items, parameter items and header items (references to schemas are left
-// unscathed)
-// - Importing external (http, file) references so they become internal to the document
-// - Moving every JSON pointer to a $ref to a named definition (i.e. the reworked spec does not contain pointers
-// like "$ref": "#/definitions/myObject/allOfs/1")
+// - Expanding parameters, responses, path items, parameter items and header items (references to schemas are left
+// unscathed)
+// - Importing external (http, file) references so they become internal to the document
+// - Moving every JSON pointer to a $ref to a named definition (i.e. the reworked spec does not contain pointers
+// like "$ref": "#/definitions/myObject/allOfs/1")
//
// A minimally flattened spec thus guarantees the following properties:
-// - all $refs point to a local definition (i.e. '#/definitions/...')
-// - definitions are unique
+// - all $refs point to a local definition (i.e. '#/definitions/...')
+// - definitions are unique
//
// NOTE: arbitrary JSON pointers (other than $refs to top level definitions) are rewritten as definitions if they
// represent a complex schema or express commonality in the spec.
// Otherwise, they are simply expanded.
// Self-referencing JSON pointers cannot resolve to a type and trigger an error.
//
-//
// Minimal flattening is necessary and sufficient for codegen rendering using go-swagger.
//
// Fully flattening a spec means:
-// - Moving every complex inline schema to be a definition with an auto-generated name in a depth-first fashion.
+// - Moving every complex inline schema to be a definition with an auto-generated name in a depth-first fashion.
//
// By complex, we mean every JSON object with some properties.
// Arrays, when they do not define a tuple,
@@ -93,22 +91,21 @@ func newContext() *context {
// have been created.
//
// Available flattening options:
-// - Minimal: stops flattening after minimal $ref processing, leaving schema constructs untouched
-// - Expand: expand all $ref's in the document (inoperant if Minimal set to true)
-// - Verbose: croaks about name conflicts detected
-// - RemoveUnused: removes unused parameters, responses and definitions after expansion/flattening
+// - Minimal: stops flattening after minimal $ref processing, leaving schema constructs untouched
+// - Expand: expand all $ref's in the document (inoperant if Minimal set to true)
+// - Verbose: croaks about name conflicts detected
+// - RemoveUnused: removes unused parameters, responses and definitions after expansion/flattening
//
// NOTE: expansion removes all $ref save circular $ref, which remain in place
//
// TODO: additional options
-// - ProgagateNameExtensions: ensure that created entries properly follow naming rules when their parent have set a
-// x-go-name extension
-// - LiftAllOfs:
-// - limit the flattening of allOf members when simple objects
-// - merge allOf with validation only
-// - merge allOf with extensions only
-// - ...
-//
+// - ProgagateNameExtensions: ensure that created entries properly follow naming rules when their parent have set a
+// x-go-name extension
+// - LiftAllOfs:
+// - limit the flattening of allOf members when simple objects
+// - merge allOf with validation only
+// - merge allOf with extensions only
+// - ...
func Flatten(opts FlattenOpts) error {
debugLog("FlattenOpts: %#v", opts)
@@ -270,6 +267,12 @@ func nameInlinedSchemas(opts *FlattenOpts) error {
}
func removeUnused(opts *FlattenOpts) {
+ for removeUnusedSinglePass(opts) {
+ // continue until no unused definition remains
+ }
+}
+
+func removeUnusedSinglePass(opts *FlattenOpts) (hasRemoved bool) {
expected := make(map[string]struct{})
for k := range opts.Swagger().Definitions {
expected[path.Join(definitionsPath, jsonpointer.Escape(k))] = struct{}{}
@@ -280,6 +283,7 @@ func removeUnused(opts *FlattenOpts) {
}
for k := range expected {
+ hasRemoved = true
debugLog("removing unused definition %s", path.Base(k))
if opts.Verbose {
log.Printf("info: removing unused definition: %s", path.Base(k))
@@ -288,6 +292,8 @@ func removeUnused(opts *FlattenOpts) {
}
opts.Spec.reload() // re-analyze
+
+ return hasRemoved
}
func importKnownRef(entry sortref.RefRevIdx, refStr, newName string, opts *FlattenOpts) error {
@@ -334,7 +340,7 @@ func importNewRef(entry sortref.RefRevIdx, refStr string, opts *FlattenOpts) err
}
// generate a unique name - isOAIGen means that a naming conflict was resolved by changing the name
- newName, isOAIGen = uniqifyName(opts.Swagger().Definitions, nameFromRef(entry.Ref))
+ newName, isOAIGen = uniqifyName(opts.Swagger().Definitions, nameFromRef(entry.Ref, opts))
debugLog("new name for [%s]: %s - with name conflict:%t", strings.Join(entry.Keys, ", "), newName, isOAIGen)
opts.flattenContext.resolved[refStr] = newName
@@ -488,9 +494,9 @@ func stripPointersAndOAIGen(opts *FlattenOpts) error {
// stripOAIGen strips the spec from unnecessary OAIGen constructs, initially created to dedupe flattened definitions.
//
// A dedupe is deemed unnecessary whenever:
-// - the only conflict is with its (single) parent: OAIGen is merged into its parent (reinlining)
-// - there is a conflict with multiple parents: merge OAIGen in first parent, the rewrite other parents to point to
-// the first parent.
+// - the only conflict is with its (single) parent: OAIGen is merged into its parent (reinlining)
+// - there is a conflict with multiple parents: merge OAIGen in first parent, the rewrite other parents to point to
+// the first parent.
//
// This function returns true whenever it re-inlined a complex schema, so the caller may chose to iterate
// pointer and name resolution again.
@@ -652,6 +658,7 @@ func namePointers(opts *FlattenOpts) error {
refsToReplace := make(map[string]SchemaRef, len(opts.Spec.references.schemas))
for k, ref := range opts.Spec.references.allRefs {
+ debugLog("name pointers: %q => %#v", k, ref)
if path.Dir(ref.String()) == definitionsPath {
// this a ref to a top-level definition: ok
continue
@@ -769,6 +776,10 @@ func flattenAnonPointer(key string, v SchemaRef, refsToReplace map[string]Schema
// identifying edge case when the namer did nothing because we point to a non-schema object
// no definition is created and we expand the $ref for all callers
+ debugLog("decide what to do with the schema pointed to: asch.IsSimpleSchema=%t, len(callers)=%d, parts.IsSharedParam=%t, parts.IsSharedResponse=%t",
+ asch.IsSimpleSchema, len(callers), parts.IsSharedParam(), parts.IsSharedResponse(),
+ )
+
if (!asch.IsSimpleSchema || len(callers) > 1) && !parts.IsSharedParam() && !parts.IsSharedResponse() {
debugLog("replace JSON pointer at [%s] by definition: %s", key, v.Ref.String())
if err := namer.Name(v.Ref.String(), v.Schema, asch); err != nil {
@@ -791,6 +802,7 @@ func flattenAnonPointer(key string, v SchemaRef, refsToReplace map[string]Schema
return nil
}
+ // everything that is a simple schema and not factorizable is expanded
debugLog("expand JSON pointer for key=%s", key)
if err := replace.UpdateRefWithSchema(opts.Swagger(), key, v.Schema); err != nil {
diff --git a/vendor/github.com/go-openapi/analysis/flatten_name.go b/vendor/github.com/go-openapi/analysis/flatten_name.go
index 3ad2ccfbf..c7d7938eb 100644
--- a/vendor/github.com/go-openapi/analysis/flatten_name.go
+++ b/vendor/github.com/go-openapi/analysis/flatten_name.go
@@ -33,12 +33,14 @@ func (isn *InlineSchemaNamer) Name(key string, schema *spec.Schema, aschema *Ana
}
// create unique name
- newName, isOAIGen := uniqifyName(isn.Spec.Definitions, swag.ToJSONName(name))
+ mangle := mangler(isn.opts)
+ newName, isOAIGen := uniqifyName(isn.Spec.Definitions, mangle(name))
// clone schema
sch := schutils.Clone(schema)
// replace values on schema
+ debugLog("rewriting schema to ref: key=%s with new name: %s", key, newName)
if err := replace.RewriteSchemaToRef(isn.Spec, key,
spec.MustCreateRef(path.Join(definitionsPath, newName))); err != nil {
return fmt.Errorf("error while creating definition %q from inline schema: %w", newName, err)
@@ -149,13 +151,15 @@ func namesFromKey(parts sortref.SplitKey, aschema *AnalyzedSchema, operations ma
startIndex int
)
- if parts.IsOperation() {
+ switch {
+ case parts.IsOperation():
baseNames, startIndex = namesForOperation(parts, operations)
- }
-
- // definitions
- if parts.IsDefinition() {
+ case parts.IsDefinition():
baseNames, startIndex = namesForDefinition(parts)
+ default:
+ // this a non-standard pointer: build a name by concatenating its parts
+ baseNames = [][]string{parts}
+ startIndex = len(baseNames) + 1
}
result := make([]string, 0, len(baseNames))
@@ -169,6 +173,7 @@ func namesFromKey(parts sortref.SplitKey, aschema *AnalyzedSchema, operations ma
}
sort.Strings(result)
+ debugLog("names from parts: %v => %v", parts, result)
return result
}
@@ -256,10 +261,20 @@ func partAdder(aschema *AnalyzedSchema) sortref.PartAdder {
}
}
-func nameFromRef(ref spec.Ref) string {
+func mangler(o *FlattenOpts) func(string) string {
+ if o.KeepNames {
+ return func(in string) string { return in }
+ }
+
+ return swag.ToJSONName
+}
+
+func nameFromRef(ref spec.Ref, o *FlattenOpts) string {
+ mangle := mangler(o)
+
u := ref.GetURL()
if u.Fragment != "" {
- return swag.ToJSONName(path.Base(u.Fragment))
+ return mangle(path.Base(u.Fragment))
}
if u.Path != "" {
@@ -267,19 +282,19 @@ func nameFromRef(ref spec.Ref) string {
if bn != "" && bn != "/" {
ext := path.Ext(bn)
if ext != "" {
- return swag.ToJSONName(bn[:len(bn)-len(ext)])
+ return mangle(bn[:len(bn)-len(ext)])
}
- return swag.ToJSONName(bn)
+ return mangle(bn)
}
}
- return swag.ToJSONName(strings.ReplaceAll(u.Host, ".", " "))
+ return mangle(strings.ReplaceAll(u.Host, ".", " "))
}
// GenLocation indicates from which section of the specification (models or operations) a definition has been created.
//
-// This is reflected in the output spec with a "x-go-gen-location" extension. At the moment, this is is provided
+// This is reflected in the output spec with a "x-go-gen-location" extension. At the moment, this is provided
// for information only.
func GenLocation(parts sortref.SplitKey) string {
switch {
diff --git a/vendor/github.com/go-openapi/analysis/flatten_options.go b/vendor/github.com/go-openapi/analysis/flatten_options.go
index c5bb97b0a..c943fe1e8 100644
--- a/vendor/github.com/go-openapi/analysis/flatten_options.go
+++ b/vendor/github.com/go-openapi/analysis/flatten_options.go
@@ -26,6 +26,7 @@ type FlattenOpts struct {
Verbose bool // enable some reporting on possible name conflicts detected
RemoveUnused bool // When true, remove unused parameters, responses and definitions after expansion/flattening
ContinueOnError bool // Continue when spec expansion issues are found
+ KeepNames bool // Do not attempt to jsonify names from references when flattening
/* Extra keys */
_ struct{} // require keys
diff --git a/vendor/github.com/go-openapi/analysis/internal/debug/debug.go b/vendor/github.com/go-openapi/analysis/internal/debug/debug.go
index ec0fec022..39f55a97b 100644
--- a/vendor/github.com/go-openapi/analysis/internal/debug/debug.go
+++ b/vendor/github.com/go-openapi/analysis/internal/debug/debug.go
@@ -29,7 +29,7 @@ var (
// GetLogger provides a prefix debug logger
func GetLogger(prefix string, debug bool) func(string, ...interface{}) {
if debug {
- logger := log.New(output, fmt.Sprintf("%s:", prefix), log.LstdFlags)
+ logger := log.New(output, prefix+":", log.LstdFlags)
return func(msg string, args ...interface{}) {
_, file1, pos1, _ := runtime.Caller(1)
@@ -37,5 +37,5 @@ func GetLogger(prefix string, debug bool) func(string, ...interface{}) {
}
}
- return func(msg string, args ...interface{}) {}
+ return func(_ string, _ ...interface{}) {}
}
diff --git a/vendor/github.com/go-openapi/analysis/internal/flatten/replace/replace.go b/vendor/github.com/go-openapi/analysis/internal/flatten/replace/replace.go
index 26c2a05a3..c0f43e728 100644
--- a/vendor/github.com/go-openapi/analysis/internal/flatten/replace/replace.go
+++ b/vendor/github.com/go-openapi/analysis/internal/flatten/replace/replace.go
@@ -1,6 +1,7 @@
package replace
import (
+ "encoding/json"
"fmt"
"net/url"
"os"
@@ -40,6 +41,8 @@ func RewriteSchemaToRef(sp *spec.Swagger, key string, ref spec.Ref) error {
if refable.Schema != nil {
refable.Schema = &spec.Schema{SchemaProps: spec.SchemaProps{Ref: ref}}
}
+ case map[string]interface{}: // this happens e.g. if a schema points to an extension unmarshaled as map[string]interface{}
+ return rewriteParentRef(sp, key, ref)
default:
return fmt.Errorf("no schema with ref found at %s for %T", key, value)
}
@@ -120,6 +123,9 @@ func rewriteParentRef(sp *spec.Swagger, key string, ref spec.Ref) error {
case spec.SchemaProperties:
container[entry] = spec.Schema{SchemaProps: spec.SchemaProps{Ref: ref}}
+ case *interface{}:
+ *container = spec.Schema{SchemaProps: spec.SchemaProps{Ref: ref}}
+
// NOTE: can't have case *spec.SchemaOrBool = parent in this case is *Schema
default:
@@ -318,8 +324,8 @@ type DeepestRefResult struct {
}
// DeepestRef finds the first definition ref, from a cascade of nested refs which are not definitions.
-// - if no definition is found, returns the deepest ref.
-// - pointers to external files are expanded
+// - if no definition is found, returns the deepest ref.
+// - pointers to external files are expanded
//
// NOTE: all external $ref's are assumed to be already expanded at this stage.
func DeepestRef(sp *spec.Swagger, opts *spec.ExpandOptions, ref spec.Ref) (*DeepestRefResult, error) {
@@ -385,8 +391,9 @@ DOWNREF:
err := asSchema.UnmarshalJSON(asJSON)
if err != nil {
return nil,
- fmt.Errorf("invalid type for resolved JSON pointer %s. Expected a schema a, got: %T",
- currentRef.String(), value)
+ fmt.Errorf("invalid type for resolved JSON pointer %s. Expected a schema a, got: %T (%v)",
+ currentRef.String(), value, err,
+ )
}
warnings = append(warnings, fmt.Sprintf("found $ref %q (response) interpreted as schema", currentRef.String()))
@@ -402,8 +409,9 @@ DOWNREF:
var asSchema spec.Schema
if err := asSchema.UnmarshalJSON(asJSON); err != nil {
return nil,
- fmt.Errorf("invalid type for resolved JSON pointer %s. Expected a schema a, got: %T",
- currentRef.String(), value)
+ fmt.Errorf("invalid type for resolved JSON pointer %s. Expected a schema a, got: %T (%v)",
+ currentRef.String(), value, err,
+ )
}
warnings = append(warnings, fmt.Sprintf("found $ref %q (parameter) interpreted as schema", currentRef.String()))
@@ -414,9 +422,25 @@ DOWNREF:
currentRef = asSchema.Ref
default:
- return nil,
- fmt.Errorf("unhandled type to resolve JSON pointer %s. Expected a Schema, got: %T",
- currentRef.String(), value)
+ // fallback: attempts to resolve the pointer as a schema
+ if refable == nil {
+ break DOWNREF
+ }
+
+ asJSON, _ := json.Marshal(refable)
+ var asSchema spec.Schema
+ if err := asSchema.UnmarshalJSON(asJSON); err != nil {
+ return nil,
+ fmt.Errorf("unhandled type to resolve JSON pointer %s. Expected a Schema, got: %T (%v)",
+ currentRef.String(), value, err,
+ )
+ }
+ warnings = append(warnings, fmt.Sprintf("found $ref %q (%T) interpreted as schema", currentRef.String(), refable))
+
+ if asSchema.Ref.String() == "" {
+ break DOWNREF
+ }
+ currentRef = asSchema.Ref
}
}
diff --git a/vendor/github.com/go-openapi/analysis/internal/flatten/sortref/keys.go b/vendor/github.com/go-openapi/analysis/internal/flatten/sortref/keys.go
index 18e552ead..ac80fc2e8 100644
--- a/vendor/github.com/go-openapi/analysis/internal/flatten/sortref/keys.go
+++ b/vendor/github.com/go-openapi/analysis/internal/flatten/sortref/keys.go
@@ -69,7 +69,7 @@ func KeyParts(key string) SplitKey {
return res
}
-// SplitKey holds of the parts of a /-separated key, soi that their location may be determined.
+// SplitKey holds of the parts of a /-separated key, so that their location may be determined.
type SplitKey []string
// IsDefinition is true when the split key is in the #/definitions section of a spec
diff --git a/vendor/github.com/go-openapi/analysis/mixin.go b/vendor/github.com/go-openapi/analysis/mixin.go
index b25305264..7785a29b2 100644
--- a/vendor/github.com/go-openapi/analysis/mixin.go
+++ b/vendor/github.com/go-openapi/analysis/mixin.go
@@ -53,7 +53,7 @@ import (
// collisions.
func Mixin(primary *spec.Swagger, mixins ...*spec.Swagger) []string {
skipped := make([]string, 0, len(mixins))
- opIds := getOpIds(primary)
+ opIDs := getOpIDs(primary)
initPrimary(primary)
for i, m := range mixins {
@@ -74,7 +74,7 @@ func Mixin(primary *spec.Swagger, mixins ...*spec.Swagger) []string {
skipped = append(skipped, mergeDefinitions(primary, m)...)
// merging paths requires a map of operationIDs to work with
- skipped = append(skipped, mergePaths(primary, m, opIds, i)...)
+ skipped = append(skipped, mergePaths(primary, m, opIDs, i)...)
skipped = append(skipped, mergeParameters(primary, m)...)
@@ -84,9 +84,9 @@ func Mixin(primary *spec.Swagger, mixins ...*spec.Swagger) []string {
return skipped
}
-// getOpIds extracts all the paths.<path>.operationIds from the given
+// getOpIDs extracts all the paths.<path>.operationIds from the given
// spec and returns them as the keys in a map with 'true' values.
-func getOpIds(s *spec.Swagger) map[string]bool {
+func getOpIDs(s *spec.Swagger) map[string]bool {
rv := make(map[string]bool)
if s.Paths == nil {
return rv
@@ -179,7 +179,7 @@ func mergeDefinitions(primary *spec.Swagger, m *spec.Swagger) (skipped []string)
return
}
-func mergePaths(primary *spec.Swagger, m *spec.Swagger, opIds map[string]bool, mixIndex int) (skipped []string) {
+func mergePaths(primary *spec.Swagger, m *spec.Swagger, opIDs map[string]bool, mixIndex int) (skipped []string) {
if m.Paths != nil {
for k, v := range m.Paths.Paths {
if _, exists := primary.Paths.Paths[k]; exists {
@@ -198,10 +198,10 @@ func mergePaths(primary *spec.Swagger, m *spec.Swagger, opIds map[string]bool, m
// all the proivded specs are already unique.
piops := pathItemOps(v)
for _, piop := range piops {
- if opIds[piop.ID] {
+ if opIDs[piop.ID] {
piop.ID = fmt.Sprintf("%v%v%v", piop.ID, "Mixin", mixIndex)
}
- opIds[piop.ID] = true
+ opIDs[piop.ID] = true
}
primary.Paths.Paths[k] = v
}
@@ -367,7 +367,7 @@ func mergeSwaggerProps(primary *spec.Swagger, m *spec.Swagger) []string {
return skipped
}
-// nolint: unparam
+//nolint:unparam
func mergeExternalDocs(primary *spec.ExternalDocumentation, m *spec.ExternalDocumentation) []string {
if primary.Description == "" {
primary.Description = m.Description
diff --git a/vendor/github.com/go-openapi/analysis/schema.go b/vendor/github.com/go-openapi/analysis/schema.go
index fc055095c..ab190db5b 100644
--- a/vendor/github.com/go-openapi/analysis/schema.go
+++ b/vendor/github.com/go-openapi/analysis/schema.go
@@ -1,7 +1,7 @@
package analysis
import (
- "fmt"
+ "errors"
"github.com/go-openapi/spec"
"github.com/go-openapi/strfmt"
@@ -19,7 +19,7 @@ type SchemaOpts struct {
// patterns.
func Schema(opts SchemaOpts) (*AnalyzedSchema, error) {
if opts.Schema == nil {
- return nil, fmt.Errorf("no schema to analyze")
+ return nil, errors.New("no schema to analyze")
}
a := &AnalyzedSchema{
@@ -247,10 +247,10 @@ func (a *AnalyzedSchema) isArrayType() bool {
// isAnalyzedAsComplex determines if an analyzed schema is eligible to flattening (i.e. it is "complex").
//
// Complex means the schema is any of:
-// - a simple type (primitive)
-// - an array of something (items are possibly complex ; if this is the case, items will generate a definition)
-// - a map of something (additionalProperties are possibly complex ; if this is the case, additionalProperties will
-// generate a definition)
+// - a simple type (primitive)
+// - an array of something (items are possibly complex ; if this is the case, items will generate a definition)
+// - a map of something (additionalProperties are possibly complex ; if this is the case, additionalProperties will
+// generate a definition)
func (a *AnalyzedSchema) isAnalyzedAsComplex() bool {
return !a.IsSimpleSchema && !a.IsArray && !a.IsMap
}