Class ProtobufSchemaCodegen

    • Constructor Detail

      • ProtobufSchemaCodegen

        public ProtobufSchemaCodegen()
    • Method Detail

      • toOperationId

        public String toOperationId​(String operationId)
        Description copied from class: DefaultCodegen
        Return the operation ID (method name)
        Overrides:
        toOperationId in class DefaultCodegen
        Parameters:
        operationId - operation ID
        Returns:
        the sanitized method name
      • addEnumValuesPrefix

        public void addEnumValuesPrefix​(Map<String,​Object> allowableValues,
                                        String prefix)
        Adds prefix to the enum allowable values NOTE: Enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. Therefore, enum value must be unique
        Parameters:
        allowableValues - allowable values
        prefix - added prefix
      • addUnspecifiedToAllowableValues

        public void addUnspecifiedToAllowableValues​(Map<String,​Object> allowableValues)
        Adds unknown value to the enum allowable values
        Parameters:
        allowableValues - allowable values
      • addEnumIndexes

        public void addEnumIndexes​(List<Map<String,​Object>> enumVars)
        Iterates enum vars and puts index to them
        Parameters:
        enumVars - list of enum vars
      • postProcessModels

        public ModelsMap postProcessModels​(ModelsMap objs)
        Post-processes CodegenModel objects to apply protobuf-specific transformations.

        This method performs several critical operations:

        1. Processes enum definitions and optionally extracts them to separate files
        2. Sets vendor extensions for protobuf field types and data types
        3. Assigns field numbers based on configuration
        4. Handles oneOf/anyOf composition schemas

        Enum Extraction Behavior: When extractEnumsToSeparateFiles is enabled, inline enum properties are extracted to separate .proto files wrapped in message containers. This prevents enum value name collisions in the protobuf global namespace. The resulting format is:

         message EnumName {
           enum Enum {
             VALUE1 = 0;
             VALUE2 = 1;
           }
         }
         
        References to these enums use the qualified name EnumName.Enum.
        Specified by:
        postProcessModels in interface CodegenConfig
        Overrides:
        postProcessModels in class DefaultCodegen
        Parameters:
        objs - the models map containing all CodegenModel objects
        Returns:
        the modified models map with protobuf-specific transformations applied
        See Also:
        extractEnumsToSeparateFiles(ModelsMap), extractEnums(ModelsMap)
      • manageChildrenProperties

        public void manageChildrenProperties​(Map<String,​ModelsMap> objs,
                                             Map<String,​CodegenModel> allModels)
        Manages property and import propagation from child models to parent models. In protobuf, inheritance doesn't exist, so all descendant properties must be copied to parent models to achieve pseudo-inheritance. This method uses a two-phase approach: 1. Bottom-up propagation: Each model copies properties to all its ancestors 2. Discriminator aggregation: Discriminator parents recursively collect from ALL descendants
        Parameters:
        objs - the complete models map for import tracking
        allModels - map of all CodegenModels by name
      • aggregateModels

        public Map<String,​ModelsMap> aggregateModels​(Map<String,​ModelsMap> objs)
        Aggregates all individual model definitions into a single entry.
        Parameters:
        objs - the original map of model names to their respective entries
        Returns:
        a new Map containing a single entry keyed by aggregateModelsName with combined models and imports from all provided entries
      • addImport

        public void addImport​(Map<String,​ModelsMap> objs,
                              CodegenModel cm,
                              String importValue)
        Adds an import to a CodegenModel, preventing duplicate imports.
        Parameters:
        objs - the complete models map for import tracking
        cm - the CodegenModel to add the import to
        importValue - the import path (e.g., "models/pet" or "Pet")
      • toDefaultValue

        public String toDefaultValue​(io.swagger.v3.oas.models.media.Schema p)
        Return the default value of the property
        Overrides:
        toDefaultValue in class DefaultCodegen
        Parameters:
        p - OpenAPI property object
        Returns:
        string presentation of the default value of the property
      • toApiName

        public String toApiName​(String name)
        Description copied from class: DefaultCodegen
        Output the API (class) name (capitalized) ending with the specified or default suffix Return DefaultApi if name is empty
        Specified by:
        toApiName in interface CodegenConfig
        Overrides:
        toApiName in class DefaultCodegen
        Parameters:
        name - the name of the Api
        Returns:
        capitalized Api name
      • toVarName

        public String toVarName​(String name)
        Description copied from class: DefaultCodegen
        Return the variable name by removing invalid characters and proper escaping if it's a reserved word.
        Overrides:
        toVarName in class DefaultCodegen
        Parameters:
        name - the variable name
        Returns:
        the sanitized variable name
      • toParamName

        public String toParamName​(String name)
        Description copied from class: DefaultCodegen
        Return the parameter name by removing invalid characters and proper escaping if it's a reserved word.
        Specified by:
        toParamName in interface CodegenConfig
        Overrides:
        toParamName in class DefaultCodegen
        Parameters:
        name - Codegen property object
        Returns:
        the sanitized parameter name
      • toModelName

        public String toModelName​(String name)
        Description copied from class: DefaultCodegen
        Converts the OpenAPI schema name to a model name suitable for the current code generator. May be overridden for each programming language. In case the name belongs to the TypeSystem it won't be renamed.
        Specified by:
        toModelName in interface CodegenConfig
        Overrides:
        toModelName in class DefaultCodegen
        Parameters:
        name - the name of the model
        Returns:
        capitalized model name
      • getSchemaType

        public String getSchemaType​(io.swagger.v3.oas.models.media.Schema p)
        Description copied from class: DefaultCodegen
        returns the OpenAPI type for the property. Use getAlias to handle $ref of primitive type
        Overrides:
        getSchemaType in class DefaultCodegen
        Parameters:
        p - property schema
        Returns:
        string presentation of the type
      • addProperties

        protected void addProperties​(Map<String,​io.swagger.v3.oas.models.media.Schema> properties,
                                     List<String> required,
                                     io.swagger.v3.oas.models.media.Schema schema,
                                     Set<io.swagger.v3.oas.models.media.Schema> visitedSchemas)
        Handles additionalProperties defined in composed schemas (e.g., allOf) by injecting into the model's properties. Example: components: schemas: Dog: allOf: - $ref: '#/components/schemas/DogBase' - type: object additionalProperties: title: pet $ref: '#/components/schemas/Pet' In this case, the second allOf that defines a map with string keys and Pet values will be part of model's property.
        Overrides:
        addProperties in class DefaultCodegen
        Parameters:
        properties - all properties
        required - required property only
        schema - schema in which the properties will be added to the lists
        visitedSchemas - circuit-breaker - the schemas with which the method was called before for recursive structures