|
1 | 1 | require "../spec_helper" |
| 2 | +struct Project |
| 3 | + property id, name, description, vcs, open_source |
| 4 | + |
| 5 | + def initialize(@id : Int32, @name : String, @vcs : String, @open_source : Bool, @description : String? = nil) |
| 6 | + end |
| 7 | +end |
2 | 8 |
|
3 | 9 | describe Swagger::Object do |
4 | 10 | describe "#new" do |
@@ -41,5 +47,24 @@ describe Swagger::Object do |
41 | 47 | raw.properties.should be_nil |
42 | 48 | raw.items.should eq("Comment") |
43 | 49 | end |
| 50 | + |
| 51 | + it "should generate schema of object from object instance" do |
| 52 | + raw = Swagger::Object.create_from_instance( |
| 53 | + Project.new(1, "swagger", "git", true, "Swagger contains a OpenAPI / Swagger universal documentation generator and HTTP server handler.") |
| 54 | + ) |
| 55 | + raw.name.should eq "Project" |
| 56 | + raw.type.should eq "object" |
| 57 | + raw.properties.should eq [ |
| 58 | + Swagger::Property.new("id", "integer", "int32", example: 1, required: true), |
| 59 | + Swagger::Property.new("name", example: "swagger", required: true), |
| 60 | + Swagger::Property.new("vcs", example: "git", required: true), |
| 61 | + Swagger::Property.new("open_source", "boolean", example: true, required: true), |
| 62 | + Swagger::Property.new( |
| 63 | + "description", |
| 64 | + example: "Swagger contains a OpenAPI / Swagger universal documentation generator and HTTP server handler.", |
| 65 | + required: false |
| 66 | + ), |
| 67 | + ] |
| 68 | + end |
44 | 69 | end |
45 | 70 | end |
0 commit comments