@@ -19,6 +19,7 @@ OpenMorph is a production-grade CLI and TUI tool for transforming OpenAPI vendor
1919## Features
2020
2121- Transform OpenAPI vendor extension keys in YAML/JSON
22+ - ** Default values injection** - Automatically set default values for parameters, schemas, and responses with rule-based matching
2223- ** Vendor-specific pagination extensions** - Auto-inject Fern, Speakeasy, and other vendor pagination metadata
2324- ** Auto-detection of array fields** - Automatically find results arrays in response schemas
2425- Interactive TUI for reviewing and approving changes
@@ -211,7 +212,7 @@ openmorph --input ./openapi --vendor-providers fern --config config.yaml
211212
212213### Example: Complete Transformation
213214
214- Transform keys, clean up pagination, and add vendor extensions:
215+ Transform keys, clean up pagination, add vendor extensions, and set default values :
215216
216217``` sh
217218openmorph --input ./openapi \
@@ -223,6 +224,22 @@ openmorph --input ./openapi \
223224 --config ./config.yaml
224225```
225226
227+ Your ` config.yaml ` can include all features:
228+
229+ ``` yaml
230+ mappings :
231+ x-foo : x-bar
232+ vendor_extensions :
233+ enabled : true
234+ providers :
235+ fern :
236+ # ... fern config
237+ default_values :
238+ enabled : true
239+ rules :
240+ # ... default value rules
241+ ```
242+
226243### Example: Pagination Priority
227244
228245Transform APIs to use only checkpoint pagination (highest priority):
@@ -485,6 +502,202 @@ openmorph --input ./openapi --dry-run --config config.yaml
485502 results_path: "$response.data"
486503` ` `
487504
505+ # # Default Values
506+
507+ OpenMorph includes a powerful default values feature that allows you to automatically set default values throughout your OpenAPI specifications. This feature supports complex rule-based matching and can be applied to parameters, request bodies, response schemas, and component schemas.
508+
509+ # ## Overview
510+
511+ The Default Values feature allows you to :
512+
513+ - Set defaults for **parameter schemas** (path, query, header, cookie)
514+ - Set defaults for **request body schemas**
515+ - Set defaults for **response schemas**
516+ - Set defaults for **component schemas** (reusable objects)
517+ - Apply defaults to **arrays** and **enum fields**
518+ - Use **regex patterns** for flexible property matching
519+ - Configure **rule priorities** for precise control
520+
521+ # ## Configuration
522+
523+ Default values are configured through the `default_values` section in your config file :
524+
525+ ` ` ` yaml
526+ default_values:
527+ enabled: true
528+ rules:
529+ # Set default limit for pagination parameters
530+ query_limit_defaults:
531+ target:
532+ location: "parameter"
533+ condition:
534+ parameter_in: "query"
535+ type: "integer"
536+ property_name: "(limit|size|page_size|per_page)"
537+ value: 20
538+ priority: 10
539+
540+ # Set default sort direction
541+ query_sort_defaults:
542+ target:
543+ location: "parameter"
544+ condition:
545+ parameter_in: "query"
546+ type: "string"
547+ property_name: "(sort|order|direction)"
548+ value: "asc"
549+ priority: 9
550+
551+ # Boolean fields default to true
552+ boolean_defaults:
553+ target:
554+ location: "component"
555+ condition:
556+ type: "boolean"
557+ property_name: "(active|enabled|is_.*)"
558+ value: true
559+ priority: 8
560+ ` ` `
561+
562+ # ## Configuration Options
563+
564+ # ### Target
565+
566+ - `location` : Where to apply defaults
567+ - ` "parameter"` - URL parameters (query, path, header, cookie)
568+ - ` "request_body"` - Request body schemas
569+ - ` "response"` - Response body schemas
570+ - ` "component"` - Component schemas (reusable objects)
571+ - `property` : Optional specific property name to target
572+ - `path` : Optional JSONPath-like selector for precise targeting
573+
574+ # ### Conditions
575+
576+ - `type` : Schema type constraint (`"string"`, `"integer"`, `"boolean"`, `"array"`, `"object"`)
577+ - `parameter_in` : For parameters - where they're located (`"query"`, `"path"`, `"header"`, `"cookie"`)
578+ - `http_methods` : List of HTTP methods to target (`["get", "post"]`)
579+ - `path_patterns` : List of regex patterns for API paths (`["/api/v1/.*"]`)
580+ - `has_enum` : Only apply to fields with enum constraints
581+ - `is_array` : Only apply to array-type fields
582+ - `property_name` : Regex pattern to match property names (`"(limit|size|page_size)"`)
583+ - `required` : Apply only to required (`true`) or optional (`false`) fields
584+
585+ # ### Values
586+
587+ - `value` : Simple default value (string, number, boolean, array, object)
588+ - `template` : Complex template object for structured defaults
589+ - `priority` : Rule priority (higher numbers = higher priority)
590+
591+ # ## Usage Examples
592+
593+ **Apply defaults using config file:**
594+
595+ ` ` ` bash
596+ openmorph --input ./openapi --config config.yaml
597+ ` ` `
598+
599+ **Preview defaults changes:**
600+
601+ ` ` ` bash
602+ openmorph --input ./openapi --config config.yaml --dry-run
603+ ` ` `
604+
605+ **Combine with other transformations:**
606+
607+ ` ` ` bash
608+ openmorph --input ./openapi \
609+ --mapping x-operation-group-name=x-fern-sdk-group-name \
610+ --vendor-providers fern \
611+ --pagination-priority cursor,offset,none \
612+ --flatten-responses \
613+ --config config.yaml
614+ ` ` `
615+
616+ # ## Advanced Examples
617+
618+ **Complex object defaults:**
619+
620+ ` ` ` yaml
621+ default_values:
622+ enabled: true
623+ rules:
624+ settings_defaults:
625+ target:
626+ location: "component"
627+ condition:
628+ type: "object"
629+ property_name: "settings"
630+ template:
631+ theme: "light"
632+ notifications: true
633+ language: "en"
634+ priority: 4
635+ ` ` `
636+
637+ **Array response defaults:**
638+
639+ ` ` ` yaml
640+ default_values:
641+ enabled: true
642+ rules:
643+ array_defaults:
644+ target:
645+ location: "response"
646+ condition:
647+ type: "array"
648+ http_methods: ["get"]
649+ path_patterns: ["/api/v1/.*"]
650+ value: []
651+ priority: 5
652+ ` ` `
653+
654+ # ## Rule Priority and Ordering
655+
656+ Rules are processed in priority order (highest priority first), allowing you to :
657+
658+ 1. Set broad defaults with low priority
659+ 2. Override with specific defaults using higher priority
660+ 3. Ensure consistent application order across runs
661+
662+ ` ` ` yaml
663+ default_values:
664+ enabled: true
665+ rules:
666+ # Broad rule - low priority
667+ all_strings:
668+ condition:
669+ type: "string"
670+ value: "default"
671+ priority: 1
672+
673+ # Specific rule - high priority (overrides above)
674+ user_names:
675+ condition:
676+ type: "string"
677+ property_name: "name"
678+ value: "Anonymous"
679+ priority: 10
680+ ` ` `
681+
682+ # ## Best Practices
683+
684+ 1. **Use Regex Patterns** : Property name matching supports regex for flexible targeting
685+ 2. **Prioritize Rules** : Use priority to control application order
686+ 3. **Test with Dry-Run** : Always preview changes before applying
687+ 4. **Backup Files** : Enable backup for safe operations
688+ 5. **Combine Features** : Use alongside vendor extensions and other transformations
689+ 6. **Document Rules** : Use clear rule names and comments in config files
690+
691+ # ## Integration
692+
693+ The defaults feature integrates seamlessly with other OpenMorph features :
694+
695+ - **Vendor Extensions**: Applied before vendor extensions
696+ - **Response Flattening**: Works on original schemas before flattening
697+ - **Validation**: Validates resulting OpenAPI specs
698+ - **Interactive Mode**: Preview all changes together
699+ - **Backup**: Automatic backup before modifications
700+
488701# # Interactive TUI Controls
489702
490703- `j`/`k` or `left`/`right` : Navigate files
0 commit comments