(window.webpackJsonp=window.webpackJsonp||[]).push([[87],{215:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return i})),n.d(t,"metadata",(function(){return p})),n.d(t,"rightToc",(function(){return l})),n.d(t,"default",(function(){return c}));var a=n(1),o=n(9),r=(n(0),n(307)),i={id:"usage",title:"Usage"},p={id:"usage",title:"Usage",description:"Options for OpenAPI Generator are the same whether you're using the CLI, Maven/Gradle Plugins, or Online generation options.",source:"@site/../docs/usage.md",permalink:"/docs/usage",editUrl:"https://github.com/OpenAPITools/openapi-generator/edit/master/website/../docs/usage.md",lastUpdatedBy:"William Cheng",lastUpdatedAt:1614097903,sidebar:"docs",previous:{title:"Online",permalink:"/docs/online"},next:{title:"Global Properties",permalink:"/docs/globals"}},l=[{value:"help",id:"help",children:[]},{value:"version",id:"version",children:[]},{value:"list",id:"list",children:[]},{value:"config-help",id:"config-help",children:[]},{value:"meta",id:"meta",children:[]},{value:"validate",id:"validate",children:[]},{value:"completion",id:"completion",children:[]},{value:"generate",id:"generate",children:[{value:"Examples",id:"examples",children:[]},{value:"Target External Models",id:"target-external-models",children:[]}]},{value:"batch",id:"batch",children:[]},{value:"author",id:"author",children:[{value:"template",id:"template",children:[]}]}],s={rightToc:l};function c(e){var t=e.components,n=Object(o.a)(e,["components"]);return Object(r.b)("wrapper",Object(a.a)({},s,n,{components:t,mdxType:"MDXLayout"}),Object(r.b)("p",null,"Options for OpenAPI Generator are the same whether you're using the CLI, Maven/Gradle Plugins, or Online generation options.\nThis page demonstrates navigating the options via CLI. Commands are presented here in a logical progression as a tutorial, but you're welcome to skip directly to the ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"#generate"}),"generate")," command."),Object(r.b)("h2",{id:"help"},"help"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"help")," option lists all commands available to the CLI."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help\nusage: openapi-generator-cli []\n\nThe most commonly used openapi-generator-cli commands are:\n author Utilities for authoring generators or customizing templates.\n config-help Config help for chosen lang\n generate Generate code with the specified generator.\n help Display help information about openapi-generator\n list Lists the available generators\n meta MetaGenerator. Generator for creating a new template set and configuration for Codegen. The output will be based on the language you specify, and includes default templates to include.\n validate Validate specification\n version Show version information used in tooling\n\nSee 'openapi-generator-cli help ' for more information on a specific\ncommand.\n")),Object(r.b)("h2",{id:"version"},"version"),Object(r.b)("p",null,"The version command provides version information, returning either the semver version by default or the git sha when passed ",Object(r.b)("inlineCode",{parentName:"p"},"--sha"),"."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"NAME\n openapi-generator-cli version - Show version information\n\nSYNOPSIS\n openapi-generator-cli version [--sha]\n\nOPTIONS\n --sha\n Git commit SHA version\n\n")),Object(r.b)("h2",{id:"list"},"list"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"list")," command outputs a formatted list of every available generator. Pass the ",Object(r.b)("inlineCode",{parentName:"p"},"-s/--short")," option if you would like a CSV output for easy parsing."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help list\nNAME\n openapi-generator-cli list - Lists the available generators\n\nSYNOPSIS\n openapi-generator-cli list [(-i | --include )]\n [(-s | --short)]\n\nOPTIONS\n -i , --include \n comma-separated list of stability indexes to include (value:\n all,beta,stable,experimental,deprecated). Excludes deprecated by\n default.\n\n -s, --short\n shortened output (suitable for scripting)\n\n")),Object(r.b)("p",null,"Example:"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator list -s | tr ',' '\\n'\n")),Object(r.b)("p",null,"For the full list of generators, refer to the ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"/docs/generators"}),"Generators List"),"."),Object(r.b)("h2",{id:"config-help"},"config-help"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"config-help")," option provides details about "),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help config-help\nNAME\n openapi-generator-cli config-help - Config help for chosen lang\n\nSYNOPSIS\n openapi-generator-cli config-help\n [(-f | --format )]\n [(-g | --generator-name )]\n [--markdown-header] [--named-header]\n [(-o | --output )]\n\nOPTIONS\n -f , --format \n Write output files in the desired format. Options are 'text',\n 'markdown' or 'yamlsample'. Default is 'text'.\n\n -g , --generator-name \n generator to get config help for\n\n --markdown-header\n When format=markdown, include this option to write out markdown\n headers (e.g. for docusaurus).\n\n --named-header\n Header includes the generator name, for clarity in output\n\n -o , --output \n Optionally write help to this location, otherwise default is\n standard output\n\n")),Object(r.b)("p",null,"The option of note is ",Object(r.b)("inlineCode",{parentName:"p"},"-g/--generator-name")," (other options are exposed for tooling)."),Object(r.b)("p",null,"You may pass any generator name (see ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"#list"}),"list")," command) to ",Object(r.b)("inlineCode",{parentName:"p"},"-g"),", and options specific to that generator will be displayed. Some generators have ",Object(r.b)("em",{parentName:"p"},"many")," options, while others may have only a few."),Object(r.b)("p",null,"Example:"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator config-help -g go\n")),Object(r.b)("p",null,"Outputs:"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"CONFIG OPTIONS\n packageName\n Go package name (convention: lowercase). (Default: openapi)\n\n hideGenerationTimestamp\n Hides the generation timestamp when files are generated. (Default: true)\n\n packageVersion\n Go package version. (Default: 1.0.0)\n\n withGoCodegenComment\n whether to include Go codegen comment to disable Go Lint and collapse by default in GitHub PRs and diffs (Default: false)\n\n withXml\n whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML) (Default: false)\n\n prependFormOrBodyParameters\n Add form or body parameters to the beginning of the parameter list. (Default: false)\n")),Object(r.b)("p",null,"To pass these go client generator-specific options to the ",Object(r.b)("inlineCode",{parentName:"p"},"generate")," command for a go client, use the ",Object(r.b)("inlineCode",{parentName:"p"},"--additional-properties")," option. See the ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"#generate"}),"generate")," command section for an example."),Object(r.b)("h2",{id:"meta"},"meta"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"meta")," command creates a new Java class and template files, used for creating your own custom templates."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help meta\nNAME\n openapi-generator-cli meta - MetaGenerator. Generator for creating a new\n template set and configuration for Codegen. The output will be based on\n the language you specify, and includes default templates to include.\n\nSYNOPSIS\n openapi-generator-cli meta [(-n | --name )]\n [(-o | --output )]\n [(-p | --package )] [(-t | --type )]\n\nOPTIONS\n -n , --name \n the human-readable name of the generator\n\n -o , --output \n where to write the generated files (current dir by default)\n\n -p , --package \n the package to put the main class into (defaults to\n org.openapitools.codegen)\n\n -t , --type \n the type of generator that is created\n")),Object(r.b)("p",null,"For an in-depth example of using the ",Object(r.b)("inlineCode",{parentName:"p"},"meta")," command, see ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"/docs/customization"}),"Customization"),"."),Object(r.b)("h2",{id:"validate"},"validate"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"validate")," command allows you to validate an input specification, optionally providing recommendations for error fixes or other improvements (if available)."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help validate\nNAME\n openapi-generator-cli validate - Validate specification\n\nSYNOPSIS\n openapi-generator-cli validate\n (-i | --input-spec ) [--recommend]\n\nOPTIONS\n -i , --input-spec \n location of the OpenAPI spec, as URL or file (required)\n\n --recommend\n\n")),Object(r.b)("p",null,"Valid Spec Example (using ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator-gradle-plugin/samples/local-spec/petstore-v3.0.yaml"}),"petstore-v3.0.yaml"),")"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator validate -i petstore-v3.0.yaml\n")),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"Validating spec (petstore-v3.0.yaml)\nNo validation issues detected.\n")),Object(r.b)("p",null,"Invalid Spec Example (using ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator-gradle-plugin/samples/local-spec/petstore-v3.0-invalid.yaml"}),"petstore-v3.0-invalid.yaml"),"):"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator validate -i petstore-v3.0-invalid.yaml\n")),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"Validating spec (petstore-v3.0-invalid.yaml)\nErrors:\n -attribute info is missing\n\n[error] Spec has 1 errors.\n")),Object(r.b)("h2",{id:"completion"},"completion"),Object(r.b)("p",null,"Although not documented in the ",Object(r.b)("inlineCode",{parentName:"p"},"help")," output, the CLI offers a ",Object(r.b)("inlineCode",{parentName:"p"},"completion")," command, which can be used for auto-completion."),Object(r.b)("p",null,"This command takes one or more parameters representing the args list you would otherwise pass to ",Object(r.b)("inlineCode",{parentName:"p"},"openapi-generator"),". For example:"),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator completion config-help\n-o\n--output\n--named-header\n-g\n--generator-name\n-f\n--format\n--markdown-header\n")),Object(r.b)("p",null,"An example bash completion script can be found in the repo at ",Object(r.b)("a",Object(a.a)({parentName:"p"},{href:"https://github.com/OpenAPITools/openapi-generator/blob/master/scripts/openapi-generator-cli-completion.bash"}),"scripts/openapi-generator-cli-completion.bash"),"."),Object(r.b)("h2",{id:"generate"},"generate"),Object(r.b)("p",null,"The ",Object(r.b)("inlineCode",{parentName:"p"},"generate")," command is the workhorse of the generator toolset. As such, it has ",Object(r.b)("em",{parentName:"p"},"many")," more options available than the previous commands. The abbreviated options are below, but you may expand the full descriptions."),Object(r.b)("pre",null,Object(r.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator help generate\nNAME\n openapi-generator-cli generate - Generate code with the specified\n generator.\n\nSYNOPSIS\n openapi-generator-cli generate\n [(-a | --auth )]\n [--api-name-suffix ] [--api-package ]\n [--artifact-id ] [--artifact-version ]\n [(-c | --config )] [--dry-run]\n [(-e | --engine )]\n [--enable-post-process-file]\n [(-g | --generator-name )]\n [--generate-alias-as-model] [--git-host ]\n [--git-repo-id ] [--git-user-id ]\n [--global-property ...] [--group-id ]\n [--http-user-agent ]\n (-i | --input-spec )\n [--ignore-file-override ]\n [--import-mappings ...]\n [--instantiation-types ...]\n [--invoker-package ]\n [--language-specific-primitives ...]\n [--library ] [--log-to-stderr] [--minimal-update]\n [--model-name-prefix ]\n [--model-name-suffix ]\n [--model-package ]\n [(-o | --output )] \n [(-p | --additional-properties )...]\n [--package-name ] [--release-note ]\n [--remove-operation-id-prefix]\n [--reserved-words-mappings ...]\n [(-s | --skip-overwrite)] [--server-variables ...]\n [--skip-validate-spec] [--strict-spec ]\n [(-t