OpenAPITools / OpenAPITools/openapi-generator

[BUG][Ruby] NameError when using OneOf in json schema

Open
#8,441 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Hi,

I used the openapi-generator to build ruby code from a json schema, which is using oneOf relations for some of their attributes in the response data model.

"UserDto": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "id": {
        "type": "string",
        "description": "The id of the user."
      },
      "fullName": {
        "type": "string",
        "description": "The full name of the user."
      },
      "settings": {
        "description": "Notification settings per channel.",
        "oneOf": [
          {
            "$ref": "#/components/schemas/NotificationSettingsDto"
          }
        ]
      }
    }
  },
  "NotificationSettingsDto": {
    "type": "object",
    "additionalProperties": {
      "$ref": "#/components/schemas/NotificationSettingDto"
    }
  },
  "NotificationSettingDto": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "send": {
        "type": "boolean",
        "description": "True or false to send the notification for the channel.",
        "nullable": true
      },
      "delayInSeconds": {
        "type": "integer",
        "description": "The delay in seconds.",
        "format": "int32",
        "nullable": true
      }
    }
  }

Building and integration into my app is working, but when calling the endpoint I get following error for the response model:
#<NameError: uninitialized constant APP::OneOfmap>

The generated code for the user_dto contains the method:

 def self.openapi_types
  {
    :'id' => :'String',
    :'full_name' => :'String',
    :'settings' => :'OneOfmap''
  }
end

Is this correct? I can't find any information about "OneOfmap", neither any example.
Any help is appreciated

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named in the report. Start by reproducing the schema with the Ruby generator and trace oneOf plus additionalProperties handling into the generated user_dto openapi_types method; done when the generated response model no longer references the unresolved OneOfmap constant and the endpoint response works.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.