Comments (10)
There are quite a few JS form libraries (Angular, React, etc.) out there that work with JSON schema, e.g.:
https://github.com/mozilla-services/react-jsonschema-form
http://schemaform.io/
The basic idea would be that the client application asks for "application/schema+json" via accept header and gets the JSON schema back. Endpoints could be any content object in Plone. This can be used by the client applications to render the edit form.
An alternative would be to have a specific endpoint to ask for the schema. Though, I think the first solution is more elegant.
from plone.restapi.
I agree that the first solution has a certain elegancy to it, but how about the content-creation use case? If a client application wants to add some new content of type Foo
, it would need an endpoint to ask for the schema. And even if another object of that type already exists (which it might not), the client application would need to locate and ask a completely unrelated object for its type's schema, which is a pretty awkward way to go about things.
from plone.restapi.
@lukasgraf good point. Then I guess we need to decide if we want the first solution in addition to a "factory" endpoint.
from plone.restapi.
I'm gonna work on this subject for a customer project. I have to generate a JSONSchema from Dexterity content types so I can work on the mapping between the DX fields and the JSONSchema
from plone.restapi.
@cedricmessiant awesome! Would you mind starting with roughly outlining the endpoint design you have in mind? Do you plan to have a single endpoint for all portal type schemas (e.g. exposing the portal_types tool via REST)?
from plone.restapi.
@tisto I believe we might possibly need both. Both vocabulary factories and default value factories / default value adapters can be dynamic and context dependent.
I also did some work recently that relates to this - automatically generating Sphinx docs that describe the schemata used by our custom content types (so I can hand that to the customer that's going to use the API). It's currently a bit hackish and in a "works for our types" sort of state, but I'll contribute back what I can once I cleaned that up. @cedricmessiant I'll drop you a line the next couple days as soon as I pushed that code.
from plone.restapi.
What could get tricky here is Plone's (resp. DX and AT's) lack of clear separation between the data model, validation and forms. So much of validation and default value generation is tied into form logic.
E.g., the default value that is being chosen and proposed when a user adds a DX content type TTW is essentially determined in z3c.form.widget.Widget.update()
.
If that logic ends up looking for a default value adapter, that will be an adapter that adapts context, request, form, field and widget to IValue
, and could therefore potentially depend on all of those things.
Another thing that we might have to deal with at some point are the plone.autoform
directives: Fields can be omitted, reordered, grouped / moved into fieldsets, and have individual read / write permissions. I'm not sure how much of this will be relevant to us, but here's some pointers as to how it works:
Those form hints are stored on the schema interfaces as tagged values. TGV from an individual schema interface can be retrieved with iface.queryTaggedValue(KEY)
. But the fun bit is getting merged tagged values that consider interface inheritance and IRO. Both plone.autoform
and plone.supermodel
contain several helper functions that should be useful here.
from plone.restapi.
@tisto : My intuition is to use a single endpoint. Exposing the portal_types
tool may be useful e.g. to be able to retrieve the list of portal types via the restapi.
But first, I will focus on the adapters to map zope.schema
fields with jsonschema. I probably wont use the REST api in my application.
from plone.restapi.
It's done ! (See : dea48da )
from plone.restapi.
Done: #92
from plone.restapi.
Related Issues (20)
- CI Badge HOT 2
- Github Actions are skipped HOT 3
- Undeprecate comma separated expansion parameters HOT 8
- Undeprecate token parameter from vocabularies endpoint HOT 9
- Code that seems to do nothing HOT 2
- Drop Python 3.7 support HOT 1
- jwt_auth PAS plugin is active without being installed HOT 9
- Global Site tabs should also be customizable with customize_entry HOT 5
- navigation_base_url is not also used here HOT 2
- json_body should not read entire request BODY HOT 5
- debug-exceptions = on in instance part in buildout causes requests that return BadRequest to be returned as html instead of json
- KeyError: 'portal' in tests with Python 3.12.1 HOT 10
- Translate validation error messages
- IBlocks SearchableText indexer bypasses plone.textindexer behavior HOT 2
- relatedItems field returns None in the serializer if the related item is deleted HOT 1
- Site Administrator cannot add user to group
- Add remote_url(getRemoteUrl) to link content-types in navigation HOT 4
- Include release notes in Plone 6 Documentation
- Authentication error messages from PAS Plugins aren't returned by the restapi HOT 1
- restapi double parameter is broking code. HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plone.restapi.