|
33 | 33 | }) |
34 | 34 | end |
35 | 35 |
|
| 36 | + it "converts a schema with meta description/desc" do |
| 37 | + schema = Verse::Schema.define do |
| 38 | + field(:title, String).meta(description: "The title of the item") |
| 39 | + field(:count, Integer).meta(desc: "The count of items") |
| 40 | + end |
| 41 | + |
| 42 | + json_schema = described_class.from(schema) |
| 43 | + expect(json_schema).to eq({ |
| 44 | + type: "object", |
| 45 | + properties: { |
| 46 | + title: { |
| 47 | + type: "string", |
| 48 | + description: "The title of the item" |
| 49 | + }, |
| 50 | + count: { |
| 51 | + type: "integer", |
| 52 | + description: "The count of items" |
| 53 | + } |
| 54 | + }, |
| 55 | + required: [:title, :count], |
| 56 | + additionalProperties: false |
| 57 | + }) |
| 58 | + end |
| 59 | + |
36 | 60 | it "converts a schema with nested structs" do |
37 | 61 | schema = Verse::Schema.define do |
38 | 62 | field(:user) do |
|
288 | 312 | }) |
289 | 313 | end |
290 | 314 |
|
| 315 | + it "converts a hash schema" do |
| 316 | + schema = Verse::Schema.define do |
| 317 | + field(:settings, Hash) |
| 318 | + end |
| 319 | + |
| 320 | + json_schema = described_class.from(schema) |
| 321 | + expect(json_schema).to eq({ |
| 322 | + type: "object", |
| 323 | + properties: { |
| 324 | + settings: { type: "object" } |
| 325 | + }, |
| 326 | + required: [:settings], |
| 327 | + additionalProperties: false |
| 328 | + }) |
| 329 | + end |
| 330 | + |
| 331 | + it "converts an IO/Tempfile schema" do |
| 332 | + schema = Verse::Schema.define do |
| 333 | + field(:file, IO) |
| 334 | + field(:tempfile, Tempfile) |
| 335 | + end |
| 336 | + |
| 337 | + json_schema = described_class.from(schema) |
| 338 | + expect(json_schema).to eq({ |
| 339 | + type: "object", |
| 340 | + properties: { |
| 341 | + file: { |
| 342 | + type: "object", |
| 343 | + instanceof: "IO", |
| 344 | + description: "A native IO stream or file pointer" |
| 345 | + }, |
| 346 | + tempfile: { |
| 347 | + type: "object", |
| 348 | + instanceof: "IO", |
| 349 | + description: "A native IO stream or file pointer" |
| 350 | + } |
| 351 | + }, |
| 352 | + required: [:file, :tempfile], |
| 353 | + additionalProperties: false |
| 354 | + }) |
| 355 | + end |
| 356 | + |
291 | 357 | it "converts a custom schema" do |
292 | 358 | class CustomSchemaType |
293 | 359 | def to_json_schema |
|
0 commit comments