You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding ruby to the targets array generates Ruby code snippets. Tested it on Mac and Ubuntu. Code:
'use strict';constfs=require('fs');constOpenAPISnippet=require('openapi-snippet');constyaml=require('js-yaml');constargs=require('yargs').argv;lettargets=['node_request','shell_curl','shell_httpie','python_python3','php_curl','php_http1','php_http2','ruby'];if(args.targets){targets=args.targets.split(',');}functionenrichSchema(schema){for(varpathinschema.paths){for(varmethodinschema.paths[path]){vargeneratedCode=OpenAPISnippet.getEndpointSnippets(schema,path,method,targets);schema.paths[path][method]["x-codeSamples"]=[];for(varsnippetIdxingeneratedCode.snippets){varsnippet=generatedCode.snippets[snippetIdx];schema.paths[path][method]["x-codeSamples"][snippetIdx]={"lang": snippet.title,"source": snippet.content};}}}returnschema;}if(!args.input){thrownewError("Please pass the OpenAPI JSON schema as argument.");}// Try to interpret as YAML first, based on file extensionif(args.input.indexOf('yml')!==-1||args.input.indexOf('yaml')!==-1){try{letschema=yaml.safeLoad(fs.readFileSync(args.input,'utf8'));schema=enrichSchema(schema);console.log(JSON.stringify(schema));}catch(e){console.log(e);}}else{fs.readFile(args.input,(err,data)=>{if(err)throwerr;letschema=JSON.parse(data);schema=enrichSchema(schema);console.log(JSON.stringify(schema));});}
The text was updated successfully, but these errors were encountered:
Adding ruby to the targets array generates Ruby code snippets. Tested it on Mac and Ubuntu. Code:
The text was updated successfully, but these errors were encountered: