-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change API parser to handle nested objects (#159)
* rewrite parser to handle new format and nested objects * add properties section also to nested properties * update docs manually
- Loading branch information
1 parent
69cddad
commit dd08a8e
Showing
23 changed files
with
4,241 additions
and
1,259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/pb33f/libopenapi/index" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func main() { | ||
|
||
// if len(os.Args) != 1 { | ||
// fmt.Printf("No input file provided!\n") | ||
// } | ||
|
||
// load an OpenAPI 3 specification from bytes | ||
// petstore, _ := ioutil.ReadFile(os.Args[0]) | ||
petstore, _ := ioutil.ReadFile("openapi/openapi.yml") | ||
|
||
// create a root node to unmarshal the spec into. | ||
var rootNode yaml.Node | ||
_ = yaml.Unmarshal(petstore, &rootNode) | ||
|
||
// create a new config that does not allow lookups. | ||
indexConfig := index.CreateClosedAPIIndexConfig() | ||
|
||
// create a new rolodex | ||
rolodex := index.NewRolodex(indexConfig) | ||
|
||
// set the rolodex root node to the root node of the spec. | ||
rolodex.SetRootNode(&rootNode) | ||
|
||
// index the rolodex | ||
indexedErr := rolodex.IndexTheRolodex() | ||
if indexedErr != nil { | ||
panic(indexedErr) | ||
} | ||
|
||
// resolve the petstore | ||
rolodex.Resolve() | ||
|
||
// extract the resolver from the root index. | ||
node := rolodex.GetRootNode() | ||
|
||
b, e := yaml.Marshal(node) | ||
if e != nil { | ||
panic(e) | ||
} | ||
|
||
var newNode yaml.Node | ||
_ = yaml.Unmarshal(b, &newNode) | ||
|
||
err := os.WriteFile("openapi/expanded.yml", b, 0644) | ||
if err != nil { | ||
fmt.Printf("Failed to write file: %v", err) | ||
return | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module generator | ||
|
||
go 1.21.1 | ||
|
||
require github.com/pb33f/libopenapi v0.15.13 | ||
|
||
require ( | ||
github.com/bahlo/generic-list-go v0.2.0 // indirect | ||
github.com/buger/jsonparser v1.1.1 // indirect | ||
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect | ||
github.com/mailru/easyjson v0.7.7 // indirect | ||
github.com/vmware-labs/yaml-jsonpath v0.3.2 // indirect | ||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect | ||
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect | ||
golang.org/x/sync v0.6.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.