YAML Config and API Patterns

Application config, OpenAPI, environment settings, and interoperability patterns for YAML across modern tooling.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## App config patterns
App config example
app:
  name: Cheatsheet.today
  env: production
  features:
    ai_search: true
    premium_packs: true
  database:
    host: localhost
    port: 5432

# Structure app settings in a readable YAML document.

Environment-specific config
environments:
  development:
    log_level: debug
  production:
    log_level: info

# Model different settings by environment.

OpenAPI YAML snippet
openapi: 3.1.0
info:
  title: ExpressYou API
  version: 1.0.0
paths: {}

# Show how YAML appears in API documentation.

Validate an OpenAPI YAML file
swagger-cli validate openapi.yaml

# Check API spec correctness from the command line.

## Conversion and interoperability
Convert JSON to YAML with Python
python - <<'PY'
import json, yaml, sys
print(yaml.safe_dump(json.load(open('config.json')), sort_keys=False))
PY

# Transform JSON into YAML output for config workflows.

Convert JSON to YAML with yq
yq -P -p=json '.' config.json

# Convert JSON input into YAML from the shell.

Convert Compose to resolved output
docker compose convert

# Render final service configuration from a YAML Compose file.

Build layered Kubernetes YAML
kustomize build overlays/prod

# Generate final Kubernetes YAML from base and overlays.

Recommended next

No recommendations yet.