forked from loafle/openapi-generator-original
1 line
9.1 KiB
JavaScript
1 line
9.1 KiB
JavaScript
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[7748],{3905:function(e,n,t){t.d(n,{Zo:function(){return u},kt:function(){return m}});var a=t(7294);function r(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function o(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);n&&(a=a.filter((function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable}))),t.push.apply(t,a)}return t}function l(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?o(Object(t),!0).forEach((function(n){r(e,n,t[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):o(Object(t)).forEach((function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}))}return e}function i(e,n){if(null==e)return{};var t,a,r=function(e,n){if(null==e)return{};var t,a,r={},o=Object.keys(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)t=o[a],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var p=a.createContext({}),s=function(e){var n=a.useContext(p),t=n;return e&&(t="function"==typeof e?e(n):l(l({},n),e)),t},u=function(e){var n=s(e.components);return a.createElement(p.Provider,{value:n},e.children)},c="mdxType",d={inlineCode:"code",wrapper:function(e){var n=e.children;return a.createElement(a.Fragment,{},n)}},g=a.forwardRef((function(e,n){var t=e.components,r=e.mdxType,o=e.originalType,p=e.parentName,u=i(e,["components","mdxType","originalType","parentName"]),c=s(t),g=r,m=c["".concat(p,".").concat(g)]||c[g]||d[g]||o;return t?a.createElement(m,l(l({ref:n},u),{},{components:t})):a.createElement(m,l({ref:n},u))}));function m(e,n){var t=arguments,r=n&&n.mdxType;if("string"==typeof e||r){var o=t.length,l=new Array(o);l[0]=g;var i={};for(var p in n)hasOwnProperty.call(n,p)&&(i[p]=n[p]);i.originalType=e,i[c]="string"==typeof e?e:r,l[1]=i;for(var s=2;s<o;s++)l[s]=t[s];return a.createElement.apply(null,l)}return a.createElement.apply(null,t)}g.displayName="MDXCreateElement"},8101:function(e,n,t){t.r(n),t.d(n,{assets:function(){return u},contentTitle:function(){return p},default:function(){return g},frontMatter:function(){return i},metadata:function(){return s},toc:function(){return c}});var a=t(7462),r=t(3366),o=(t(7294),t(3905)),l=["components"],i={id:"plugins",title:"Plugins"},p=void 0,s={unversionedId:"plugins",id:"plugins",title:"Plugins",description:"Maven",source:"@site/../docs/plugins.md",sourceDirName:".",slug:"/plugins",permalink:"/docs/plugins",draft:!1,editUrl:"https://github.com/OpenAPITools/openapi-generator/edit/master/website/../docs/plugins.md",tags:[],version:"current",lastUpdatedBy:"phoenix",lastUpdatedAt:1655367672,formattedLastUpdatedAt:"Jun 16, 2022",frontMatter:{id:"plugins",title:"Plugins"},sidebar:"docs",previous:{title:"CLI Installation",permalink:"/docs/installation"},next:{title:"Online",permalink:"/docs/online"}},u={},c=[{value:"Maven",id:"maven",level:2},{value:"Example",id:"example",level:3},{value:"Dependencies",id:"dependencies",level:3},{value:"Gradle",id:"gradle",level:2},{value:"Example",id:"example-1",level:3}],d={toc:c};function g(e){var n=e.components,t=(0,r.Z)(e,l);return(0,o.kt)("wrapper",(0,a.Z)({},d,t,{components:n,mdxType:"MDXLayout"}),(0,o.kt)("h2",{id:"maven"},"Maven"),(0,o.kt)("p",null,"A Maven plugin to support the OpenAPI generator project"),(0,o.kt)("h3",{id:"example"},"Example"),(0,o.kt)("p",null,"Add to your ",(0,o.kt)("inlineCode",{parentName:"p"},"build->plugins")," section (default phase is ",(0,o.kt)("inlineCode",{parentName:"p"},"generate-sources")," phase)"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-xml"},"<plugin>\n <groupId>org.openapitools</groupId>\n <artifactId>openapi-generator-maven-plugin</artifactId>\n \x3c!-- RELEASE_VERSION --\x3e\n <version>6.0.0</version>\n \x3c!-- /RELEASE_VERSION --\x3e\n <executions>\n <execution>\n <goals>\n <goal>generate</goal>\n </goals>\n <configuration>\n <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>\n <generatorName>java</generatorName>\n <configOptions>\n <sourceFolder>src/gen/java/main</sourceFolder>\n </configOptions>\n </configuration>\n </execution>\n </executions>\n</plugin>\n")),(0,o.kt)("p",null,"Followed by:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-bash"},"mvn clean compile\n")),(0,o.kt)("p",null,"For full details of all options, see the ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin"},"plugin README"),"."),(0,o.kt)("h3",{id:"dependencies"},"Dependencies"),(0,o.kt)("p",null,"The generated models use commonly used Swagger v2 annotations like ",(0,o.kt)("inlineCode",{parentName:"p"},"@ApiModelProperty"),". A user may add Swagger v3 annotations:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-xml"},"<dependency>\n <groupId>io.swagger.core.v3</groupId>\n <artifactId>swagger-annotations</artifactId>\n</dependency>\n")),(0,o.kt)("p",null,"But this will not work. This dependency is not binary compatible with Swagger v2 annotations. The resulting code will fail to compile."),(0,o.kt)("p",null,"As alternative instead use the following dependency:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-xml"},"<dependency>\n <groupId>io.swagger.parser.v3</groupId>\n <artifactId>swagger-parser</artifactId>\n</dependency>\n")),(0,o.kt)("h2",{id:"gradle"},"Gradle"),(0,o.kt)("p",null,"This gradle plugin offers a declarative DSL via extensions (these are Gradle project extensions). These map almost fully 1:1 with the options you\u2019d pass to the CLI or Maven plugin. The plugin maps the extensions to a task of the same name to provide a clean API. If you\u2019re interested in the extension/task mapping concept from a high-level, you can check out ",(0,o.kt)("a",{parentName:"p",href:"https://docs.gradle.org/current/userguide/custom_plugins.html#sec:mapping_extension_properties_to_task_properties"},"Gradle\u2019s docs"),"."),(0,o.kt)("p",null,"To include in your project, add the following to ",(0,o.kt)("inlineCode",{parentName:"p"},"build.gradle"),":"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-groovy"},'buildscript {\n repositories {\n mavenLocal()\n maven { url "https://repo1.maven.org/maven2" }\n }\n dependencies {\n classpath "org.openapitools:openapi-generator-gradle-plugin:5.0.0"\n }\n}\n\napply plugin: \'org.openapi.generator\'\n')),(0,o.kt)("p",null,"This gives access to the following tasks:"),(0,o.kt)("table",null,(0,o.kt)("thead",{parentName:"table"},(0,o.kt)("tr",{parentName:"thead"},(0,o.kt)("th",{parentName:"tr",align:null},"Task"),(0,o.kt)("th",{parentName:"tr",align:null},"Description"))),(0,o.kt)("tbody",{parentName:"table"},(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"openApiGenerate"),(0,o.kt)("td",{parentName:"tr",align:null},"Generate code via Open API Tools Generator for Open API 2.0 or 3.x specification documents.")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"openApiGenerators"),(0,o.kt)("td",{parentName:"tr",align:null},"Lists generators available via Open API Generators.")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"openApiMeta"),(0,o.kt)("td",{parentName:"tr",align:null},"Generates a new generator to be consumed via Open API Generator.")),(0,o.kt)("tr",{parentName:"tbody"},(0,o.kt)("td",{parentName:"tr",align:null},"openApiValidate"),(0,o.kt)("td",{parentName:"tr",align:null},"Validates an Open API 2.0 or 3.x specification document.")))),(0,o.kt)("blockquote",null,(0,o.kt)("p",{parentName:"blockquote"},"The plugin implements the above tasks as project extensions of the same name. If you\u2019d like to declare these tasks as dependencies to other tasks (using ",(0,o.kt)("inlineCode",{parentName:"p"},"dependsOn"),"), you\u2019ll need a task reference. e.g.:"),(0,o.kt)("pre",{parentName:"blockquote"},(0,o.kt)("code",{parentName:"pre",className:"language-groovy"},"compileJava.dependsOn tasks.openApiGenerate\n"))),(0,o.kt)("p",null,"For full details of all options, see the ",(0,o.kt)("a",{parentName:"p",href:"https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-gradle-plugin"},"plugin README"),"."),(0,o.kt)("h3",{id:"example-1"},"Example"),(0,o.kt)("p",null,"An example task for generating a kotlin client:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-groovy"},'openApiGenerate {\n generatorName = "kotlin"\n inputSpec = "$rootDir/specs/petstore-v3.0.yaml".toString()\n outputDir = "$buildDir/generated".toString()\n apiPackage = "org.openapi.example.api"\n invokerPackage = "org.openapi.example.invoker"\n modelPackage = "org.openapi.example.model"\n configOptions = [\n dateLibrary: "java8"\n ]\n}\n')))}g.isMDXComponent=!0}}]); |