Skip to content

Adding maxItems to a custom array type in JSON schema #144

@LazarenkoA

Description

@LazarenkoA

I have the following Go structure:

type CustomTypes []CustomType

type test struct {
    Field1 CustomTypes `json:"field1"`
}

This generates the following JSON schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://stash.sigma.sbrf.ru/scpl/core.agentserver/pkg/app/test",
  "$ref": "#/$defs/test",
  "$defs": {
    "CustomType": {
      "properties": {},
      "additionalProperties": false,
      "type": "object"
    },
    "CustomTypes": {
      "items": {
        "$ref": "#/$defs/CustomType"
      },
      "type": "array"
    },
    "test": {
      "properties": {
        "field1": {
          "$ref": "#/$defs/CustomTypes"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "field1"
      ]
    }
  }
}

I need to add a maxItems constraint to the CustomTypes array, for example:

"CustomTypes": {
      "items": {
        "$ref": "#/$defs/CustomType"
      },
      "type": "array",
      "maxItems": 10
    }

How can I achieve this? I can't add a tag to the type definition in Go.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions