Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Swagger Object creation #26

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

MathiusD
Copy link

@MathiusD MathiusD commented Nov 17, 2022

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", "icyleaf.cn@gmail.com", "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.

@trafico-bot trafico-bot bot added the 🔍 Ready for Review Pull Request is not reviewed yet label Nov 17, 2022
@icyleaf
Copy link
Owner

icyleaf commented Nov 18, 2022

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.

@MathiusD
Copy link
Author

MathiusD commented Nov 18, 2022

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:

  • Manage classes and enums by reusing references (Cf Property ref #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.

erdnaxeli and others added 2 commits December 19, 2022 12:17
Add creation of Swagger::Object by some object instance

(Related to icyleaf#18)
@MathiusD MathiusD marked this pull request as draft December 23, 2022 13:06
Add management of enumeration
Add support of enumeration inside creation by instance of Swagger::Object
Add refs for other Swagger::Object for non primitive type in creation by instance

(Related to icyleaf#18)

TODO : add spec for enumeration addition
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch 2 times, most recently from 9e739f3 to 66adacc Compare October 10, 2023 19:19
… directive when instance name is retrieved from class name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 Ready for Review Pull Request is not reviewed yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants