sbt-openapi-generator

April 28, 2026 ยท View on GitHub

A Sbt plugin to support the OpenAPI generator project.

Usage

Add to your project/plugins.sbt:

addSbtPlugin("org.openapitools" % "sbt-openapi-generator" % "7.22.0")

Configuration

Configuration based on project module is recommended way to separate specifications by modules.

You must define one of the settings openApiInputSpec or openApiConfigFile to able run plugin to generate.

Settings will be picked up from openApiConfigFile first if defined and then will be overwritten with module specified settings if provided

With the next example module generated will be defined as:

lazy val generated = project.in(file("generated"))
  .settings(
    openApiInputSpec := "openapi.yaml",
    openApiConfigFile := "config.yaml"
  )

There is a helpers to have boolean settings more readable. Instead of Some(true) it possible to do next:

    openApiValidateSpec := SettingDisabled,
    openApiGenerateModelTests := SettingEnabled,

Execution

To print all available languages use

sbt openApiGenerators

To run template generation process

sbt openApiGenerate

or per defined module

sbt generated/openApiGenerate

Settings

SettingTypeDescription
openApiGeneratorName *StringThe name of the generator which will handle codegen. (see "openApiGenerators" task)
Required. Can be provided as generatorName option of openApiConfigFile json config
openApiInputSpec *StringThe Open API 2.0/3.x specification location (file or url)
Required. Can be provided as inputSpec option of openApiConfigFile json config
openApiOutputDirStringThe output target directory into which code will be generated
openApiConfigFile **StringPath to json configuration file
This setting is required with generatorName and inputSpec settings provided if sbt settings openApiGeneratorName and openApiInputSpec are absent
openApiAdditionalPropertiesMap[String, String]Sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. You can also have multiple occurrences of this option
openApiGlobalPropertiesMap[String, String]Sets specified system properties
openApiVerboseOption[Boolean]The verbosity of generation
openApiValidateSpecOption[Boolean]Whether or not an input specification should be validated upon generation
openApiTemplateDirStringThe template directory holding a custom template
openApiAuthStringAdds authorization headers when fetching the OpenAPI definitions remotely. Pass in a URL-encoded string of name:header with a comma separating multiple values
openApiSkipOverwriteOption[Boolean]Specifies if the existing files should be overwritten during the generation
openApiPackageNameStringPackage for generated classes (where supported)
openApiApiPackageStringPackage for generated api classes
openApiModelPackageStringPackage for generated models
openApiModelNamePrefixStringPrefix that will be prepended to all model names
openApiModelNameSuffixStringSuffix that will be appended to all model names
openApiInstantiationTypesMap[String, String]Sets instantiation type mappings
openApiTypeMappingsMap[String, String]Sets mappings between OpenAPI spec types and generated code types
openApiServerVariablesMap[String, String]Sets server variable for server URL template substitution, in the format of name=value,name=value. You can also have multiple occurrences of this option
openApiLanguageSpecificPrimitivesList[String]Specifies additional language specific primitive types in the format of type1,type2,type3,type3. For example: String,boolean,Boolean,Double
openApiImportMappingsMap[String, String]Specifies mappings between a given class and the import that should be used for that class
openApiInvokerPackageStringRoot package for generated code
openApiGroupIdStringgroupId in generated pom.xml/build.sbt
openApiIdStringartifactId in generated pom.xml/build.sbt. This also becomes part of the generated library's filename
openApiLibraryStringlibrary template (sub-template)
openApiGitHostStringGit host, e.g. gitlab.com
openApiGitUserIdStringGit user ID, e.g. openapitools
openApiGitRepoIdStringGit repo ID, e.g. openapi-generator
openApiReleaseNoteStringRelease note, default to 'Minor update'
openApiHttpUserAgentStringHTTP user agent, e.g. codegen_csharp_api_client, default to 'OpenAPI-Generator/{packageVersion}}/{language}'
openApiReservedWordsMappingsMap[String, String]]("Specifies how a reserved name should be escaped to
openApiIgnoreFileOverrideStringSpecifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.
openApiRemoveOperationIdPrefixOption[Boolean]Remove prefix of operationId, e.g. config_getId => getId
openApiApiFilesConstrainedToList[String]Defines which API-related files should be generated. This allows you to create a subset of generated files (or none at all)
openApiModelFilesConstrainedToList[String]Defines which model-related files should be generated. This allows you to create a subset of generated files (or none at all)
openApiSupportingFilesConstrainedToList[String]Defines which supporting files should be generated. This allows you to create a subset of generated files (or none at all
openApiGenerateModelTestsOption[Boolean]Specifies that model tests are to be generated
openApiGenerateModelDocumentationOption[Boolean]Defines whether or not model-related documentation files should be generated
openApiGenerateApiTestsOption[Boolean]Specifies that api tests are to be generated
openApiGenerateApiDocumentationOption[Boolean]Defines whether or not api-related documentation files should be generated
openApiWithXmlOption[Boolean]A special-case setting which configures some generators with XML support. In some cases, this forces json OR xml, so the default here is false
openApiLogToStderrOption[Boolean]To write all log messages (not just errors) to STDOUT
openApiEnablePostProcessFileOption[Boolean]Enable post-processing file using environment variables
openApiSkipValidateSpecOption[Boolean]To skip spec validation. When true, we will skip the default behavior of validating a spec before generation
openApiGenerateAliasAsModelOption[Boolean]Generate model implementation for aliases to map and array schemas
openApiGenerateMetadataOption[Boolean]Generate metadata files used by OpenAPI Generator. This includes .openapi-generator-ignore and any files within .openapi-generator.

Examples

Please see an sbt-test configuration for examples of using the plugin. Do not run those examples directly, please copy them to separate place first.

Contribution and Tests

Write plugin integration tests under src/sbt-test

Execute next command to run tests:

sbt scripted

More information about how to write and execute tests is here