"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=0||(r[t]=e[t]);return r}(e,n);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a=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;splugins")," 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"},"\n org.openapitools\n openapi-generator-maven-plugin\n \x3c!-- RELEASE_VERSION --\x3e\n 6.0.0\n \x3c!-- /RELEASE_VERSION --\x3e\n \n \n \n generate\n \n \n ${project.basedir}/src/main/resources/api.yaml\n java\n \n src/gen/java/main\n \n \n \n \n\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"},"\n io.swagger.core.v3\n swagger-annotations\n\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"},"\n io.swagger.parser.v3\n swagger-parser\n\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}}]);