kontent-ai / model-generator-js

MIT License
13 stars 9 forks source link

Add Subpages to generated page and homepage models #27

Closed macdermott closed 2 years ago

macdermott commented 2 years ago

Motivation

Generated models for pages and the homepage do not explicitly reference subpages

Proposed solution

Subpages of a model can be accessed via model.subpages

Additional context

I know that subpages can currently be accessed via linkedItems, but explicitly separating out subpages helps when trying to build a hierarchical structure in a site generator

Enngage commented 2 years ago

@macdermott,

Thank you for the issue! If I understand it correctly, you are proposing a change of the actual underlying model defined by the Delivery SDK (https://github.com/kontent-ai/delivery-sdk-js) which would 'separate' subpages elements from the 'elements' section to its own property?

macdermott commented 2 years ago

Yes, that is correct. Ideally the models generated would separate out elements and subpages and the delivery SDK would be modified accordingly

Freekbron commented 2 years ago

I've got the same issue. I don't think the delivery SDK needs modification. It would make sense when subpages are part of the model under elements.

My Homepage 'Content model' has:

The generated file: export type Homepage = IContentItem only has:

Enngage commented 2 years ago

I've added the support for subpages element to the generator and released it under 5.4.0.

We are not planning on modifying the Delivery model to separate the subpages elements completely as it would bring inconsistency between other SDKs and elements. It should be fairly easy to programmatically find the subpages element by filtering based on the type.

Freekbron commented 2 years ago

Hi @Enngage, thanks for the quick response!

Now I get the following error:

Cannot find name 'Page'.
 * Codename: subpages
 */
subpages: Elements.LinkedItemsElement<Page>;

It seems like the types in subpages (e.g. 'Page') are not imported as modules.

Enngage commented 2 years ago

@Freekbron, oh, you're right, sorry :) I've released a fix for that.

Freekbron commented 2 years ago

@Enngage Thanks, all working now!