Canonicalize option for /v1/jobs/parse-endpoint does not set defaults for ParameterizedJob Payload
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
# Nomad version
Output from `0.10.2`, bug also tested and verified on `0.11.0-beta2`.
### Operating system and Environment details
### Issue
When I read the documentation for ParseJob (https://nomadproject.io/api-docs/jobs/#parse-job) it says the following about `Canonicalize`:
> Canonicalize (bool: false) - Flag to enable setting any unset fields to their default values.
### Reproduction steps
```bash
curl -X "POST" "http://nomadserver.vpn.kaspergrubbe.com:4646/v1/jobs/parse" \
-H 'Accept: application/json' \
-H 'Content-Type: application/json; charset=utf-8' \
-d $'{
"Canonicalize": true,
"JobHCL": "job \\"example\\" { parameterized = { meta_required = [\\"SLEEP_TIME\\"] } type = \\"service\\" group \\"cache\\" {} }" | jq '.["ParameterizedJob"]'
}'
```
#### Output:
```json
{
"MetaOptional": null,
"MetaRequired": [
"SLEEP_TIME"
],
"Payload": ""
}
```
#### Expected output:
```json
{
"MetaOptional": null,
"MetaRequired": [
"SLEEP_TIME"
],
"Payload": "optional"
}
```
When I go to http://nomadserver.vpn.kaspergrubbe.com:4646/ui/jobs/example/definition I also see that Payload is optional there:

When reading the structs file, it also doesn't seem like an empty value is even valid: https://github.com/hashicorp/nomad/blob/d3e72883343ca5c5dbf23c72a78ac9174e55f940/nomad/structs/structs.go#L4491-L4524
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the /v1/jobs/parse endpoint and inspect the ParameterizedJob definition in nomad/structs/structs.go at the referenced lines. Reproduce the request with Canonicalize set to true and compare Payload with the documented default. Done means unset Payload fields receive their documented default while the existing parameterized job fields remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100