ReadOnly attributes appearing in POST swagger

Hi, I'm new to XData so trying to get the basics. I have defined the following entities but have an issue in that I want the Id and the CreatedAtDateTime to be readOnly, so they appear in the GET's Response but not in the Body for the POST/PUT in the swagger. Is there an easy way to do this please?

unit uPartyModel;

interface

uses
  SysUtils,
  Generics.Collections,
  Aurelius.Mapping.Attributes,
  Aurelius.Types.Blob,
  Aurelius.Types.DynamicProperties,
  Aurelius.Types.Nullable,
  Aurelius.Types.Proxy,
  Aurelius.Dictionary.Classes,
  XData.Service.Common,
  XData.Model.Attributes,
  System.DateUtils;

type
  TParty = class;

  [Entity]
  [UriPath('parties')]
  [Table('PARTY')]
  [id('FId', TIdGenerator.Uuid36)]
  TParty = class
  private
    [Column('ID', [TColumnProp.Required, TColumnProp.Unique , TColumnProp.NoUpdate], 36)]
    FId: string;

    [Column('FIRST_NAME', [TColumnProp.Required], 100)]
    FFirstName: string;

    [Column('LAST_NAME', [TColumnProp.Required], 100)]
    FLastName: string;

    [Column('MOBILE', [], 20)]
    FMobile: Nullable<string>;

    [Column('LANDLINE', [], 20)]
    FLandline: Nullable<string>;

    [Column('EMAIL_ADDRESS', [], 100)]
    FEmailAddress: Nullable<string>;

    [Column('CREATED_AT_DATETIME', [TColumnProp.Required, TColumnProp.NoUpdate])]
    FCreatedAtDateTime: TDateTime;
  public
    property Id: string read FId; //write FId;
    property FirstName: string read FFirstName write FFirstName;
    property LastName: string read FLastName write FLastName;
    property Mobile: Nullable<string> read FMobile write FMobile;
    property Landline: Nullable<string> read FLandline write FLandline;
    property EmailAddress: Nullable<string> read FEmailAddress write FEmailAddress;
    property CreatedAtDateTime: TDateTime read FCreatedAtDateTime; // write FCreatedAtDateTime;
  end;

implementation


initialization
  RegisterEntity(TParty);

end.

As you have already flagged those fields as TColumnProp.NoUpdate so it would cause no harm in having those in JSON, as they won't be updated.

But if you want the to be absent from Swagger itself, then no, it's not possible with Automatic CRUD endpoints.

In this case, you can override the PUT/POST methods with service operations and create a separated DTO class to receive the properties you want.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.