---
# System prepended metadata

title: ytt schema default annotation open questions
tags: [ytt]

---

---
title: ytt schema default annotation open questions
tags: ytt
---

## Current (implicit) defaulting for maps
Data Values Schemas will automatically insert any item missing from a map with its defaults.

#### Example:
`schema.yml`
```
#@data/values-schema
---
job:
  name: default
  run: "" 
```
`dataValues.yml`
```
#@data/values
---
job:
  run: ./script.sh
```
`ytt -f schema.yml dataValues.yml --data-values-inspect`
```
job:
  name: default
  run: ./script.sh
```



## @schema/default

The `@schema/default` annotation explicitly sets the default value of the annotated node.

```yaml
@schema/default value
```

- `value` (any except `function`) — the overriding default value.

#### Example:
`schema.yml`
```
#@data/values-schema
---
#@schema/default {'run':'./script.sh'}
job:
  name: default
  run: "" 
```
`ytt -f schema.yml --data-values-inspect`
#### option 1 - #@ schema/default completely takes over default behavior
```
job:
  run: ./script.sh
```
#### option 2 - #@ schema/default takes priority over implicit default behavior
```
job:
  name: default
  run: ./script.sh
```
---
## More complex example

#### Example:
Implicit defaulting (no `@schema/default`)

`schema.yml`:
```
#@data/values-schema
---
databases:
- name: ""
  adapter: postgresql
  host: ""
  port: 5432
  user: admin
  secretRef:
    name: ""
```

`dataValues.yml`:
```
#@data/values
---
databases:
- name: uaa
- name: capi
  host: capi-db.svc.cluster.local
  secretRef:
    name: capi-db-credentials
- {}
```
`ytt -f schema.yml -f dataValues.yml --data-values-inspect`
```
databases:
- name: uaa
  adapter: postgresql
  host: ""
  port: 5432
  user: admin
  secretRef:
    name: ""
- name: capi
  adapter: postgresql
  host: capi-db.svc.cluster.local
  port: 5432
  user: admin
  secretRef:
    name: capi-db-credentials
- name: ""
  adapter: postgresql
  host: ""
  port: 5432
  user: admin
  secretRef:
    name: ""
```

#### Example:
Explicit defaulting (with `@schema/default`)

`schema.yml`:
```
#@ def uaa_db():
name: uaa
host: uaa-db.svc.cluster.local
user: admin
#@ end

#@ def capi_db():
name: capi-embedded
user: admin
#@ end

#@data/values-schema
---
#@schema/default [uaa_db(), capi_db(), {"name": "null_db"}]
databases:
- name: ""
  adapter: postgresql
  host: ""
  port: 5432
  user: admin
  secretRef:
    name: ""
```
`ytt -f schema.yml --data-values-inspect`
#### option 1 - #@ schema/default completely takes over default behavior
```
databases:
- name: uaa
  host: uaa-db.svc.cluster.local
  user: admin
- name: capi-embedded
  user: admin
- name: null_db
```
#### option 2 - #@ schema/default takes priority over implicit default behavior
```
databases:
- name: uaa
  host: uaa-db.svc.cluster.local
  user: admin
  adapter: postgresql
  port: 5432
  secretRef:
    name: ""
- name: capi-embedded
  user: admin
  adapter: postgresql
  host: ""
  port: 5432
  secretRef:
    name: ""
- name: null_db
  adapter: postgresql
  host: ""
  port: 5432
  user: admin
  secretRef:
    name: ""
```
