Support automatically generating Identifiable conformance on entities#61
Support automatically generating Identifiable conformance on entities#61liamnichols merged 12 commits intoCreateAPI:mainCreateAPI/CreateAPI:mainfrom LePips:add-identifiable-if-availableLePips/CreateAPI:add-identifiable-if-availableCopy head branch name to clipboard
Identifiable conformance on entities#61Conversation
liamnichols
left a comment
There was a problem hiding this comment.
Awesome! Thanks for the contribution @LePips!
Identifiable is only available on iOS 13+ and while we don't officially state which OS version we try and maintain compatibility with, I know that some people use CreateAPI while still supporting iOS 12 (me 😬).
I think putting this behind a flag is a good approach! Are you able to give that a go?
Secondly, we'll want to make sure that this change is covered in some of our test fixtures so that nobody mistakenly breaks your change in the future 🙏 This process isn't very well documented at the moment, but either adapting an existing test or adding a new one to GenerateOptionsTests.swift should do the trick.
You'll need to temporarily update the projectPath in Snapshots.swift and add a GENERATE_SNAPSHOTS environment variable that is set to true for it to update the expected fixtures. Let me know if you get stuck, I know its not the smoothest process at the moment 👍
|
Oops, didn't think about the iOS versions. Thanks for the comment! I'll get on the tests. |
|
Just one more thought, if somebody used the rename:
properties:
User.user_id: id
identifier: idWould we be able to pick this up and annotate I ask because I am not too familiar where the renaming takes place so we might need to adjust how we check? |
|
It will indeed attach |
Identifiable conformance on entities
|
Thanks for showing me the ropes! |
Co-authored-by: Liam Nichols <liam.nichols.ln@gmail.com>
| } | ||
|
|
||
| private func getProtocols(for type: TypeName, context: Context) -> Protocols { | ||
| private func getProtocols(for entity: EntityDeclaration, context: Context) -> Protocols { |
There was a problem hiding this comment.
I just went ahead and will pass in the entire entity, mainly because I think we will have to check the nested types for Hashable declaration. I will take a look at that next and if not, I will change to just passing the properties there.
| entity.protocols = { | ||
| var protocols = getProtocols(for: name, context: context) | ||
| var protocols = getProtocols(for: entity, context: context) | ||
| let hashable = Set(["String", "Bool", "URL", "Int", "Double"]) // TODO: Add support for more types |
There was a problem hiding this comment.
These will be removed when getting to Hashable
liamnichols
left a comment
There was a problem hiding this comment.
Good job! Looking great! Just one more thing to get the tests passing again and then I think that its good to go 🚀
|
Sorry this PR has taken a bit of back and forth, I'm really appreciative of it and showing me how things should be done around here. I'll get the hang of it soon. This project is great! We're going to be moving from OpenAPI after a few things are done. |
liamnichols
left a comment
There was a problem hiding this comment.
Sorry this PR has taken a bit of back and forth, I'm really appreciative of it and showing me how things should be done around here. I'll get the hang of it soon. This project is great! We're going to be moving from OpenAPI after a few things are done.
No, thank you for taking the time to work on this! Your contribution is very valuable and it's good that we get to work though this 🙇
I think we just need to revert that change still (reasoning inline) but then this is good to go 🎉
Thanks again!
Tests/CreateAPITests/Expected/petstore-no-package/Entities.swift
Outdated
Show resolved
Hide resolved
This reverts commit 40c340e.
liamnichols
left a comment
There was a problem hiding this comment.
Great work on this! Everything looks good to me 🚀
I might work on the documentation improvements over the weekend and then get a release out after that. But if you want this in a tagged release before then, let me know!

As getting comfortable with the project, generate
Identifiableif available on the entity.I initially had
Hashableas well however that should be behind some config option because only structs have automatic conformance. I think all built in types can be statically listed and that hashable list is of course a subset of that list. SinceHashablewould be desired in bothmakeOneOfand 'makeObject', for the future:If this needs to be behind a config flag, I'm okay to do that.