Skip to content

[BUG][Ruby] Description undefined method build_from_hash in Ruby generated code #22495

@michael-reeves-nc

Description

@michael-reeves-nc

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Error message: failed with the exception 'undefined method 'build_from_hash' for module Builder::Filter

Previous builds of my Ruby files for my gem using 7.14.0 generated code that contained:

      # Builds the object
      # @param [Mixed] Data to be matched against the list of oneOf items
      # @return [Object] Returns the model or the data itself
      def build(data)
        discriminator_value = data[openapi_discriminator_name]
        return nil if discriminator_value.nil?

        klass = openapi_discriminator_mapping[discriminator_value.to_s.to_sym]
        return nil unless klass

        resolved_klass = Builder.const_get(klass)
        resolved_klass.build(data)
    end

while version 7.17.0 generates

      # Builds the object
      # @param [Mixed] Data to be matched against the list of oneOf items
      # @return [Object] Returns the model or the data itself
      def build(data)
        discriminator_value = data[openapi_discriminator_name]
        return nil if discriminator_value.nil?

        klass = openapi_discriminator_mapping[discriminator_value.to_s.to_sym]
        return nil unless klass

        Builder.const_get(klass).build_from_hash(data)
      end

this last line, build_from_hash is blowing up my call, while the code generated with 7.14.0 successfully processes the same request.

openapi-generator version

7.17.0

OpenAPI declaration file content or url

files are the same between generated versions

Generation Details

$ openapi-generator generate -c generator-config.json

generator-config.json:

{
  "generatorName": "ruby",
  "inputSpec": "./builder.yaml",
  "outputDir": "./",
  "packageName": "my_builder",
  "gemName": "my_builder",
  "gemAuthor": "MyCompany",
  "gemHomepage": "https://github.com/<my_company>/builder-ruby-sdk",
  "gemVersion": "0.0.24",
  "moduleName": "Builder",
  "templateDir": "./templates"
}
Steps to reproduce
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions