Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jsonschema/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type Definition struct {
AdditionalProperties any `json:"additionalProperties,omitempty"`
// Whether the schema is nullable or not.
Nullable bool `json:"nullable,omitempty"`
// MaxLength specifies the maximum length of a string.
MaxLength int `json:"maxLength,omitempty"`

// Ref Reference to a definition in $defs or external schema.
Ref string `json:"$ref,omitempty"`
Expand Down
11 changes: 11 additions & 0 deletions jsonschema/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ func TestDefinition_MarshalJSON(t *testing.T) {
}
}`,
},
{
name: "Test with MaxLength",
def: jsonschema.Definition{
Type: jsonschema.String,
MaxLength: 100,
},
want: `{
"type":"string",
"maxLength":100
}`,
},
}

for _, tt := range tests {
Expand Down
Loading