Skip to content

Collapse anyOf with only one option? #296

@stevekuznetsov

Description

@stevekuznetsov

If I have a schema like:

        "rings": {
          "type": "array",
          "description": "Array of the deployment ring object.",
            "items": {
                "anyOf": [
                    {
                        "$ref": "#/definitions/deploymentRing"
                    }
                ]
            }
      }

In a sense, it's equivalent to:

        "rings": {
          "type": "array",
          "description": "Array of the deployment ring object.",
          "items": {
              "type": "object",
              "$ref": "#/definitions/deploymentRing"
          }
      }

For users that generate Go types using a JSONSchema they do not control, the use of anyOf in the above example will generate []interface{}, which is unfortunate and very much so not ergonomic, either on generation or parsing. Would it be acceptable to generate a Go struct in these cases with a definite type for the slice, even if that is not perfectly what the author of the JSONSchema intended?

I am not sure, but it seems like there may be some other tool that generates these "loose" JSONSchemas with anyOf array items with only one type, perhaps also a bug in that generator. Would be awesome to work around such cases on the consumer end with this tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions