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

Reusable YAML examples for application settings, feature flags, and environment config.

App config example

Structure app settings in a readable YAML document.

yamlANYyamlconfigapplication
yaml
app:
  name: Cheatsheet.today
  env: production
  features:
    ai_search: true
    premium_packs: true
  database:
    host: localhost
    port: 5432
Notes

A common YAML layout for application config files and internal tools.

Environment-specific config

Model different settings by environment.

yamlANYyamlconfigenvironment
yaml
environments:
  development:
    log_level: debug
  production:
    log_level: info
Notes

Keeping environments in one structure can simplify smaller projects and documentation.

OpenAPI YAML snippet

Show how YAML appears in API documentation.

yamlANYyamlopenapiapi
yaml
openapi: 3.1.0
info:
  title: ExpressYou API
  version: 1.0.0
paths: {}
Notes

OpenAPI is a major YAML use case and an SEO-friendly adjacent topic.

Validate an OpenAPI YAML file

Check API spec correctness from the command line.

bashANYyamlopenapivalidation
bash
swagger-cli validate openapi.yaml
Notes

Useful when YAML is being used as an API contract rather than plain config.

Conversion and interoperability

Move YAML data between formats and systems safely.

Convert JSON to YAML with Python

Transform JSON into YAML output for config workflows.

bashANYyamljsonconversionpython
bash
python - <<'PY'
import json, yaml, sys
print(yaml.safe_dump(json.load(open('config.json')), sort_keys=False))
PY
Notes

Helpful when migrating configs or producing more human-readable output.

Convert JSON to YAML with yq

Convert JSON input into YAML from the shell.

bashANYyamljsonyq
bash
yq -P -p=json '.' config.json
Notes

Useful in scripts and format conversion pipelines.

Convert Compose to resolved output

Render final service configuration from a YAML Compose file.

bashANYyamlcomposeconversion
bash
docker compose convert
Notes

Useful for troubleshooting generated or inherited Compose config.

Build layered Kubernetes YAML

Generate final Kubernetes YAML from base and overlays.

bashANYyamlkustomizekubernetes
bash
kustomize build overlays/prod
Notes

A practical YAML workflow for teams using declarative deployment overlays.

Recommended next

No recommendations yet.