Code Monkey home page Code Monkey logo

Comments (2)

woshimaliang avatar woshimaliang commented on June 8, 2024 2

Thanks @rahul-malik! Very good points.

#1, yep, either subset of or full json-schema spec is a good idea;
#2, I don't think we need inheritance in Plank at all. JSON is not primarily designed for that. I like the idea of flattening properties, as that's what allOf is supposed to do: look up properties till root and flatten them.

allOf is slightly different than extends, which will be flatten and is useful for in abstracting common data without a base class or protocol.

Also, I may misunderstood and i don't think polymorphicTypeIdentifier /ADT has to do with extends or allOf. I thought it is a solution to union(doesn't seem to be valid keyword in json-schema) or oneOf. I don't have strong opinion around that and I think they should continue to work after flattened.

Yeah, migration is always the most difficult part. Usually NSObject should be good enough unless their codebase replies on properties of base class like we do (PIModel 😄 ). I like the idea of generating protocol for extended type but:

  1. that might be overhead in code generating if there're many immediate protocols. Unlikely in real word though.
  2. once we support that, we can't get rid of that.

Having said that, this seems to be the best path moving forward. To summarize:

  • Support allOfkeyword
  • Add build option to treat extends as allOf and also generate protocol for extended type
  • Deprecate methods in generated protocols to expedite migration
  • Remove 'extends` support from Plank, also the build option.

I've not looked into source code or java implementation yet. I am more than happy to spend some time on this. Very interesting stuff!

from plank.

rahul-malik avatar rahul-malik commented on June 8, 2024

I think there are two distinct points here:

  • The extends keyword is not documented in JSON Schema making Plank divergent from the open specification. Should this be changed and should we enforce its aligned with the open specification?

Plank occasionally has taken liberties with the schema syntax to make our migration to immutable models earlier. The extends keyword was added as well as a few others like polymorphicTypeIdentifier to support ADT types. I don't have a strong opinion around switching to allOf but it likely will open it up to more of a mix-in style schema where you could "inherit" from multiple types which can be powerful but also will change how we consider code generation.

Additionally, there are missing attributes of JSON schema outside of allOfand we should figure out if we should attempt to support these as well. Alternatively, we could also use JSON schema to write a schema definition for what Plank accepts which could be another path forward here.

  • How should code generation handle cases like allOf or extends? Should inheritance be supported at all or should we migrate towards composing models?

The ObjC generation is the only one I'm aware of that actually uses inheritance. The Java output from what I remember actually flattens the inherited set of properties and I think we can do the same on the ObjC side. We should consider generating protocols for the specific properties on each type (unflattened) though to allow for APIs to be migrated where they specified a base class type.

from plank.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.