Class EnumValueInterfaceUtils
- java.lang.Object
-
- org.openapitools.codegen.languages.EnumValueInterfaceUtils
-
public final class EnumValueInterfaceUtils extends Object
Language-agnostic utility for theuseEnumValueInterfacecode-generation option.When enabled, every generated enum (both top-level schema enums and inline property enums) is made to implement a common
ValuedEnum<T>interface that exposes the backing value, allowing generic code to access enum values without reflection.Two entry points are provided, one for each generator lifecycle hook:
setupInPreprocessOpenAPI(java.util.Map<java.lang.String, java.lang.String>, java.util.Map<java.lang.String, java.lang.Object>, java.util.List<org.openapitools.codegen.SupportingFile>, java.lang.String, java.lang.String, java.lang.String, java.lang.String)— called frompreprocessOpenAPIto register the supporting file and the import mapping.injectInPostProcessModelsEnum(org.openapitools.codegen.model.ModelsMap, java.lang.String, java.lang.String, java.lang.String)— called frompostProcessModelsEnumto inject the interface into every enum model's implements vendor extension.
The only language-specific knobs are:
- The name of the vendor extension that carries implemented interfaces
(
"x-implements"for Java,"x-kotlin-implements"for Kotlin). - The output file name (
"ValuedEnum.java"vs"ValuedEnum.kt").
Used by both
SpringCodegenandKotlinSpringServerCodegen.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidinjectInPostProcessModelsEnum(ModelsMap objs, String valuedEnumClassName, String valuedEnumFqn, String xImplementsExtensionKey)InjectsValuedEnum<T>into the implements vendor extension of every enum in the given model batch.static StringsetupInPreprocessOpenAPI(Map<String,String> importMapping, Map<String,Object> additionalProperties, List<SupportingFile> supportingFiles, String sourceFolder, String configPackage, String mustacheTemplate, String outputFileName)Registers theValuedEnumsupporting file and import mapping.
-
-
-
Method Detail
-
setupInPreprocessOpenAPI
public static String setupInPreprocessOpenAPI(Map<String,String> importMapping, Map<String,Object> additionalProperties, List<SupportingFile> supportingFiles, String sourceFolder, String configPackage, String mustacheTemplate, String outputFileName)
Registers theValuedEnumsupporting file and import mapping.Must be called from
preprocessOpenAPIwhenuseEnumValueInterfaceis enabled. Returns the simple class name derived from the (possibly custom) import mapping, which the caller must store and pass toinjectInPostProcessModelsEnum(org.openapitools.codegen.model.ModelsMap, java.lang.String, java.lang.String, java.lang.String)later.- Parameters:
importMapping- the codegen's import-mapping map (mutated in place)additionalProperties- the codegen's additional-properties map (mutated in place)supportingFiles- the codegen's supporting-files list (mutated in place)sourceFolder- language source folder (e.g."src/main/java")configPackage- the config package where the interface is generated (e.g."org.openapitools.configuration")mustacheTemplate- template name (e.g."enumValueInterface.mustache")outputFileName- generated file name (e.g."ValuedEnum.java")- Returns:
- the simple class name of
ValuedEnum(accounts for custom import mappings)
-
injectInPostProcessModelsEnum
public static void injectInPostProcessModelsEnum(ModelsMap objs, String valuedEnumClassName, String valuedEnumFqn, String xImplementsExtensionKey)
InjectsValuedEnum<T>into the implements vendor extension of every enum in the given model batch.Must be called from
postProcessModelsEnumwhenuseEnumValueInterfaceis enabled. Handles both top-level enum schemas and inline enum properties.- Parameters:
objs- the model batch being post-processedvaluedEnumClassName- simple class name (e.g."ValuedEnum")valuedEnumFqn- fully-qualified name used for the import statementxImplementsExtensionKey- vendor-extension key that carries the implements list ("x-implements"for Java,"x-kotlin-implements"for Kotlin)
-
-