Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array type relations and components are always generated as mandatory #45

Open
weidox opened this issue Nov 12, 2021 · 5 comments
Open

Comments

@weidox
Copy link

weidox commented Nov 12, 2021

Array type relations and components are always generated as mandatory, irrespective if they're marked as required or not.

@aperron
Copy link
Collaborator

aperron commented Nov 19, 2021

have you tried the option -u collectionCanBeUndefined ?

@weidox
Copy link
Author

weidox commented Nov 19, 2021

Missed this configuration option. It's a pretty tricky thing, as by the way it's generated by default, optional/mandatory is following response structure (where id and array collections are always non-nullish), but when making a POST/PUT request, id has to not exist and array collections then need to follow required flag. So I think the current behavior is right and I gave a false alarm.

The collectionCanBeUndefined flag documentation seems to be wrong, it says about all collections, but I think it should say only about array collections, as now only array collections are generated as mandatory by default (which is correct behavior and should stay as is). And beyond that, I don't see uses of that flag, as if targeting for POST/PUT request, it would make array collections optional, but id would still stay mandatory.

@aperron
Copy link
Collaborator

aperron commented Nov 19, 2021

just for information, the only use of this flag in the base code:
const required = !a.required && !(!this.config.collectionCanBeUndefined && (a.collection || a.repeatable)) && a.type !== 'dynamiczone' ? '?' : '';

@weidox
Copy link
Author

weidox commented Nov 19, 2021

a.collection || a.repeatable - this seems to be a double bug, because it looks like it tries to generate mandatory fields for all collections and repeatables (a bug in what it is trying to do), but it happens only for repeatables (a bug again, as what it tries does not happen), and double bug resolves to correct behavior. Mandatory should be generated only for repeatables, as only for repeatables (arrays) Strapi is automatically adding empty brackets in responses.

@aperron
Copy link
Collaborator

aperron commented Nov 19, 2021

It's not clear to me but it doesn't really matter. I no longer actively use Strapi, so if you have a fix, which does not change the current behavior, maybe with new options, feel free to create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants