I have created an Aurelius entity via the Data-Modeler. In this entity there is a creation date field. I want this field to be retrievable via GET, but I don't want it to be modified via POST or PATCH. I can't see any "read-only" possibility.
I know that I cannot change the Column attribute via the Data-Modeler. (TColumnProp.NoInsert, TColumnProp.NoUpdate)
So how can I prevent this field from being changed? It would also be best not to display it at all in SwaggerUI.
The same for the ID field. It is an mariadb autoincrement field which must not be filled when creating. But it is displayed in SwaggerUI at POST.
You can do that via customization scripts. Example:
procedure OnColumnGenerated(Args: TColumnGeneratedArgs);
if Args.DBField.FieldName = 'CreationDate' then
TCodeSnippetExpression(Args.ColumnAttr.Arguments.Value).Value := '[TColumnProp.NoUpdate]';
If you want different DTOs (classes) for different endpoints, then in this case you need to effectively create different DTO classes for each endpoint.
Thanks for the Script. That helps.
I dont "want" different Classes. I try to create a Simple API for our customers to read and write to our Database.
Theres a ID (autoincrement), some String fields and a CreationDate.
SwaggerUI shows me GET, POST, PUT, PATCH. For GET its ok. For POST its misleading. The api user must not specify the id and date.
So do I really have to create 2 classes for this?
/api/Entity (for GET)
/api/PostEntity (without ID and Date for Post)
As I said, they are different classes from the point of view of your user. You don't want and don't accept them to be the same (i.e., have ID and CreationDate properties). Then effectively they end up being different ones and then you need to declare different ones, with different properties.