-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Common response/payload object but different data defined per API? #773
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
Comments
If I understand right, you want support for generic data types. A related issue I found is #519. |
@ePaul , yes sort of. I want to be able to define a data type that's generic - like a "response" that has basic fields but I want to be able to further define that content for each API (data containing permissions or roles or whatever). |
will this to be supported in future? |
I am evaluating this as a possible use case for overlays, OAI/Overlay-Specification#9. I don't think overlays are needed here. I believe this can be represented in openapi3 as example (I did not test this) {
"openapi": "3.0.1",
"info": {
"title": "API",
"version": "1.0"
},
"paths": {
"/permissions": {
"get": {
"description": "Returns all permissions",
"operationId": "getPermissions",
"responses": {
"200": {
"description": "success",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/permissionResponse"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"permissionResponse": {
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "A string indicating the response from the server."
},
"totalElements": {
"type": "integer",
"description": "The number of items retrieved.",
"format": "int64"
},
"status": {
"type": "string",
"description": "A string indicating the response from the server."
},
"data": {
"type": "array",
"description": "The collection of items returned from the API request.",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/permission",
},
{
"$ref": "#/components/schemas/role"
}
]
}
}
}
},
"role": {
"type": "object",
"properties": {
"roleName": {
"type": "string"
},
"description": {
"type": "string"
}
}
},
"permission": {
"required": [
"active",
"description",
"id",
"label"
],
"type": "object",
"properties": {
"id": {
"type": "integer",
"description": "Unique identifier representing a specific permission.",
"format": "int64"
},
"label": {
"type": "string",
"description": "The label of a permission."
},
"description": {
"type": "string",
"description": "A description of the permission."
},
"active": {
"type": "boolean",
"description": "A flag indicating whether a permission is active."
}
}
}
}
}
} which looks like this at editor.swagger.io |
This has been supported in OAS 3.1 by using dynamic references to implement generic types. |
What is the best way to represent a generic response/payload object that has basic fields such as message, total elements, data, and status? Where the variability between each API is the data element. For instance, one API could be for permissions, so the data element would hold an array of permissions. But for another API, it would hold a different array of object types. My main goal is to have reuse with a payload object and to define the next "layer" of actual data.
Here are some JSON samples of what's been attempted but isn't rendering the way we would expect it to in Swagger UI (i.e. a flat structure of 4 elements with data defined per the API).
Example 1 - composition:
Example 2 - composition variation:
Example 3 - additional properties:
The text was updated successfully, but these errors were encountered: