---
layout: default
title: Attributes
parent: Deriving JsonSchema
nav_order: 1
permalink: /deriving/attributes
---
# Attributes
You can add attributes to your types to customize Schemars's derived `JsonSchema` implementation.
Serde also allows setting `#[serde(...)]` attributes which change how types are serialized, and Schemars will generally respect these attributes to ensure that generated schemas will match how the type is serialized by serde_json. `#[serde(...)]` attributes can be overriden using `#[schemars(...)]` attributes, which behave identically (e.g. `#[schemars(rename_all = "camelCase")]`). You may find this useful if you want to change the generated schema without affecting Serde's behaviour, or if you're just not using Serde.
## Table of Contents
1. [Supported Serde Attributes](#supported-serde-attributes)
- [`rename`](#rename)
- [`rename_all`](#rename_all)
- [`tag` / `untagged`](#tag)
- [`default`](#default)
- [`skip`](#skip)
- [`skip_serializing`](#skip_serializing)
- [`skip_deserializing`](#skip_deserializing)
- [`flatten`](#flatten)
- [`with`](#with)
1. [Other Attributes](#other-attributes)
- [Doc Comments (`doc`)](#doc)
## Supported Serde Attributes
`#[serde(rename = "name")]` / `#[schemars(rename = "name")]`
Set on a struct, enum, field or variant to use the given name in the generated schema instead of the Rust name. When used on a struct or enum, the given name will be used as the title for root schemas, and the key within the root's `definitions` property for subschemas.
If set on a struct or enum with generic type parameters, then the given name may contain them enclosed in curly braces (e.g. `{T}`) and they will be replaced with the concrete type names when the schema is generated.
Serde docs: [container](https://serde.rs/container-attrs.html#rename) / [variant](https://serde.rs/variant-attrs.html#rename) / [field](https://serde.rs/field-attrs.html#rename)
`#[serde(rename_all = "...")]` / `#[schemars(rename_all = "...")]`
Set on a struct, enum or variant to rename all fields according to the given case convention (see the Serde docs for details).
Serde docs: [container](https://serde.rs/container-attrs.html#rename_all) / [variant](https://serde.rs/variant-attrs.html#rename_all)
`#[serde(tag = "type")]` / `#[schemars(tag = "type")]` / `#[serde(untagged)]` / `#[schemars(untagged)]`
Set on an enum to generate the schema for the [internally tagged](https://serde.rs/enum-representations.html#internally-tagged) or [untagged](https://serde.rs/enum-representations.html#untagged) representation of this enum. Schemars does not currently support the adjacently tagged representation ([#4](https://github.com/GREsau/schemars/issues/4)).
Serde docs: [`tag`](https://serde.rs/container-attrs.html#tag) / [`untagged`](https://serde.rs/container-attrs.html#untagged)
`#[serde(default)]` / `#[schemars(default)]` / `#[serde(default = "path")]` / `#[schemars(default = "path")]`
Set on a struct or field to give fields a default value, which excludes them from the schema's `required` properties. The default will also be set on the field's schema's `default` property, unless it is skipped by a [`skip_serializing_if`](https://serde.rs/field-attrs.html#skip_serializing_if) attribute on the field. Any [`serialize_with`](https://serde.rs/field-attrs.html#serialize_with) or [`with`](https://serde.rs/field-attrs.html#with) attribute set on the field will be used to serialize the default value.
Serde docs: [container](https://serde.rs/container-attrs.html#default) / [field](https://serde.rs/field-attrs.html#default)
`#[serde(skip)]` / `#[schemars(skip)]`
Set on a variant or field to prevent it from appearing in any generated schema.
Serde docs: [variant](https://serde.rs/variant-attrs.html#skip) / [field](https://serde.rs/field-attrs.html#skip)
`#[serde(skip_serializing)]` / `#[schemars(skip_serializing)]`
Set on a field of a (non-tuple) struct to set the `writeOnly` property on that field's schema. Serde also allows this attribute on variants or tuple struct fields, but this will have no effect on generated schemas.
Serde docs: [field](https://serde.rs/field-attrs.html#skip_deserializing)
`#[serde(skip_deserializing)]` / `#[schemars(skip_deserializing)]`
Set on a variant or field. When set on a field of a (non-tuple) struct, that field's schema will have the `readOnly` property set. When set on a variant or tuple struct field Schemars will treat this the same as a [`skip`](#skip) attribute.
Serde docs: [variant](https://serde.rs/variant-attrs.html#skip_deserializing) / [field](https://serde.rs/field-attrs.html#skip_deserializing)
`#[serde(flatten)]` / `#[schemars(flatten)]`
Set on a field to include that field's contents as though they belonged to the field's container.
Serde docs: [field](https://serde.rs/field-attrs.html#flatten)
`#[serde(with = "Type")]` / `#[schemars(with = "Type")]`
Set on a field to generate this field's schema as the given type instead of the field's actual type. Serde allows the `with` attribute to refer to any module path, but Schemars requires this to be an actual type which implements `JsonSchema`.
Serde docs: [field](https://serde.rs/field-attrs.html#with)
## Other Attributes
Doc Comments (`#[doc = "..."]`)
If a struct, variant or field has any [doc comments](https://doc.rust-lang.org/stable/rust-by-example/meta/doc.html#doc-comments) (or [`doc` attributes](https://doc.rust-lang.org/rustdoc/the-doc-attribute.html)), then these will be used as the generated schema's `description`. If the first line is an ATX-style markdown heading (i.e. it begins with a # character), then it will be used as the schema's `title`, and the remaining lines will be the `description`.