Skip to content

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
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from 6b7aaea to 7f0039c Compare November 17, 2022 23:23
@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
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from 7f0039c to 2a1802d Compare December 23, 2022 16:16
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
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from 66adacc to 714c2e2 Compare October 10, 2023 19:52
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from c3611af to bf66b6f Compare April 13, 2024 10:18
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from 95fc12b to 031eb8d Compare April 15, 2024 21:17
@MathiusD MathiusD force-pushed the schemaCreationByInstance branch from 68a0382 to 662f4ff Compare April 22, 2024 19:52
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.

3 participants