Add support for external types and objc decorations#302
Open
yigit wants to merge 6 commits intopinterest:masterfrom
Open
Add support for external types and objc decorations#302yigit wants to merge 6 commits intopinterest:masterfrom
yigit wants to merge 6 commits intopinterest:masterfrom
Conversation
…ecorations similar to java decorations
RicoYao
reviewed
Nov 20, 2025
| "type": "object", | ||
| "properties": { | ||
| "name" : { "type": "string" }, | ||
| "externalType": { |
Contributor
There was a problem hiding this comment.
consider renaming to "myCustomClass"
RicoYao
reviewed
Nov 20, 2025
| case let .object(schemaRoot): | ||
| return [schemaRoot.className(with: self.params)] | ||
| if schemaRoot.external { | ||
| return [] |
Contributor
There was a problem hiding this comment.
add comment to indicate that we expect developer to use an import decoration
RicoYao
approved these changes
Nov 20, 2025
Contributor
RicoYao
left a comment
There was a problem hiding this comment.
Looks good for Android changes
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements ability to reference application classes from the schema.
A property of type
objectcan now reference an existing class in the codebase that will not be generated by plank but should still conform to the expected protocols.example usage:
When plank compiler finds
x-external:true, it will mark the SchemaObjectRoot as external, which will prevent it from trying to generate that model object. Anx-typenameis required, otherwise, it will fail code generation.On Java, it will just use the class as if it exists. Unless the class is not in the same package, it needs to be imported using the existing java_decorations feature.
java decorations file:
On ObjC, it will just use the class as if it exists. I've implemented ObjC decorations support, similar to Java, which allows specifying
swiftpackage imports that will be imported from the generated.mfile.objc decorations file:
This will generate:
In ObjC header, we also need to declare a forward reference for it, which is automatically added if there is a referenced external type. (each of these types are added to the
ObjCIR.Rootenumaration)Lists and Maps
I've not implemented support for external classes and list and map types. It requires a bit more logic when generating gson, hence skipped it for now. We still detect it and fail w/ an explicit error, in case someone tries to use it.
Examples Update
I've added decorated examples to demonstrate both x-external and decorations support. Added a test to the ObjC code to validate serialization-deserialization for the type with external data.
Other relevant but misc changes:
iOS External Class Requirements
External classes should implement the following protocols:
External classes should implement the following functions:
Android external class requirements
Custom android classes should register a GSON type adapter when deserializing.
They should also implement:
equals & hashcode