From 8e20b2024b62dce3c4583c657cc593bac09211a3 Mon Sep 17 00:00:00 2001 From: Philip Makedonski <makedonski@informatik.uni-goettingen.de> Date: Fri, 7 Apr 2023 10:59:31 +0200 Subject: [PATCH] + added basic openapi wrapper launcher ui (validation disabled) * need new icon, need additional integration, in case also a wizard --- .../.classpath | 7 ++ .../.project | 28 +++++ .../.settings/org.eclipse.jdt.core.prefs | 10 ++ .../META-INF/MANIFEST.MF | 15 +++ .../build.properties | 6 + .../icons/TransformIcon.png | Bin 0 -> 1405 bytes .../icons/TranslateIcon.png | Bin 0 -> 1293 bytes .../icons/sample.gif | Bin 0 -> 983 bytes .../plugin.xml | 54 +++++++++ .../tdl/openapi/generator/ui/Activator.java | 61 ++++++++++ .../ui/handlers/GeneratorHandler.java | 111 ++++++++++++++++++ .../ui/handlers/OpenAPIGeneratorLauncher.java | 79 +++++++++++++ 12 files changed, 371 insertions(+) create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/.classpath create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/.project create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/.settings/org.eclipse.jdt.core.prefs create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/META-INF/MANIFEST.MF create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/build.properties create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TransformIcon.png create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TranslateIcon.png create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/sample.gif create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/plugin.xml create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/Activator.java create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/GeneratorHandler.java create mode 100644 plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/OpenAPIGeneratorLauncher.java diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/.classpath b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.classpath new file mode 100644 index 00000000..e801ebfb --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/.project b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.project new file mode 100644 index 00000000..91de69b2 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.etsi.mts.tdl.openapi.generator.ui</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000..7adc0fb9 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,10 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/META-INF/MANIFEST.MF b/plugins/org.etsi.mts.tdl.openapi.generator.ui/META-INF/MANIFEST.MF new file mode 100644 index 00000000..38138a20 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/META-INF/MANIFEST.MF @@ -0,0 +1,15 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OpenAPI Generator Wrapper UI +Bundle-SymbolicName: org.etsi.mts.tdl.openapi.generator.ui;singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: org.etsi.mts.tdl.openapi.generator.ui.Activator +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.ui.editors;bundle-version="3.5.0", + org.eclipse.ui.ide;bundle-version="3.5.0", + org.eclipse.ui.workbench, + org.etsi.mts.tdl.openapi.generator.wrapper +Bundle-ActivationPolicy: lazy +Import-Package: org.eclipse.emf.common.util diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/build.properties b/plugins/org.etsi.mts.tdl.openapi.generator.ui/build.properties new file mode 100644 index 00000000..0d3d3a74 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TransformIcon.png b/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TransformIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..6b23bd6a60b0c2362a07da1a44e16f8c6a66926c GIT binary patch literal 1405 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|mZe5`ruq6Z zXaU(A3~Y=-49p-UK*+!-#lQ+?GcbfPO2gT4j2ciiOh7e;3_y}W6o}K>GZ|Q*>T7^B z2zUT7&?E>QkXezMlbcwQU!)LFl&@f<XQ*cilw)4Nh_G`36Wk1e1<VLGP#wcv4>55d z#aZAHS<Jw|Eeyhp4727)0L_?{84^(v;p=0SoS&<gn3A8As#lR)0Mf-^Q(*;U=BAb; zDpcg=<P}?0*eZclSOM7}VSOb9u#%E&Tcrr!00rm#qErPlJp(-hB|9z!1qGX;lr*a# z7dNPOAkS7Qqokz3N?*Ucyj-u`STDaQUEk2s(o)~RNZ-gv7pOwFxH7LKu|hYmSQ%mn z%p8~0;^d;tf|AVqJOz-siAnjTCALaRAdBDt;?C5HOoUB&#ZYenJ*W?o(KpmH(8s2& zBr^?%HjoTXZNM;sdke*~io^nlCU9Ut+-L)GffYDHBV96cQ}c>}{;@MOvjIB|LjvJB zB#jZcG$Ki$Yjn=f$u9~nNK8((GlbfOB!r|I<W;MPpw#00oKjF&+nE~~0D-<Ch_uni zkVe;v&>5PSSz>1d)q*CBt}7BDkIh14X>_grMVYC<6a#iE&}(1^B8wrZ2ga0@b5SZN zBZcJW=h$J(S2p_Ss?ZGZ1t$EI#F9jp#FA7yBLgEtT|)z11M?6=ODhu#D^qiA10yR? zNP&z&Q42N4Mjw=Vky0}xtAIs;dBu(ks1=s)?6}fX3ughd;weuT#}Es_x07u7njA!0 z(hIwFEt}gnd}fn7#4XW!Y+8_X{kx>ho{d+H3)ro>PM(O4xZ|Oeol|>q)8RAQg%ue7 z|NP0Vktwlc#uRB8m)ER%0a-e~YB}zm)=iq<uj8`Soh>-~j)&ap(k$*1t1A@F$;R=_ z)p%ucD(8h>u*B<d$utSe=(73i=R3p{WeV}QviTm~&&BZB;j7le<jVaDe^$8vVr^x6 z9(PS$cYSnMjHvaKx3%*#Dxw_}^pn^8KDT4f;nV#O4^8+R{V(~sFuR=B*Nb|mR)9(v MPgg&ebxsLQ0H~&$_5c6? literal 0 HcmV?d00001 diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TranslateIcon.png b/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/TranslateIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..555d9f2a5ad5bd079bb41a2d952dc7adfb8939e1 GIT binary patch literal 1293 zcmZ`(J#5oJ6n20@n>O@^r9wzOg-#XqC29I+IhND7&<IkZG)1YzP{+9xL;NHAqPPpC z6%tekQ2`4T5)mv+l~_74AXFp<7G^eBS!fp|5O8Owt%*`g=ev9F`|f-1+3(h~vzJ1_ zvq6SoLg^VPN9G<n+E0@Az}{b(OedC-nIyx!dDQt^ZX^2+b7sM2n9ehF1end|{RA_p z<_oxxxxy)i#>yq5h*(E637TPeha*c3VHr4DMYlO85q1$ASyM9%0~dmCCBlVF7NiUd zfl)TjM#4f60Ki+NGMAGsHt1xR2;aci<RGloYHV$UHLN8Vot&J6kr<4{h6!TWUe>Yf z4D0rJ?~wg-BxEa=YGT#U0X<hP8daPKhpEuP<Hd>9@}ZJ$H_{>rLh6B0HUeAGkfR<! zqn;yaCFLM1vuah`oJtBr6{H~@+k_WwDMxC1K>ROAM>ah%w}@VDJdK>oA={`_X$j_a z6$>%mO{m#?SP_qvGBnddwoPclXoKRnHRB71GQ#-2hTqssxN4~+Q<=skL>mHrTQh#4 zm4M&qBhb=wS=B+6f~1myx>-cWc-Yd>OiURS!<sW?1<}A<iqF)Hc4ZchlJPlw#FE0< z)#6R0VBgmw-^~5@r{pE*GxM+|nkRn(moZ9ed0CP%5@M0)7#E3i(FxF4M0nVQ@kKyA zDGSNiu=0jc5!@^^x&<So7vmn+k7$s2Nc+gwS6<V)R?@XXkTCae03nFu`G@3ESV>FC z{6w#^*uQ(H_d$1Iwb&<KXx}*|erns{#jd`4f!pBQxt<rr)phWBQ`|n@vvR6f2HVWn zJ@M_p{gtU7-5~T{S}oLv)aygf%(VC+x%*P=vO?FykId;hI|lx&&5vg{HUi(p(fYez m(_4XhzjOEU-s_)>9RcRc)6kPwgOBIv1(lwjmA0l9*Zu)8lZPe% literal 0 HcmV?d00001 diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/sample.gif b/plugins/org.etsi.mts.tdl.openapi.generator.ui/icons/sample.gif new file mode 100644 index 0000000000000000000000000000000000000000..34fb3c9d8cb7d489681b7f7aee4bdcd7eaf53610 GIT binary patch literal 983 zcmZ?wbhEHb6krfw_|CxKYUg-n!?izO{@<MU=lrfa-=6>9*?jxd%4aX0yzy`dymabz zw#(eg=y~&N&n)dZv2xzduG}5lraiApo3(c4*{Ylg5#|$JO_EEZ<^|a2`Z*=9ns7DV zy=TR&gYw*7f%auV?ip3tvjRPmcdoho{K?x$_vR?C#t5&<;~V}S*>OMCr>h}%%bLZ9 zmo3`hYE<KGQ|@6^6ztNF7&tM)w`%LUlM$ZXF+LNb{aPCe*E?B9-oF0Q%eE%Wqbtg% z@9CqD9#(CE&J!||x{C9<qx`1E1<#EMm>wTICo-TTCZwgTsC&VjZRgJ1eE#fBa^%9R zmmfWS@;bnyJ27HWY}kxYzv(Hl>yu;FCPlAEh+34Muq-8Rb6C)<<b<V}>8qA3{r2e5 z`$vyngh#H=FWlqqvnapfc5%(!sQ4v?r7J61-&eJNEN^;KTK}T7{#i-g<Ko(f<;_oL zEqXI)#s$xy8I>Jh%G*9vcYdwv_*~xdw!Gz4Va?T!sXyyF@8?w<>X`X=#<IVLwl(2N zbDlnX{r~@ehEXtZA)xq^g^_`wfk6l41W=w};Ml^z$SLEoVZp&>j%uHV4GRvj@+tE@ zQ%F!a)GKcn<q;6D!JEN>^~8abN>4la1UNXVL;{ZWi)lEwyeatDu%Lr6;aASiLrXXW z<qR}<jx?wH%UBk_m}3}x+;6r`C0o`5p=aFFG(%QJbS6DH5nx_(p~G`=8t-hw@-KTT zjSG%3ippkO@kn%b<6zL?_~%%t)W#~L>Qm#<km7kzO+(7yLxUo7pMn=(Rpi5j!`up< Pa}@5JsVsJ2V6X-N$YLV6 literal 0 HcmV?d00001 diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/plugin.xml b/plugins/org.etsi.mts.tdl.openapi.generator.ui/plugin.xml new file mode 100644 index 00000000..701e6dee --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/plugin.xml @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + + <extension + point="org.eclipse.ui.commands"> + <category + name="TDL" + id="org.etsi.mts.tdl.openapi.generator.ui.commands.category"> + </category> + <command + name="OpenAPI Generate target implementation" + categoryId="org.etsi.mts.tdl.openapi.generator.ui.commands.category" + id="org.etsi.mts.tdl.openapi.generator.ui.commands.generateCommand"> + </command> + </extension> + <extension + point="org.eclipse.ui.handlers"> + <handler + commandId="org.etsi.mts.tdl.openapi.generator.ui.commands.generateCommand" + class="org.etsi.mts.tdl.openapi.generator.ui.handlers.GeneratorHandler"> + </handler> + </extension> + <extension + point="org.eclipse.ui.menus"> + <menuContribution + locationURI="menu:org.eclipse.ui.main.menu?after=additions"> + <menu + label="TDL" + mnemonic="X" + id="org.etsi.mts.tdl.tools.menus.TDLMenu"> + <command + commandId="org.etsi.mts.tdl.openapi.generator.ui.commands.generateCommand" + icon="icons/TransformIcon.png" + mnemonic="X" + id="org.etsi.mts.tdl.openapi.generator.ui.menus.generateCommand"> + </command> + </menu> + </menuContribution> + <menuContribution + locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions"> + <toolbar + id="org.etsi.mts.tdl.openapi.generator.ui.toolbars.generate"> + <command + commandId="org.etsi.mts.tdl.openapi.generator.ui.commands.generateCommand" + icon="icons/TransformIcon.png" + name="OpenAPI Generate target implementation" + id="org.etsi.mts.tdl.openapi.generator.ui.toolbars.generateCommand"> + </command> + </toolbar> + </menuContribution> + </extension> + +</plugin> diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/Activator.java b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/Activator.java new file mode 100644 index 00000000..0905c406 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/Activator.java @@ -0,0 +1,61 @@ +package org.etsi.mts.tdl.openapi.generator.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.etsi.mts.tdl.openapi.generator.ui"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/GeneratorHandler.java b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/GeneratorHandler.java new file mode 100644 index 00000000..234b3a65 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/GeneratorHandler.java @@ -0,0 +1,111 @@ +package org.etsi.mts.tdl.openapi.generator.ui.handlers; + +import java.util.Arrays; +import java.util.LinkedHashMap; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.part.FileEditorInput; + +/** + * Our sample handler extends AbstractHandler, an IHandler base class. + * @see org.eclipse.core.commands.IHandler + * @see org.eclipse.core.commands.AbstractHandler + */ +public class GeneratorHandler extends AbstractHandler { + + LinkedHashMap<String, String> targetFormats = new LinkedHashMap<>(); + + public static String translationTarget = "java"; + + private IWorkbenchWindow window; + + /** + * The constructor. + */ + public GeneratorHandler() { + init(); + } + + private void init() { + //TODO: update rt.ui as well + //TODO: do not reload after first init + if (!targetFormats.isEmpty()) { + return; + } + targetFormats.clear(); + + for (String gen : OpenAPIGeneratorLauncher.listGenerators()) { + targetFormats.put(gen, gen); + } + } + + /** + * the command has been executed, so extract extract the needed information + * from the application context. + */ + public Object execute(ExecutionEvent event) throws ExecutionException { + init(); + ISelection selection = HandlerUtil.getCurrentSelection(event); + IEditorInput input = HandlerUtil.getActiveEditorInput(event); + IFile file = null; + if (input != null && input instanceof FileEditorInput && ((FileEditorInput) input).getFile().getName().endsWith("yaml")) { + file = ((FileEditorInput) input).getFile(); + } else if (selection !=null && selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + Object firstElement = structuredSelection.getFirstElement(); + if (firstElement instanceof IFile) { + file = (IFile) firstElement; + } + } + + if (file !=null && file.getName().endsWith("yaml")) { + + ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getDefault().getActiveShell(), new LabelProvider()); + dialog.setTitle("OpenAPI Generator Target Selection"); + dialog.setMessage("Generating assets from "+file.getName() + +"\n\nSelect the target format"); + dialog.setElements(targetFormats.keySet().toArray()); + + dialog.setInitialElementSelections(Arrays.asList(new String[] {GeneratorHandler.translationTarget})); + //TODO: add option to skip validation + //TODO: add step to validate + + // user pressed cancel + if (dialog.open() != Window.OK) { + return false; + } else { + //TODO: enable validation once it does not exit +// OpenAPIGeneratorLauncher.validate(file.getLocation().toFile().getAbsolutePath()); +// OpenAPIGeneratorLauncher.parse(file.getLocation().toFile().getAbsolutePath()); + + Object[] result = dialog.getResult(); + String selected = (String)result[0]; + translationTarget = selected; + OpenAPIGeneratorLauncher.launch(file.getLocation().toFile().getAbsolutePath(), selected); + } + } + return null; + } + + public void init(IWorkbenchWindow window) { + this.window = window; + } + + @Override + public boolean isEnabled() { + return true; + } + +} diff --git a/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/OpenAPIGeneratorLauncher.java b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/OpenAPIGeneratorLauncher.java new file mode 100644 index 00000000..1c13cf35 --- /dev/null +++ b/plugins/org.etsi.mts.tdl.openapi.generator.ui/src/org/etsi/mts/tdl/openapi/generator/ui/handlers/OpenAPIGeneratorLauncher.java @@ -0,0 +1,79 @@ +package org.etsi.mts.tdl.openapi.generator.ui.handlers; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.openapitools.codegen.CodegenConfig; +import org.openapitools.codegen.CodegenConfigLoader; +import org.openapitools.codegen.OpenAPIGenerator; +import org.openapitools.codegen.meta.GeneratorMetadata; +import org.openapitools.codegen.utils.ModelUtils; + +import io.swagger.parser.OpenAPIParser; +import io.swagger.v3.oas.models.Components; +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.media.ArraySchema; +import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.parser.core.models.ParseOptions; + +public class OpenAPIGeneratorLauncher { + + public static void main(String[] args) { +// launch(input, target); + listGenerators(); +// parse(input); + } + + public static List<String> listGenerators() { + List<CodegenConfig> generators = new ArrayList<>(); + List<String> generatorNames = new ArrayList<>(); + for (CodegenConfig codegenConfig : CodegenConfigLoader.getAll()) { + GeneratorMetadata meta = codegenConfig.getGeneratorMetadata(); + if (meta != null) { + generators.add(codegenConfig); + generatorNames.add(codegenConfig.getName()); + } + } + return generatorNames; + } + + public static void launch(String input, String target) { + launch(input, target, true); + } + + public static void launch(String input, String target, boolean skipValidation) { + String inputFolder = new File(input).getParentFile().getAbsolutePath(); + String output = inputFolder+"/generated/"+target+"/"; + new File(output).mkdirs(); + String skip = ""; + if (skipValidation) { + skip = "--skip-validate-spec"; + } + OpenAPIGenerator.main(new String[] {"generate", "-g", target, "-i", input, "-o", output, skip}); + } + + public static void validate(String input) { + //TODO: adapt from source so that it does not exit or run in a separate process? + OpenAPIGenerator.main(new String[] {"validate", "-i", input}); + } + + public static void parse(String input) { + System.out.println("Parsing "+input); + OpenAPI openAPI = new OpenAPIParser().readLocation(input, null, new ParseOptions()).getOpenAPI(); + Components components = openAPI.getComponents(); + Map<String, Schema> schemas = components.getSchemas(); + ArraySchema object = (ArraySchema) schemas.get("Library").getProperties().get("books"); + System.out.println(object.getItems().get$ref()); +// System.out.println(schemas.get("Library").getName()); + System.out.println("MU:"+ModelUtils.getReferencedSchema(openAPI, object.getItems())); + schemas.forEach((k,v) -> System.out.println(k)); + // Invoke helper function to get the original swagger version. + // See https://github.com/swagger-api/swagger-parser/pull/1374 + // Also see https://github.com/swagger-api/swagger-parser/issues/1369. + ModelUtils.getOpenApiVersion(openAPI, input, null); + + } + +} -- GitLab