...

Source file src/github.com/go-openapi/analysis/internal/flatten/schutils/flatten_schema.go

Documentation: github.com/go-openapi/analysis/internal/flatten/schutils

     1  // Package schutils provides tools to save or clone a schema
     2  // when flattening a spec.
     3  package schutils
     4  
     5  import (
     6  	"github.com/go-openapi/spec"
     7  	"github.com/go-openapi/swag"
     8  )
     9  
    10  // Save registers a schema as an entry in spec #/definitions
    11  func Save(sp *spec.Swagger, name string, schema *spec.Schema) {
    12  	if schema == nil {
    13  		return
    14  	}
    15  
    16  	if sp.Definitions == nil {
    17  		sp.Definitions = make(map[string]spec.Schema, 150)
    18  	}
    19  
    20  	sp.Definitions[name] = *schema
    21  }
    22  
    23  // Clone deep-clones a schema
    24  func Clone(schema *spec.Schema) *spec.Schema {
    25  	var sch spec.Schema
    26  	_ = swag.FromDynamicJSON(schema, &sch)
    27  
    28  	return &sch
    29  }
    30  

View as plain text