openapi3_parser icon indicating copy to clipboard operation
openapi3_parser copied to clipboard

Convert the Openapi3Parser.load() output to hash or JSON

Open DanielRoig opened this issue 1 year ago • 7 comments

Hey! Congrats for you gem, it is really amazing! I was wondering if there is any way to convert the Openapi3Parser.load() output to hash or JSON. In my case I try something like this:

yaml_content = YAML.load_file(swagger.yaml)
schema = Openapi3Parser.load(yaml_content)
schema.to_h
{"openapi"=>"3.0.2", "info"=>Openapi3Parser::Node::Info(#/info), "externalDocs"=>Openapi3Parser::Node::ExternalDocumentation(#/externalDocs), "security"=>Openapi3Parser::Node::Array(#/security), "tags"=>Openapi3Parser::Node::Array(#/tags), "x-tagGroups"=>[{"name"=>"API V2 Resources", "tags"=>["prebuilt_collections-v2", "stocks-v2"]}, {"name"=>"API V1 Resources", "tags"=>["auth", "contract", "current_user", "feature_candidates", "feature_flags", "invitations", "investment_documents", "me", "nicknames", "prebuilt_collections", "payments", "payment_methods", "recommendation_advisories", "risk_profiles", "stock_positions", "subscription_plans", "surveys", "trading_sessions"]}], "paths"=>Openapi3Parser::Node::Paths(#/paths), "components"=>Openapi3Parser::Node::Components(#/components), "servers"=>Openapi3Parser::Node::Array(#/servers)}

But the nested Openapi3Parser objects still being objects. Are there any way to do this recursively (including the $ref resolved)? I've tried to do by myself but is really low performing. Maybe there is a method that Im missing.

Thank you!

DanielRoig avatar Dec 13 '24 15:12 DanielRoig