Open vladlaba opened 5 years ago
This discussed in #663 as well - clearly the framework needs to provide a solution. I am not sure what it is yet.
One option is to override your ManagedObject
subclass' documentSchema
method (this impacts every endpoint that exposes User
).
class User extends ManagedObject<_User>
implements _User, ManagedAuthResourceOwner<_User> {
@override
APISchemaObject documentSchema(APIDocumentContext context) {
final object = super.documentSchema(context);
object.properties["role"] = context.schema.getObjectWithType(RoleType)
return object;
}
}
The missing piece appears to be an easy-to-use, endpoint-specific adjustment of a schema object. There's two things to think about - how should this modified object appear in the OpenAPI doc and what is the Dart API for that modification?
For the OpenAPI doc, would it make sense for there to be a schema component for each permutation? That is, you will end up with a User
schema component and a UserWithRole
schema component. Is there a better way than this and/or will this generate decent client code?
For the Dart API in Aqueduct - sounds like having a cloning method for schema objects would be helpful? I've also wondered if the documentOperationResponses
method is too cumbersome - and if there is a better way there?
Hi Aqueduct team,
I have a User ManagedObject that relates to the RoleType one (belongs-to):
And I have an endpoint that responses with User:
Here is endpoint response where Role has all fields populated.
After running
aqueduct document
the schema for the User object does not contain reference to the RoleType one. Instead, the 'role' field contains the object with 'id' only:I wonder is it possible to document the User in such way that the result of document generation will contain the User with 'role' field as a reference to the RoleType scheme?
There is a possible workaround for this situation - we can override
documentComponents
method for our application channel and register User with fields we want:But this approach is seemed to be complicated especially if we have a lot of endpoints that need to be handled in such way.