Search code examples
apiblueprint

Given an API blueprint resource model, how can I ensure that the readonly part of a resource is not updatable?


I have a large model which I am using for both GET and PUT on a resource. The model includes an "audit" object like so:

            "audit": {
                "createdAt": "2014-04-14T02:15:15Z",
                "lastUpdatedAt": "2014-04-14T02:15:15Z",
                "deletedAt": ""
            }

This is obviously a readonly part of the resource - is there any way to show this in the contract model so "audit" appears for the GET response representation but not the PUT request representation?

The only alternative I can see is to copy the model into the body of the PUT and remove the readonly parts - but that then eliminates the benefit of having a single model that is reusable across different methods.


Solution

  • This is not possible yet. Capabilities of current resource model are very limited. It's similar issue as Apiary: Refer to multiple models in a body or Reuse a resource model as an array.

    There are plans to address this need and make blueprints more DRY in the future - See the Embedded Assets and Traits milestones.

    Solution is to either copy & paste, or, in your particular case, not to return different payloads in GET and PUT. Why are you doing it?