1// Copyright 2015 go-swagger maintainers 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package analysis_test 16 17import ( 18 "fmt" 19 20 "github.com/go-openapi/analysis" // This package 21 "github.com/go-openapi/loads" // Spec loading 22) 23 24func ExampleSpec() { 25 // Example with spec file in this repo 26 path := "fixtures/flatten.yml" 27 doc, err := loads.Spec(path) // Load spec from file 28 if err == nil { 29 an := analysis.New(doc.Spec()) // Analyze spec 30 31 paths := an.AllPaths() 32 fmt.Printf("This spec contains %d paths", len(paths)) 33 } 34 // Output: This spec contains 2 paths 35} 36 37func ExampleFlatten() { 38 // Example with spec file in this repo 39 path := "fixtures/flatten.yml" 40 doc, err := loads.Spec(path) // Load spec from file 41 if err == nil { 42 an := analysis.New(doc.Spec()) // Analyze spec 43 // flatten the specification in doc 44 erf := analysis.Flatten(analysis.FlattenOpts{Spec: an, BasePath: path}) 45 if erf == nil { 46 fmt.Printf("Specification doc flattened") 47 } 48 // .. the analyzed spec has been updated and may be now used with the reworked spec 49 } 50 // Output: Specification doc flattened 51} 52