@hyperone/cli-ext-root-openapi-generator
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -1,1 +0,1 @@ | ||
module.exports=function(e){var t={};function r(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(a,n,function(t){return e[t]}.bind(null,n));return a},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t){e.exports=require("@hyperone/cli-core")},function(e,t){e.exports=require("@hyperone/cli-framework")},function(e){e.exports=JSON.parse('{"name":"@hyperone/cli-ext-root-openapi-generator","version":"1.0.13","description":"","main":"dist/index.js","browser":"index.js","scripts":{"prepack":"NODE_ENV=production webpack","build":"webpack","watch":"webpack --watch","clean":"rm dist -rf"},"devDependencies":{"webpack":"^4.43.0","webpack-cli":"^3.3.12","webpack-dev-server":"^3.11.0"},"author":"Adam Dobrawy","license":"MIT","dependencies":{"@hyperone/cli-core":"^1.0.13","@hyperone/cli-framework":"^1.0.12","jsonpatch":"^3.0.1","openapi-sampler":"^1.0.0-beta.16","pluralize":"^8.0.0"},"gitHead":"ffed02ce77a52b163cab5ce701d538186609d679","publishConfig":{"access":"public"}}')},function(e,t,r){e.exports=function(){var e=[],t=[],r={},a={},n={};function o(e){return"string"==typeof e?new RegExp("^"+e+"$","i"):e}function i(e,t){return e===t?t:e===e.toLowerCase()?t.toLowerCase():e===e.toUpperCase()?t.toUpperCase():e[0]===e[0].toUpperCase()?t.charAt(0).toUpperCase()+t.substr(1).toLowerCase():t.toLowerCase()}function s(e,t){return e.replace(/\$(\d{1,2})/g,(function(e,r){return t[r]||""}))}function u(e,t){return e.replace(t[0],(function(r,a){var n=s(t[1],arguments);return i(""===r?e[a-1]:r,n)}))}function p(e,t,a){if(!e.length||r.hasOwnProperty(e))return t;for(var n=a.length;n--;){var o=a[n];if(o[0].test(t))return u(t,o)}return t}function c(e,t,r){return function(a){var n=a.toLowerCase();return t.hasOwnProperty(n)?i(a,n):e.hasOwnProperty(n)?i(a,e[n]):p(n,a,r)}}function l(e,t,r,a){return function(a){var n=a.toLowerCase();return!!t.hasOwnProperty(n)||!e.hasOwnProperty(n)&&p(n,n,r)===n}}function d(e,t,r){return(r?t+" ":"")+(1===t?d.singular(e):d.plural(e))}return d.plural=c(n,a,e),d.isPlural=l(n,a,e),d.singular=c(a,n,t),d.isSingular=l(a,n,t),d.addPluralRule=function(t,r){e.push([o(t),r])},d.addSingularRule=function(e,r){t.push([o(e),r])},d.addUncountableRule=function(e){"string"!=typeof e?(d.addPluralRule(e,"$0"),d.addSingularRule(e,"$0")):r[e.toLowerCase()]=!0},d.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),n[e]=t,a[t]=e},[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"]].forEach((function(e){return d.addIrregularRule(e[0],e[1])})),[[/s?$/i,"s"],[/[^\u0000-\u007F]$/i,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach((function(e){return d.addPluralRule(e[0],e[1])})),[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach((function(e){return d.addSingularRule(e[0],e[1])})),["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","species","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(d.addUncountableRule),d}()},function(e,t,r){"use strict";r.r(t),r.d(t,"makeOperationCommand",(function(){return g})),r.d(t,"makeResourceCommand",(function(){return y})),r.d(t,"buildNamespaceCommand",(function(){return b}));var a=r(3),n=r.n(a),o=r(1),i=r(0);const s=e=>String(e).replace(/([a-z])([A-Z])/,(e,t,r)=>`${t}-${r}`).toLowerCase(),u=(e,t,r)=>{const a=String.prototype.split.call(t,/[,[\].]+?/).filter(Boolean);let n=e;for(const e of a.slice(0,-1))void 0===n[e]&&(n[e]={}),n=n[e];n[a[a.length-1]]=r};var p={extractId:e=>e.startsWith("/")?e.split("/").pop():e,nestedValue:e=>{const t={};for(const r of e.split(",")){const[e,a]=r.split(/=/,2);t[e]=a}return t}};const c=e=>e.replace(/Id$/,""),l=(e=[])=>{const t=[];for(const r of e){const e=c(r.name),a=[r.description],n={name:s(e),use:{in:r.in,field:r.name}};r.name.endsWith("Id")&&Object.assign(n,{required:!0,defaultSource:e,type:p.extractId,typeLabel:"id-or-uri"}),t.push({...n,description:a.join(".")})}return t},d=(e,t="",r="")=>{const a=[];for(const[n,o]of Object.entries(e.properties||{})){const u=[],c=e.required||[],l={name:`${t}${s(n)}`,required:c.includes(n),use:{in:"body",field:`${r}/${n}`}};if(o.title&&u.push(o.title),o.readOnly)continue;const m=o["x-audience"];if(!m||["user","all"].includes(m)){if(o["x-resource"]){Object.assign(l,{typeLabel:"uri"});const e=i.openapi.getEndpointForKind(o["x-resource"].kind);1==e.length?(Object.assign(l,{typeLabel:"id-or-uri",prefix:e[0]}),u.push("Provide ID or URI of "+o["x-resource"].kind)):u.push("Provide URI of "+o["x-resource"].kind)}if(o["x-permissions"]&&u.push("Requires permissions "+o["x-permissions"].join(", ")),"string"==o.type&&Object.assign(l,{placeholder:n}),"array"==o.type&&"string"==o.items.type&&Object.assign(l,{multiple:!0}),"boolean"==o.type){const e=[!0,!1].map(String);Object.assign(l,{type:e=>"true"==e,typeLabel:e.join(","),choices:e})}if("object"!=o.type){if("array"==o.type&&"object"==o.items.type){const e=Object.entries(o.items.properties||{}).filter(([,e])=>1!=e.readOnly).map(([e])=>`${e}=${e}`).join(",");Object.assign(l,{multiple:!0,typeLabel:e,type:p.nestedValue})}o.default&&(u.push("Defaults is "+o.default),Object.assign(l,{defaultValue:o.default})),Object.assign(l,{description:u.join(". ")}),a.push(l)}else a.push(...d(o,t?`${t}-${n}`:n+"-",`${r}/${n}`))}}return a},m=e=>{if(e.allOf){const t={};for(const r of e.allOf)Object.assign(t,r.properties);return{type:"object",properties:t}}return e},f=(e,t)=>{const r={};for(const a of t.filter(e=>e.use))e[a.name]&&["path","query"].includes(a.use.in)&&(r[a.use.field]=e[a.name]);return r};var h={renderOptions:(e,t=[])=>{const r=i.openapi.getSchema(e);return[...l(t),...d(m(r))]},renderBody:(e,t,r)=>{const a={},n=f(t,r);for(const e of r){if(!e.use||"body"!=e.use.in)continue;let r=t[e.name];void 0!==r&&(r!=e.defaultValue&&(e.prefix&&r&&!r.startsWith("/")&&(r=i.openapi.renderPath(e.prefix,{...n,[e.name+"Id"]:r})),u(a,e.use.field.replace(/\//g,"."),r)))}return a},renderQuery:(e,t)=>Object.fromEntries(t.filter(t=>t.use&&"query"==t.use.in&&e[t.name]).map(t=>[t.use.field,e[t.name]])),generateQuery:(e,t)=>{const r=i.openapi.getResponse(t)||{},a=[];let n;if("array"==r.type?n=r.items.properties||{}:"object"==r.type&&(n=r.properties||{}),n)for(const e of["id","name","state","flavour","content","enabled","size"])n[e]&&a.push(`${e}:${e}`);return 0==a.length&&a.push("value:@"),`[].{${a.join(",")}}`},renderParameter:f};const $=(e,t)=>new o.Command({name:e,summary:"Print specification of context",handler:()=>t}),g=({name:e,endpoint:t,method:r,path:a})=>()=>{const n=t[r],s=[...n.parameters||[],...t.parameters||[]],u=h.renderOptions(n,s);return new o.Command({name:e,summary:`${n.summary} [${n.operationId}]`,options:[...u,{name:"skeleton",type:e=>"true"==e,typeLabel:"true,false",choices:["true","false"]}],tags:[n.operationId],handler:async e=>{const t=e._all||e,o=h.renderParameter(t,u),s=i.openapi.getUrl(a,o),p=h.renderQuery(t,u);let c;if(e.defaultQuery=h.generateQuery(a,n,t),["post","patch","put"].includes(r)&&(c=h.renderBody(n,t,u)),t.skeleton)return{parameters:o,requestBody:c||{}};const l=await e.api[r](s,{json:c,query:p});return e.format(e,l)}})},y=(e,t)=>()=>{const r=new o.Category({name:s(e.type),summary:t.description||`Management of ${e.type} resource`});r.addCommand(()=>$("spec",t));const a=i.openapi.getPath(t.path)||{};a&&(a.post&&r.addCommand(g({...t,name:"create",method:"post",endpoint:a})),a.get&&r.addCommand(g({...t,name:"list",method:"get",endpoint:a})),a.patch&&r.addCommand(g({...t,name:"update",method:"patch",endpoint:a})));for(const{path:a,endpoint:o}of i.openapi.getDetail(t.path)){o.get&&r.addCommand(g({...t,name:"show",method:"get",endpoint:o,path:a})),o.patch&&r.addCommand(g({...t,name:"update",method:"patch",endpoint:o,path:a})),o.delete&&r.addCommand(g({...t,name:"delete",method:"delete",endpoint:o,path:a}));for(const{name:e,path:n,endpoint:o}of i.openapi.getActions(a))for(const a of["post","get"])o[a]&&r.addCommand(g({...t,name:e,method:a,path:n,endpoint:o}));for(const t of i.openapi.getChild(a))r.addCommand(y(t,{path:t.path,description:`Manage ${n()(t.type)} of the ${e.type}`}))}return r},b=(e,t,r)=>async()=>{const a=new o.Category({name:e,summary:`Management of ${e} namespace`,extensions:["@hyperone/cli-ext-"+e]});a.addCommand($("spec",t));const n=[...i.openapi.getChild(r.path)];"iam"!==e&&n.push(...i.openapi.getChild(r.path+"/project/{projectId}"),...i.openapi.getChild(r.path+"/{locationId}/project/{projectId}"));for(const e of n)a.addCommand(y(e,{path:e.path,description:`Management of ${e.type} resource`}));return a};t.default={name:r(2).name,version:r(2).version,load:async e=>{const t=i.openapi.getNamespaces();for(const[r,a]of Object.entries(t))await e.addCommand(b(r,a,{path:"/"+r}))}}}]); | ||
module.exports=function(e){var t={};function r(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(a,n,function(t){return e[t]}.bind(null,n));return a},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}([function(e,t){e.exports=require("@hyperone/cli-core")},function(e,t){e.exports=require("@hyperone/cli-framework")},function(e){e.exports=JSON.parse('{"name":"@hyperone/cli-ext-root-openapi-generator","version":"1.0.14","description":"","main":"dist/index.js","browser":"index.js","scripts":{"prepack":"NODE_ENV=production webpack","build":"webpack","watch":"webpack --watch","clean":"rm dist -rf"},"devDependencies":{"webpack":"^4.43.0","webpack-cli":"^3.3.12","webpack-dev-server":"^3.11.0"},"author":"Adam Dobrawy","license":"MIT","dependencies":{"@hyperone/cli-core":"^1.0.14","@hyperone/cli-framework":"^1.0.12","jsonpatch":"^3.0.1","openapi-sampler":"^1.0.0-beta.16","pluralize":"^8.0.0"},"gitHead":"89c15fc66c5ac441bd909c77bb9e05fc8eb433ef","publishConfig":{"access":"public"}}')},function(e,t,r){e.exports=function(){var e=[],t=[],r={},a={},n={};function o(e){return"string"==typeof e?new RegExp("^"+e+"$","i"):e}function i(e,t){return e===t?t:e===e.toLowerCase()?t.toLowerCase():e===e.toUpperCase()?t.toUpperCase():e[0]===e[0].toUpperCase()?t.charAt(0).toUpperCase()+t.substr(1).toLowerCase():t.toLowerCase()}function s(e,t){return e.replace(/\$(\d{1,2})/g,(function(e,r){return t[r]||""}))}function u(e,t){return e.replace(t[0],(function(r,a){var n=s(t[1],arguments);return i(""===r?e[a-1]:r,n)}))}function c(e,t,a){if(!e.length||r.hasOwnProperty(e))return t;for(var n=a.length;n--;){var o=a[n];if(o[0].test(t))return u(t,o)}return t}function p(e,t,r){return function(a){var n=a.toLowerCase();return t.hasOwnProperty(n)?i(a,n):e.hasOwnProperty(n)?i(a,e[n]):c(n,a,r)}}function l(e,t,r,a){return function(a){var n=a.toLowerCase();return!!t.hasOwnProperty(n)||!e.hasOwnProperty(n)&&c(n,n,r)===n}}function d(e,t,r){return(r?t+" ":"")+(1===t?d.singular(e):d.plural(e))}return d.plural=p(n,a,e),d.isPlural=l(n,a,e),d.singular=p(a,n,t),d.isSingular=l(a,n,t),d.addPluralRule=function(t,r){e.push([o(t),r])},d.addSingularRule=function(e,r){t.push([o(e),r])},d.addUncountableRule=function(e){"string"!=typeof e?(d.addPluralRule(e,"$0"),d.addSingularRule(e,"$0")):r[e.toLowerCase()]=!0},d.addIrregularRule=function(e,t){t=t.toLowerCase(),e=e.toLowerCase(),n[e]=t,a[t]=e},[["I","we"],["me","us"],["he","they"],["she","they"],["them","them"],["myself","ourselves"],["yourself","yourselves"],["itself","themselves"],["herself","themselves"],["himself","themselves"],["themself","themselves"],["is","are"],["was","were"],["has","have"],["this","these"],["that","those"],["echo","echoes"],["dingo","dingoes"],["volcano","volcanoes"],["tornado","tornadoes"],["torpedo","torpedoes"],["genus","genera"],["viscus","viscera"],["stigma","stigmata"],["stoma","stomata"],["dogma","dogmata"],["lemma","lemmata"],["schema","schemata"],["anathema","anathemata"],["ox","oxen"],["axe","axes"],["die","dice"],["yes","yeses"],["foot","feet"],["eave","eaves"],["goose","geese"],["tooth","teeth"],["quiz","quizzes"],["human","humans"],["proof","proofs"],["carve","carves"],["valve","valves"],["looey","looies"],["thief","thieves"],["groove","grooves"],["pickaxe","pickaxes"],["passerby","passersby"]].forEach((function(e){return d.addIrregularRule(e[0],e[1])})),[[/s?$/i,"s"],[/[^\u0000-\u007F]$/i,"$0"],[/([^aeiou]ese)$/i,"$1"],[/(ax|test)is$/i,"$1es"],[/(alias|[^aou]us|t[lm]as|gas|ris)$/i,"$1es"],[/(e[mn]u)s?$/i,"$1s"],[/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i,"$1"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1i"],[/(alumn|alg|vertebr)(?:a|ae)$/i,"$1ae"],[/(seraph|cherub)(?:im)?$/i,"$1im"],[/(her|at|gr)o$/i,"$1oes"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i,"$1a"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i,"$1a"],[/sis$/i,"ses"],[/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i,"$1$2ves"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/([^ch][ieo][ln])ey$/i,"$1ies"],[/(x|ch|ss|sh|zz)$/i,"$1es"],[/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i,"$1ices"],[/\b((?:tit)?m|l)(?:ice|ouse)$/i,"$1ice"],[/(pe)(?:rson|ople)$/i,"$1ople"],[/(child)(?:ren)?$/i,"$1ren"],[/eaux$/i,"$0"],[/m[ae]n$/i,"men"],["thou","you"]].forEach((function(e){return d.addPluralRule(e[0],e[1])})),[[/s$/i,""],[/(ss)$/i,"$1"],[/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i,"$1fe"],[/(ar|(?:wo|[ae])l|[eo][ao])ves$/i,"$1f"],[/ies$/i,"y"],[/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i,"$1ie"],[/\b(mon|smil)ies$/i,"$1ey"],[/\b((?:tit)?m|l)ice$/i,"$1ouse"],[/(seraph|cherub)im$/i,"$1"],[/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i,"$1"],[/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i,"$1sis"],[/(movie|twelve|abuse|e[mn]u)s$/i,"$1"],[/(test)(?:is|es)$/i,"$1is"],[/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i,"$1us"],[/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i,"$1um"],[/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i,"$1on"],[/(alumn|alg|vertebr)ae$/i,"$1a"],[/(cod|mur|sil|vert|ind)ices$/i,"$1ex"],[/(matr|append)ices$/i,"$1ix"],[/(pe)(rson|ople)$/i,"$1rson"],[/(child)ren$/i,"$1"],[/(eau)x?$/i,"$1"],[/men$/i,"man"]].forEach((function(e){return d.addSingularRule(e[0],e[1])})),["adulthood","advice","agenda","aid","aircraft","alcohol","ammo","analytics","anime","athletics","audio","bison","blood","bream","buffalo","butter","carp","cash","chassis","chess","clothing","cod","commerce","cooperation","corps","debris","diabetes","digestion","elk","energy","equipment","excretion","expertise","firmware","flounder","fun","gallows","garbage","graffiti","hardware","headquarters","health","herpes","highjinks","homework","housework","information","jeans","justice","kudos","labour","literature","machinery","mackerel","mail","media","mews","moose","music","mud","manga","news","only","personnel","pike","plankton","pliers","police","pollution","premises","rain","research","rice","salmon","scissors","series","sewage","shambles","shrimp","software","species","staff","swine","tennis","traffic","transportation","trout","tuna","wealth","welfare","whiting","wildebeest","wildlife","you",/pok[eé]mon$/i,/[^aeiou]ese$/i,/deer$/i,/fish$/i,/measles$/i,/o[iu]s$/i,/pox$/i,/sheep$/i].forEach(d.addUncountableRule),d}()},function(e,t,r){"use strict";r.r(t),r.d(t,"makeOperationCommand",(function(){return g})),r.d(t,"makeResourceCommand",(function(){return y})),r.d(t,"buildNamespaceCommand",(function(){return b}));var a=r(3),n=r.n(a),o=r(1),i=r(0);const s=e=>String(e).replace(/([a-z])([A-Z])/,(e,t,r)=>`${t}-${r}`).toLowerCase(),u=(e,t,r)=>{const a=String.prototype.split.call(t,/[,[\].]+?/).filter(Boolean);let n=e;for(const e of a.slice(0,-1))void 0===n[e]&&(n[e]={}),n=n[e];n[a[a.length-1]]=r};var c={extractId:e=>e.startsWith("/")?e.split("/").pop():e,nestedValue:e=>{const t={};for(const r of e.split(",")){const[e,a]=r.split(/=/,2);t[e]=a}return t}};const p=e=>e.replace(/Id$/,""),l=(e=[])=>{const t=[];for(const r of e){const e=p(r.name),a=[r.description],n={name:s(e),use:{in:r.in,field:r.name}};r.name.endsWith("Id")&&Object.assign(n,{required:!0,defaultSource:e,type:c.extractId,typeLabel:"id-or-uri"}),t.push({...n,description:a.join(".")})}return t},d=(e,t="",r="")=>{const a=[];for(const[n,o]of Object.entries(e.properties||{})){const u=[],p=e.required||[],l={name:`${t}${s(n)}`,required:p.includes(n),use:{in:"body",field:`${r}/${n}`}};if(o.title&&u.push(o.title),o.readOnly)continue;const m=o["x-audience"];if(!m||["user","all"].includes(m)){if(o["x-resource"]){Object.assign(l,{typeLabel:"uri"});const e=i.openapi.getEndpointForKind(o["x-resource"].kind);1==e.length?(Object.assign(l,{typeLabel:"id-or-uri",prefix:e[0]}),u.push("Provide ID or URI of "+o["x-resource"].kind)):u.push("Provide URI of "+o["x-resource"].kind)}if(o["x-permissions"]&&u.push("Requires permissions "+o["x-permissions"].join(", ")),"string"==o.type&&Object.assign(l,{placeholder:n}),"array"==o.type&&"string"==o.items.type&&Object.assign(l,{multiple:!0}),"boolean"==o.type){const e=[!0,!1].map(String);Object.assign(l,{type:e=>"true"==e,typeLabel:e.join(","),choices:e})}if("object"!=o.type){if("array"==o.type&&"object"==o.items.type){const e=Object.entries(o.items.properties||{}).filter(([,e])=>1!=e.readOnly).map(([e])=>`${e}=${e}`).join(",");Object.assign(l,{multiple:!0,typeLabel:e,type:c.nestedValue})}o.default&&(u.push("Defaults is "+o.default),Object.assign(l,{defaultValue:o.default})),Object.assign(l,{description:u.join(". ")}),a.push(l)}else a.push(...d(o,t?`${t}-${n}`:n+"-",`${r}/${n}`))}}return a},m=e=>{if(e.allOf){const t={};for(const r of e.allOf)Object.assign(t,r.properties);return{type:"object",properties:t}}return e},f=(e,t)=>{const r={};for(const a of t.filter(e=>e.use))e[a.name]&&["path","query"].includes(a.use.in)&&(r[a.use.field]=e[a.name]);return r};var h={renderOptions:(e,t=[])=>{const r=i.openapi.getSchema(e);return[...l(t),...d(m(r))]},renderBody:(e,t,r)=>{const a={},n=f(t,r);for(const e of r){if(!e.use||"body"!=e.use.in)continue;let r=t[e.name];void 0!==r&&(r!=e.defaultValue&&(e.prefix&&r&&!r.startsWith("/")&&(r=i.openapi.renderPath(e.prefix,{...n,[e.name+"Id"]:r})),u(a,e.use.field.replace(/\//g,"."),r)))}return a},renderQuery:(e,t)=>Object.fromEntries(t.filter(t=>t.use&&"query"==t.use.in&&e[t.name]).map(t=>[t.use.field,e[t.name]])),generateQuery:(e,t)=>{const r=i.openapi.getResponse(t)||{},a=[];let n;if("array"==r.type?n=r.items.properties||{}:"object"==r.type&&(n=r.properties||{}),n)for(const e of["id","name","state","flavour","content","enabled","size"])n[e]&&a.push(`${e}:${e}`);return 0==a.length&&a.push("value:@"),`[].{${a.join(",")}}`},renderParameter:f};const $=(e,t)=>new o.Command({name:e,summary:"Print specification of context",handler:()=>t}),g=({name:e,endpoint:t,method:r,path:a})=>()=>{const n=t[r],s=[...n.parameters||[],...t.parameters||[]],u=h.renderOptions(n,s);return new o.Command({name:e,summary:`${n.summary} [${n.operationId}]`,options:[...u,{name:"skeleton",type:e=>"true"==e,typeLabel:"true,false",choices:["true","false"]}],tags:[n.operationId],handler:async e=>{const t=e._all||e,o=h.renderParameter(t,u),s=i.openapi.getUrl(a,o),c=h.renderQuery(t,u);let p;if(e.defaultQuery=h.generateQuery(a,n,t),["post","patch","put"].includes(r)&&(p=h.renderBody(n,t,u)),t.skeleton)return{parameters:o,requestBody:p||{}};const l=await e.api[r](s,{json:p,query:c});return e.format(e,l)}})},y=(e,t)=>()=>{const r=new o.Category({name:s(e.type),summary:t.description||`Management of ${e.type} resource`});r.addCommand(()=>$("spec",t));const a=i.openapi.getPath(t.path)||{};a&&(a.post&&r.addCommand(g({...t,name:"create",method:"post",endpoint:a})),a.get&&r.addCommand(g({...t,name:"list",method:"get",endpoint:a})),a.patch&&r.addCommand(g({...t,name:"update",method:"patch",endpoint:a})));for(const{path:a,endpoint:o}of i.openapi.getDetail(t.path)){o.get&&r.addCommand(g({...t,name:"show",method:"get",endpoint:o,path:a})),o.patch&&r.addCommand(g({...t,name:"update",method:"patch",endpoint:o,path:a})),o.delete&&r.addCommand(g({...t,name:"delete",method:"delete",endpoint:o,path:a}));for(const{name:e,path:n,endpoint:o}of i.openapi.getActions(a))for(const a of["post","get"])o[a]&&r.addCommand(g({...t,name:e,method:a,path:n,endpoint:o}));for(const t of i.openapi.getChild(a))r.addCommand(y(t,{path:t.path,description:`Manage ${n()(t.type)} of the ${e.type}`}))}return r},b=(e,t,r)=>async()=>{const a=new o.Category({name:e,summary:`Management of ${e} namespace`,extensions:["@hyperone/cli-ext-"+e]});a.addCommand($("spec",t));const n=[...i.openapi.getChild(r.path)];"iam"!==e&&n.push(...i.openapi.getChild(r.path+"/project/{projectId}"),...i.openapi.getChild(r.path+"/{locationId}/project/{projectId}"));for(const e of n)a.addCommand(y(e,{path:e.path,description:`Management of ${e.type} resource`}));return a};t.default={name:r(2).name,version:r(2).version,load:async e=>{const t=i.openapi.getNamespaces();for(const[r,a]of Object.entries(t))await e.addCommand(b(r,a,{path:"/"+r}))}}}]); |
{ | ||
"name": "@hyperone/cli-ext-root-openapi-generator", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"description": "", | ||
@@ -21,3 +21,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@hyperone/cli-core": "^1.0.13", | ||
"@hyperone/cli-core": "^1.0.14", | ||
"@hyperone/cli-framework": "^1.0.12", | ||
@@ -28,3 +28,3 @@ "jsonpatch": "^3.0.1", | ||
}, | ||
"gitHead": "ffed02ce77a52b163cab5ce701d538186609d679", | ||
"gitHead": "89c15fc66c5ac441bd909c77bb9e05fc8eb433ef", | ||
"publishConfig": { | ||
@@ -31,0 +31,0 @@ "access": "public" |
Updated@hyperone/cli-core@^1.0.14