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

Partial update for subproperties of object property #341

Open
morrisson opened this issue Dec 20, 2016 · 0 comments
Open

Partial update for subproperties of object property #341

morrisson opened this issue Dec 20, 2016 · 0 comments
Labels

Comments

@morrisson
Copy link
Contributor

Gohan allows to update a part of resource with PUT API. However, update of subproperty of object property results in replace with the object. For example,

Sample Schema

schemas:
- id: simple
  description: simple resource
  singular: simple
  plural: simples
  prefix: /v1.0
  schema:
    properties:
      id:
        description: The ID of the resource
        title: ID
        type: string
        format: uuid
        permission:
        - create
        view:
        - detail
      name:
        description: The name of the resource
        title: Name
        type: string
        permission:
        - create
        - update
      info:
        description: The detail info
        title: Info
        type: object
        permission:
        - create
        - update
        properties:
          address:
            type: string
            title: Address
          tel:
            type: string
            title: Telephone Number
      tenant_id:
        description: The Tenant ID
        title: Tenant ID
        type: string
        permission:
        - create
        view:
        - detail
    propertiesOrder:
    - id
    - name
    - info
    - tenant_id
    type: object
  title: Simple

Sample Use Case

Create data as follows:

curl -X POST -H "X-Auth-Token: <token>" http://localhost:9091/simples -d '{"id": "google", "name": "Google", "info": {"address": "160 Amphitheatre Pkwy, Mountain View, CA 94043", "tel": "(650) 253-0000"}}'

Then, data will be

+--------+--------+----------------------------------------------------------------------------------------+
| id     | name   | info 
+--------+--------+----------------------------------------------------------------------------------------+
| google | Google | {"address": "160 Amphitheatre Pkwy, Mountain View, CA 94043", "tel": "(650) 253-0000"} | 
+--------+--------+----------------------------------------------------------------------------------------+

However, real address is wrong, so user tried to modify 'only' address by:

curl -X PUT -H "X-Auth-Token: <token>" http://localhost:9091/simples/google -d '{"name": "Google", "info": {"address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043"}}'

Then, data will unfortunately lose 'tel' info.

+--------+--------+----------------------------------------------------------------+
| id     | name   | info 
+--------+--------+----------------------------------------------------------------+
| google | Google | {"address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043"} | 
+--------+--------+----------------------------------------------------------------+

Of course, one workaround is bringing all properties to '1st level'. However, sometimes this workaround becomes unreasonable from the viewpoint of schema architecture.

@morrisson morrisson assigned morrisson and unassigned morrisson Dec 20, 2016
@morrisson morrisson added the bug label Dec 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant