MarshalJSON marshals the schema into JSON, respecting the `Extensions` map to marshal extensions inline.
()
| 175 | // MarshalJSON marshals the schema into JSON, respecting the `Extensions` map |
| 176 | // to marshal extensions inline. |
| 177 | func (s *Schema) MarshalJSON() ([]byte, error) { |
| 178 | var typ any = s.Type |
| 179 | if s.Nullable { |
| 180 | typ = []string{s.Type, "null"} |
| 181 | } |
| 182 | |
| 183 | var contentMediaType string |
| 184 | if s.Format == "binary" { |
| 185 | contentMediaType = "application/octet-stream" |
| 186 | } |
| 187 | |
| 188 | props := s.Properties |
| 189 | for _, ps := range props { |
| 190 | if ps.hidden { |
| 191 | // Copy the map to avoid modifying the original schema. |
| 192 | props = make(map[string]*Schema, len(s.Properties)) |
| 193 | for k, v := range s.Properties { |
| 194 | if !v.hidden { |
| 195 | props[k] = v |
| 196 | } |
| 197 | } |
| 198 | break |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | return marshalJSON([]jsonFieldInfo{ |
| 203 | {"type", typ, omitEmpty}, |
| 204 | {"title", s.Title, omitEmpty}, |
| 205 | {"description", s.Description, omitEmpty}, |
| 206 | {"$ref", s.Ref, omitEmpty}, |
| 207 | {"format", s.Format, omitEmpty}, |
| 208 | {"contentMediaType", contentMediaType, omitEmpty}, |
| 209 | {"contentEncoding", s.ContentEncoding, omitEmpty}, |
| 210 | {"default", s.Default, omitNil}, |
| 211 | {"examples", s.Examples, omitEmpty}, |
| 212 | {"items", s.Items, omitEmpty}, |
| 213 | {"additionalProperties", s.AdditionalProperties, omitNil}, |
| 214 | {"properties", props, omitEmpty}, |
| 215 | {"enum", s.Enum, omitEmpty}, |
| 216 | {"minimum", s.Minimum, omitEmpty}, |
| 217 | {"exclusiveMinimum", s.ExclusiveMinimum, omitEmpty}, |
| 218 | {"maximum", s.Maximum, omitEmpty}, |
| 219 | {"exclusiveMaximum", s.ExclusiveMaximum, omitEmpty}, |
| 220 | {"multipleOf", s.MultipleOf, omitEmpty}, |
| 221 | {"minLength", s.MinLength, omitEmpty}, |
| 222 | {"maxLength", s.MaxLength, omitEmpty}, |
| 223 | {"pattern", s.Pattern, omitEmpty}, |
| 224 | {"patternDescription", s.PatternDescription, omitEmpty}, |
| 225 | {"minItems", s.MinItems, omitEmpty}, |
| 226 | {"maxItems", s.MaxItems, omitEmpty}, |
| 227 | {"uniqueItems", s.UniqueItems, omitEmpty}, |
| 228 | {"required", s.Required, omitEmpty}, |
| 229 | {"dependentRequired", s.DependentRequired, omitEmpty}, |
| 230 | {"minProperties", s.MinProperties, omitEmpty}, |
| 231 | {"maxProperties", s.MaxProperties, omitEmpty}, |
| 232 | {"readOnly", s.ReadOnly, omitEmpty}, |
| 233 | {"writeOnly", s.WriteOnly, omitEmpty}, |
| 234 | {"deprecated", s.Deprecated, omitEmpty}, |
nothing calls this directly
no test coverage detected