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

Overhaul JSON schema generation for @types endpoint #237

Merged
merged 1 commit into from
Mar 5, 2017
Merged

Conversation

lukasgraf
Copy link
Member

@lukasgraf lukasgraf commented Mar 4, 2017

This new implementation instantiates a minimal z3c.form in order to allow plone.autoform to do all the heavy lifting (particularly processing fields, fieldset directives and field move directives).

This makes sure we correctly process and respect (or at least have the option to respect):

  • Schema interface inheritance (IRO)
  • Additional schemata from behaviors
  • plone.autoform directives / form hints:
    • Fieldsets
    • Field moves
    • Omitted fields
    • Field modes
    • Field level permissions

Basically all the heavy lifting is done in (or triggered from) plone.autoform.base.AutoFields. updateFieldsFromSchemata()

So instead of attempting to do these complex tasks ourselves in plone.restapi like in the previous implementation, I instantiate a minimal z3c.form inheriting from AutoExtensibleForm (and therefore indirectly from AutoFields), and make sure form.updateFieldsFromSchemata() gets called on it.

TODO:

  • Extend tests with some schema interface inheritance testcases
  • Extend docs for @types endpoint

This also brought to the surface another issue / aspect: If we're talking about schemas with the purpose of rendering a specific form, we'll need to tell the implementation that produces the JSON schema which form this is gonna be. Different fields can be omitted / hidden / ... for edit forms than for add forms. For now I went with defaulting to delivering a schema appropriate for an add form, but I plan to further extend this implementation to support different form modes as well.

@lukasgraf lukasgraf changed the title Overhaul JSON schema generation for @types endpoint: Overhaul JSON schema generation for @types endpoint Mar 4, 2017
@lukasgraf
Copy link
Member Author

@davisagli I'd love your 2 cents on whether or not this approach is sensible.

Instantiating a minimal z3c.form with the appropriate schema and additionalSchemata, and then calling form.updateFieldsFromSchemata() on it seems to work. In particular, theres two things I'm unsure about:

  • Is there any state that form.updateFieldsFromSchemata() relies on, in the sense that some other form initialization should happen before it's called?
  • Could there be any side effects to request (or possibly context) from invoking this method?

@davisagli
Copy link
Sponsor Member

@lukasgraf I think that approach will work, and it seems like a good way to make sure that fields are processed the same as for a server-rendered form.

@lukasgraf lukasgraf force-pushed the tgv-fieldsets branch 2 times, most recently from 298e028 to 6416656 Compare March 4, 2017 21:41
This new implementation instantiates a minimal z3c.form in
order to allow plone.autoform to do all the field processing.

This makes sure we correctly process and respect (or at least
have the option to respect):

- Schema interface inheritance (IRO)
- Additional schemata from behaviors
- plone.autoform directives:
  - Fieldsets
  - Field moves
  - Omitted fields
  - Field modes
  - Field level permissions
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

Successfully merging this pull request may close these issues.

None yet

4 participants