forked from loafle/openapi-generator-original
1 line
9.7 KiB
JavaScript
1 line
9.7 KiB
JavaScript
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[9760],{3905:function(e,t,n){n.d(t,{Zo:function(){return c},kt:function(){return g}});var o=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function p(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function l(e,t){if(null==e)return{};var n,o,a=function(e,t){if(null==e)return{};var n,o,a={},r=Object.keys(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(o=0;o<r.length;o++)n=r[o],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var i=o.createContext({}),s=function(e){var t=o.useContext(i),n=t;return e&&(n="function"==typeof e?e(t):p(p({},t),e)),n},c=function(e){var t=s(e.components);return o.createElement(i.Provider,{value:t},e.children)},u="mdxType",d={inlineCode:"code",wrapper:function(e){var t=e.children;return o.createElement(o.Fragment,{},t)}},m=o.forwardRef((function(e,t){var n=e.components,a=e.mdxType,r=e.originalType,i=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),u=s(n),m=a,g=u["".concat(i,".").concat(m)]||u[m]||d[m]||r;return n?o.createElement(g,p(p({ref:t},c),{},{components:n})):o.createElement(g,p({ref:t},c))}));function g(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var r=n.length,p=new Array(r);p[0]=m;var l={};for(var i in t)hasOwnProperty.call(t,i)&&(l[i]=t[i]);l.originalType=e,l[u]="string"==typeof e?e:a,p[1]=l;for(var s=2;s<r;s++)p[s]=n[s];return o.createElement.apply(null,p)}return o.createElement.apply(null,n)}m.displayName="MDXCreateElement"},1845:function(e,t,n){n.r(t),n.d(t,{assets:function(){return c},contentTitle:function(){return i},default:function(){return m},frontMatter:function(){return l},metadata:function(){return s},toc:function(){return u}});var o=n(7462),a=n(3366),r=(n(7294),n(3905)),p=["components"],l={id:"online",title:"Online"},i=void 0,s={unversionedId:"online",id:"online",title:"Online",description:"Hosted",source:"@site/../docs/online.md",sourceDirName:".",slug:"/online",permalink:"/docs/online",draft:!1,editUrl:"https://github.com/OpenAPITools/openapi-generator/edit/master/website/../docs/online.md",tags:[],version:"current",lastUpdatedBy:"Nathan Baulch",lastUpdatedAt:1667827824,formattedLastUpdatedAt:"Nov 7, 2022",frontMatter:{id:"online",title:"Online"},sidebar:"docs",previous:{title:"Plugins",permalink:"/docs/plugins"},next:{title:"Usage",permalink:"/docs/usage"}},c={},u=[{value:"Hosted",id:"hosted",level:2},{value:"Docker Image",id:"docker-image",level:2},{value:"Local/Self-hosting",id:"localself-hosting",level:2}],d={toc:u};function m(e){var t=e.components,n=(0,a.Z)(e,p);return(0,r.kt)("wrapper",(0,o.Z)({},d,n,{components:t,mdxType:"MDXLayout"}),(0,r.kt)("h2",{id:"hosted"},"Hosted"),(0,r.kt)("p",null,"We offer online services, publicly and free of charge:"),(0,r.kt)("ul",null,(0,r.kt)("li",{parentName:"ul"},"latest stable version: ",(0,r.kt)("a",{parentName:"li",href:"http://api.openapi-generator.tech"},"http://api.openapi-generator.tech")),(0,r.kt)("li",{parentName:"ul"},"latest master: ",(0,r.kt)("a",{parentName:"li",href:"http://api-latest-master.openapi-generator.tech"},"http://api-latest-master.openapi-generator.tech")," (updated with latest master every hour)")),(0,r.kt)("blockquote",null,(0,r.kt)("p",{parentName:"blockquote"},(0,r.kt)("strong",{parentName:"p"},"Hosting Sponsor"),(0,r.kt)("br",{parentName:"p"}),"\n",(0,r.kt)("a",{parentName:"p",href:"https://www.linode.com/"},(0,r.kt)("img",{parentName:"a",src:"https://www.linode.com/media/images/logos/standard/light/linode-logo_standard_light_small.png",alt:"Linode Logo"})))),(0,r.kt)("p",null,"These services are beta and do not have any guarantee on service level"),(0,r.kt)("h2",{id:"docker-image"},"Docker Image"),(0,r.kt)("p",null,"The openapi-generator-online Docker image can act as a self-hosted web application and API for generating code. This container can be incorporated into a CI pipeline, and requires at least two HTTP requests and some docker orchestration to access generated code."),(0,r.kt)("p",null,"Example usage:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},'# Start container at port 8888 and save the container id\nCID=$(docker run -d -p 8888:8080 openapitools/openapi-generator-online)\n\n# allow for startup\nsleep 10\n\n# Get the IP of the running container (optional)\nGEN_IP=$(docker inspect --format \'{{.NetworkSettings.IPAddress}}\' ${CID})\n\n# Execute an HTTP request to generate a Ruby client\ncurl -X POST --header \'Content-Type: application/json\' \\\n --header \'Accept: application/json\' \\\n -d \'{"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"}\' \\\n \'http://localhost:8888/api/gen/clients/ruby\'\n\n# Example output:\n# {"code":"c2d483.3.4672-40e9-91df-b9ffd18d22b8","link":"http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8"}\n\n# Download the generated zip file (using "code" provided from your output) \nwget http://localhost:8888/api/gen/download/c2d483.3.4672-40e9-91df-b9ffd18d22b8\n\n# Unzip the file\nunzip c2d483.3.4672-40e9-91df-b9ffd18d22b8\n\n# Shutdown the openapi generator image\ndocker stop ${CID} && docker rm ${CID}\n')),(0,r.kt)("h2",{id:"localself-hosting"},"Local/Self-hosting"),(0,r.kt)("p",null,"If you prefer to run the service locally, here are the steps:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},"mvn clean install\ncd modules/openapi-generator-online\nmvn spring-boot:run\n")),(0,r.kt)("blockquote",null,(0,r.kt)("p",{parentName:"blockquote"},"The online openapi-generator can be run via ",(0,r.kt)("a",{parentName:"p",href:"#docker-image"},"Docker")," as well.")),(0,r.kt)("p",null,"For example, to generate Ruby API client, simply send the following HTTP request using curl:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},'curl -X POST -H "content-type:application/json" -d \'{"openAPIUrl":"https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"}\' \\\n http://localhost:8080/api/gen/clients/ruby\n')),(0,r.kt)("p",null,"Then you will receive a JSON response with the URL to download the zipped code."),(0,r.kt)("p",null,"To customize the SDK, you can ",(0,r.kt)("inlineCode",{parentName:"p"},"POST")," to ",(0,r.kt)("inlineCode",{parentName:"p"},"http://localhost:8080/gen/clients/{generator}")," with the following HTTP body:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "options": {},\n "openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"\n}\n')),(0,r.kt)("p",null,"Here, the ",(0,r.kt)("inlineCode",{parentName:"p"},"options")," for a language can be obtained by submitting a ",(0,r.kt)("inlineCode",{parentName:"p"},"GET")," request to ",(0,r.kt)("inlineCode",{parentName:"p"},"http://locahost:8080/api/gen/clients/{generator}"),":"),(0,r.kt)("p",null,"For example, ",(0,r.kt)("inlineCode",{parentName:"p"},"curl http://localhost:8080/api/gen/clients/python")," returns"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},' "packageName":{\n "opt":"packageName",\n "description":"python package name (convention: snake_case).",\n "type":"string",\n "default":"openapi_client"\n },\n "packageVersion":{\n "opt":"packageVersion",\n "description":"python package version.",\n "type":"string",\n "default":"1.0.0"\n },\n "sortParamsByRequiredFlag":{\n "opt":"sortParamsByRequiredFlag",\n "description":"Sort method arguments to place required parameters before optional parameters.",\n "type":"boolean",\n "default":"true"\n }\n\n{}\n')),(0,r.kt)("p",null,"To set package name to ",(0,r.kt)("inlineCode",{parentName:"p"},"pet_store"),", the HTTP body of the request is as follows:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "options": {\n "packageName": "pet_store"\n },\n "openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"\n}\n')),(0,r.kt)("p",null,"and here is the curl command:"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-bash"},'curl -H "Content-type: application/json" \\\n -X POST \\\n -d \'{"options": {"packageName": "pet_store"},"openAPIUrl": "https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml"}\' \\\n http://localhost:8080/api/gen/clients/python\n')),(0,r.kt)("p",null,"Instead of using ",(0,r.kt)("inlineCode",{parentName:"p"},"openAPIUrl")," with a URL to the OpenAPI spec, one can include the spec in the JSON payload with ",(0,r.kt)("inlineCode",{parentName:"p"},"spec"),":"),(0,r.kt)("pre",null,(0,r.kt)("code",{parentName:"pre",className:"language-json"},'{\n "options": {},\n "spec": {\n "swagger": "2.0",\n "info": {\n "version": "1.0.0",\n "title": "Test API"\n },\n ...\n }\n}\n')))}m.isMDXComponent=!0}}]); |