Files
herolib/lib/schemas/jsonschema/custom.v
Mahmoud-Emad ba48ae255b refactor: Update example generation and schema handling
- Remove unused `generate_example_call` and `generate_example_response` functions
- Rename `example_call` to `example_request` in `DocMethod`
- Update schema example extraction to use `schema.example` directly
- Introduce `generate_request_example` and `generate_response_example` for dynamic example generation
- Change type of `id` from string to number in schema examples

PS: The work is still in progress
2025-09-22 14:58:22 +03:00

37 lines
1.3 KiB
V

module jsonschema
pub fn (schema Schema) type_() string {
return schema.typ.str()
}
// // example_value generates a basic example value based on the schema type.
// // Returns a JSON-formatted string appropriate for the schema type.
// pub fn (schema Schema) example_value[T](model T) T {
// obj := T{}
// return obj
// // // Check if schema has an explicit example value (ignore empty arrays which indicate no example)
// // example_str := schema.example.str()
// // println('example_str: ${example_str}')
// // if example_str != '' && example_str != '[]' {
// // // For object examples, return the JSON string as-is
// // if schema.typ == 'object' || example_str.starts_with('{') {
// // return example_str
// // }
// // // For string types, ensure proper JSON formatting with quotes
// // if schema.typ == 'string' && !example_str.starts_with('"') {
// // return '"${example_str}"'
// // }
// // return example_str
// // }
// // // Generate type-based example when no explicit example is provided
// // match schema.typ {
// // 'string' { return '"example_value"' }
// // 'integer', 'number' { return '42' }
// // 'boolean' { return 'true' }
// // 'array' { return '[]' }
// // 'object' { return '{}' }
// // else { return '"example_value"' }
// // }
// }