Skip to content

oneOf conversion from enum with default value fails #2182

@rd-andreas-tollkoetter

Description

@rd-andreas-tollkoetter

found in a modified version of the Langsmith API : openapi.json

      "FeedbackCreateCoreSchema": {
        "properties": {
          "feedback_source": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/AppFeedbackSource"
              },
              {
                "$ref": "#/components/schemas/APIFeedbackSource"
              },
              {
                "$ref": "#/components/schemas/ModelFeedbackSource"
              },
              {
                "$ref": "#/components/schemas/AutoEvalFeedbackSource"
              }
            ],
            "discriminator": {
              "propertyName": "type",
              "mapping": {
                "api": "#/components/schemas/APIFeedbackSource",
                "app": "#/components/schemas/AppFeedbackSource",
                "auto_eval": "#/components/schemas/AutoEvalFeedbackSource",
                "model": "#/components/schemas/ModelFeedbackSource"
              }
            },
            "nullable": true
          },
         },
        "type": "object",
        "required": [
          "key"
        ],
        "title": "FeedbackCreateCoreSchema",
        "description": "Schema used for creating feedback without run id or session id."
      },

//...

"AppFeedbackSource": {
        "properties": {
          "type": {
            "type": "string",
            "title": "Type",
            "default": "app",
            "enum": [
              "app"
            ]
          },
          "metadata": {
            "additionalProperties": true,
            "type": "object",
            "nullable": true
          }
        },
        "type": "object",
        "title": "AppFeedbackSource",
        "description": "Feedback from the LangChainPlus App."
      },

This generates the following code:

// FromAppFeedbackSource overwrites any union data inside the FeedbackCreateCoreSchema_FeedbackSource as the provided AppFeedbackSource
func (t *FeedbackCreateCoreSchema_FeedbackSource) FromAppFeedbackSource(v AppFeedbackSource) error {
	v.Type = "app"
	b, err := json.Marshal(v)
	t.union = b
	return err
}

// AppFeedbackSource Feedback from the LangChainPlus App.
type AppFeedbackSource struct {
	Metadata *map[string]interface{} `json:"metadata"`
	Type     *AppFeedbackSourceType  `json:"type,omitempty"`
}

// AppFeedbackSourceType defines model for AppFeedbackSource.Type.
type AppFeedbackSourceType string

Notable, the type of Type in AppFeedbackSource is *string, so the assignment v.Type = "app" is an error.

Is there any workaround for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions