forked from icyleaf/swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(swagger-object) : Improve object creation
Add creation of Swagger::Object by some object instance (Related to icyleaf#18)
- Loading branch information
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Utils | ||
struct SwaggerDataType | ||
property type : String | ||
property format : String? | ||
|
||
def initialize(@type : String, @format : String?) | ||
end | ||
|
||
def self.create_from_class(type : T.class) forall T | ||
{% begin %} | ||
{% if T.union? %} | ||
return self.create_from_class({{ T.union_types.find { |var| var != Nil } }}) | ||
{% else %} | ||
# Cf https://swagger.io/specification/#data-types | ||
{% if T <= String || T <= Nil %} | ||
swagger_type = "string" | ||
swagger_format = nil | ||
{% elsif T <= Int %} | ||
swagger_type = "integer" | ||
{% if T <= Int32 %} | ||
swagger_format = "int32" | ||
{% elsif T <= Int64 %} | ||
swagger_format = "int64" | ||
{% else %} | ||
swagger_format = nil | ||
{% end %} | ||
{% elsif T <= Number %} | ||
swagger_type = "number" | ||
{% if T <= Float32 %} | ||
swagger_format = "float" | ||
{% elsif T <= Float64 %} | ||
swagger_format = "double" | ||
{% else %} | ||
swagger_format = nil | ||
{% end %} | ||
{% elsif T <= Bool %} | ||
swagger_type = "boolean" | ||
swagger_format = nil | ||
{% else %} | ||
swagger_type = {{ T.stringify }} | ||
swagger_format = nil | ||
{% end %} | ||
return self.new(swagger_type, swagger_format) | ||
{% end %} | ||
{% end %} | ||
end | ||
end | ||
end |