swagger
swagger copied to clipboard
Improve Swagger Object creation
Add creation of Swagger::Object by some object instance
(Related and insipred by #18)
Allow creation of Swagger::Object by something like that :
struct User
property id, nickname, username, email, bio
def initialize(@id : String, @nickname : String, @username : String, @email : String, @bio : String? = nil)
end
end
user = User.new(
UUID.random.to_s, "icyleaf wang", "icyleaf", "[email protected]", "Personal bio"
)
builder.add(Swagger::Object.create_from_instance(user))
P.S. : src/swagger/http/handler.cr
was modified when the code formatting was executed via crystal tool format src && crystal tool format spec
. I have therefore committed the formatting.
Thanks for the PR, I reviewed the code that the current implementation only contains the base type, so if there are complex types or nested variables such an implementation would be exceptionally complicated, my suggestion is to see if Crystal implements reflection natively.
Thanks for the PR, I reviewed the code that the current implementation only contains the base type, so if there are complex types or nested variables such an implementation would be exceptionally complicated, my suggestion is to see if Crystal implements reflection natively.
Indeed, I should have put this PR in Draft. I still have to do the following:
- [x] Manage classes and enums by reusing references (Cf #24)
- [ ] Add spec for enums addition
- [ ] Add the missing primitive types
- [ ] Add date
- [ ] Add date-time
- [ ] Add byte
- [ ] Add binary
- [ ] Add password ?
However I don't understand how the implementation would be harder without native reflection, indeed, for schemas the open-api spec the other schema and enums are pointed by reference. (In addition reflection made here via macros allows to get all the necessary information, in my opinion)
The only point which seems to me to pose problem intuitively is the management of the Union other than SomeClass? since we could not use it in the same way.