Before asking the question:
- [X] have you checked the faq, the documentation in the docs folder and couldn't find the information there
- [X] have you checked existing issues for a similar question?
I would like to add APIs for creating, reading, and updating an "Item".
We would like to use the same contract (definition) of "Item" for the API responses, as well as the body payload in the create and update requests.
The contract, however, has properties that cannot be modified (e.g., "ID"), as well as properties that should only be returned in responses, while others may be set or modified during instantiation (which depends on the type of request).
There were several combinations that I tried, including "x-ms-mutability" which sounded promising, but the results weren't as expected.
Is there any way to accomplish our goal? Are there any ways to control the visibility of a property based on a condition? Do you have any recommendations for how we can get the expected behavior?
I would appreciate your input.
Below is a swagger file sample that illustrates the situation:
{
"swagger": "2.0",
"info": {
"title": "example",
"version": "example"
},
"basePath": "/something",
"host": "myhost.com",
"paths": {
"/items": {
"post": {
"operationId": "CreateItem",
"parameters": [
{
"in": "body",
"name": "newItem",
"schema": {
"$ref": "#/definitions/Item"
}
}
],
"responses": {
"200": {
"description": "Successfuly created.",
"schema": {
"$ref": "#/definitions/Item"
}
}
}
},
"patch": {
"operationId": "UpdateItem",
"parameters": [
{
"in": "body",
"name": "updatemItem",
"schema": {
"$ref": "#/definitions/Item"
}
}
],
"responses": {
"200": {
"description": "Successfuly updated.",
"schema": {
"$ref": "#/definitions/Item"
}
}
}
}
},
"/items/{itemId}": {
"get": {
"operationId": "GetItem",
"parameters": [
{
"in": "path",
"name": "itemId"
}
],
"responses": {
"200": {
"description": "Successfuly fetched.",
"schema": {
"$ref": "#/definitions/Item"
}
}
}
}
}
},
"definitions": {
"Item": {
"type": "object",
"properties": {
"Read only property - returned in response only": {
"type": "string",
"description": "read only - returned in responses only"
},
"writable property - can be set in creation/update. returned in response": {
"type": "string",
"description": "writable. can be set in create/update and returned in responses"
},
"writable property - can be set only for update (e.g., state). returned in response": {
"type": "number",
"description": "only for update. returned in responses"
}
}
}
}
}
question needs-author-feedback no-recent-activity