(window.webpackJsonp=window.webpackJsonp||[]).push([[90],{218:function(e,t,n){"use strict";n.r(t),n.d(t,"frontMatter",(function(){return r})),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),i=(n(0),n(317)),r={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:"Kevin Chen",lastUpdatedAt:1637429145,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(i.b)("wrapper",Object(a.a)({},s,n,{components:t,mdxType:"MDXLayout"}),Object(i.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(i.b)("a",Object(a.a)({parentName:"p"},{href:"#generate"}),"generate")," command."),Object(i.b)("h2",{id:"help"},"help"),Object(i.b)("p",null,"The ",Object(i.b)("inlineCode",{parentName:"p"},"help")," option lists all commands available to the CLI."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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 batch Generate code in batch via external configs.\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(i.b)("h2",{id:"version"},"version"),Object(i.b)("p",null,"The version command provides version information, returning either the version by default, the git commit sha when passed ",Object(i.b)("inlineCode",{parentName:"p"},"--sha"),", or verbose output when passed ",Object(i.b)("inlineCode",{parentName:"p"},"--full"),"."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"NAME\n openapi-generator-cli version - Show version information used in tooling\n\nSYNOPSIS\n openapi-generator-cli version [--full] [--sha]\n\nOPTIONS\n --full\n Full version details\n\n --sha\n Git commit SHA version\n")),Object(i.b)("h2",{id:"list"},"list"),Object(i.b)("p",null,"The ",Object(i.b)("inlineCode",{parentName:"p"},"list")," command outputs a formatted list of every available generator. Pass the ",Object(i.b)("inlineCode",{parentName:"p"},"-s/--short")," option if you would like a CSV output for easy parsing."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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")),Object(i.b)("p",null,"Example:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator-cli list -s | tr ',' '\\n'\n")),Object(i.b)("p",null,"For the full list of generators, refer to the ",Object(i.b)("a",Object(a.a)({parentName:"p"},{href:"/docs/generators"}),"Generators List"),"."),Object(i.b)("h2",{id:"config-help"},"config-help"),Object(i.b)("p",null,"The ",Object(i.b)("inlineCode",{parentName:"p"},"config-help")," option provides details about "),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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 )] [--feature-set]\n [--full-details]\n [(-g | --generator-name )]\n [--import-mappings] [--instantiation-types]\n [--language-specific-primitive] [--markdown-header] [--named-header]\n [(-o | --output )] [--reserved-words]\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 --feature-set\n displays feature set as supported by the generator\n\n --full-details\n displays CLI options as well as other configs/mappings (implies\n --instantiation-types, --reserved-words,\n --language-specific-primitives, --import-mappings,\n --supporting-files)\n\n -g , --generator-name \n generator to get config help for\n\n --import-mappings\n displays the default import mappings (types and aliases, and what\n imports they will pull into the template)\n\n --instantiation-types\n displays types used to instantiate simple type/alias names\n\n --language-specific-primitive\n displays the language specific primitives (types which require no\n additional imports, or which may conflict with user defined model\n names)\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 --reserved-words\n displays the reserved words which may result in renamed model or\n property names\n")),Object(i.b)("p",null,"The option of note is ",Object(i.b)("inlineCode",{parentName:"p"},"-g/--generator-name")," (other options are exposed for tooling)."),Object(i.b)("p",null,"You may pass any generator name (see ",Object(i.b)("a",Object(a.a)({parentName:"p"},{href:"#list"}),"list")," command) to ",Object(i.b)("inlineCode",{parentName:"p"},"-g"),", and options specific to that generator will be displayed. Some generators have ",Object(i.b)("em",{parentName:"p"},"many")," options, while others may have only a few."),Object(i.b)("p",null,"Example:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator-cli config-help -g go\n")),Object(i.b)("p",null,"Outputs:"),Object(i.b)("pre",null,Object(i.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(i.b)("p",null,"To pass these go client generator-specific options to the ",Object(i.b)("inlineCode",{parentName:"p"},"generate")," command for a go client, use the ",Object(i.b)("inlineCode",{parentName:"p"},"--additional-properties")," option. See the ",Object(i.b)("a",Object(a.a)({parentName:"p"},{href:"#generate"}),"generate")," command section for an example."),Object(i.b)("h2",{id:"meta"},"meta"),Object(i.b)("p",null,"The ",Object(i.b)("inlineCode",{parentName:"p"},"meta")," command creates a new Java class and template files, used for creating your own custom templates."),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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 [(-l | --language )]\n [(-n | --name )]\n [(-o | --output )]\n [(-p | --package )] [(-t | --type )]\n\nOPTIONS\n -l , --language \n the implementation language for the generator class\n\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(i.b)("p",null,"For an in-depth example of using the ",Object(i.b)("inlineCode",{parentName:"p"},"meta")," command, see ",Object(i.b)("a",Object(a.a)({parentName:"p"},{href:"/docs/customization"}),"Customization"),"."),Object(i.b)("h2",{id:"validate"},"validate"),Object(i.b)("p",null,"The ",Object(i.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(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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")),Object(i.b)("p",null,"Valid Spec Example (using ",Object(i.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(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator-cli validate -i petstore-v3.0.yaml\n")),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"Validating spec (petstore-v3.0.yaml)\nNo validation issues detected.\n")),Object(i.b)("p",null,"Invalid Spec Example (using ",Object(i.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(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator-cli validate -i petstore-v3.0-invalid.yaml\n")),Object(i.b)("pre",null,Object(i.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(i.b)("h2",{id:"completion"},"completion"),Object(i.b)("p",null,"Although not documented in the ",Object(i.b)("inlineCode",{parentName:"p"},"help")," output, the CLI offers a ",Object(i.b)("inlineCode",{parentName:"p"},"completion")," command, which can be used for auto-completion."),Object(i.b)("p",null,"This command takes one or more parameters representing the args list you would otherwise pass to ",Object(i.b)("inlineCode",{parentName:"p"},"openapi-generator"),". For example:"),Object(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-bash"}),"openapi-generator-cli completion config-help\n-o\n--output\n--named-header\n-g\n--generator-name\n-f\n--format\n--markdown-header\n")),Object(i.b)("p",null,"An example bash completion script can be found in the repo at ",Object(i.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(i.b)("h2",{id:"generate"},"generate"),Object(i.b)("p",null,"The ",Object(i.b)("inlineCode",{parentName:"p"},"generate")," command is the workhorse of the generator toolset. As such, it has ",Object(i.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(i.b)("pre",null,Object(i.b)("code",Object(a.a)({parentName:"pre"},{className:"language-text"}),"openapi-generator-cli 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 [--legacy-discriminator-behavior] [--library ]\n [--log-to-stderr] [--minimal-update]\n [--model-name-prefix ]\n [--model-name-suffix ]\n [--model-package ]\n [(-o | --output )] [(-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-operation-example] [--skip-validate-spec]\n [--strict-spec ]\n [(-t