@@ -65,6 +65,7 @@ private static void ProcessDatasyncOperation(OperationProcessorContext context)
65
65
string path = context . OperationDescription . Path ;
66
66
Type entityType = GetTableEntityType ( context . ControllerType ) ;
67
67
JsonSchema entitySchemaRef = GetEntityReference ( context , entityType ) ;
68
+ AddMissingSchemaProperties ( entitySchemaRef . Reference ) ;
68
69
69
70
if ( method . Equals ( "DELETE" , StringComparison . InvariantCultureIgnoreCase ) )
70
71
{
@@ -91,20 +92,59 @@ private static void ProcessDatasyncOperation(OperationProcessorContext context)
91
92
if ( method . Equals ( "POST" , StringComparison . InvariantCultureIgnoreCase ) )
92
93
{
93
94
operation . AddConditionalRequestSupport ( entitySchemaRef , true ) ;
95
+ operation . TryAddConsumes ( "application/json" ) ;
96
+ operation . Parameters . Add ( new OpenApiParameter { Schema = entitySchemaRef , Kind = OpenApiParameterKind . Body } ) ;
94
97
operation . SetResponse ( HttpStatusCode . Created , entitySchemaRef ) ;
95
98
operation . SetResponse ( HttpStatusCode . BadRequest ) ;
96
99
}
97
100
98
101
if ( method . Equals ( "PUT" , StringComparison . InvariantCultureIgnoreCase ) )
99
102
{
100
103
operation . AddConditionalRequestSupport ( entitySchemaRef ) ;
104
+ operation . TryAddConsumes ( "application/json" ) ;
105
+ operation . Parameters . Add ( new OpenApiParameter { Schema = entitySchemaRef , Kind = OpenApiParameterKind . Body } ) ;
101
106
operation . SetResponse ( HttpStatusCode . OK , entitySchemaRef ) ;
102
107
operation . SetResponse ( HttpStatusCode . BadRequest ) ;
103
108
operation . SetResponse ( HttpStatusCode . NotFound ) ;
104
109
operation . SetResponse ( HttpStatusCode . Gone ) ;
105
110
}
106
111
}
107
112
113
+ private static void AddMissingSchemaProperties ( JsonSchema ? schema )
114
+ {
115
+ if ( schema is null )
116
+ {
117
+ return ;
118
+ }
119
+
120
+ if ( schema . Properties . ContainsKey ( "id" ) && schema . Properties . ContainsKey ( "updatedAt" ) && schema . Properties . ContainsKey ( "version" ) )
121
+ {
122
+ // Nothing to do - the correct properties are already in the schma.
123
+ return ;
124
+ }
125
+
126
+ _ = schema . Properties . TryAdd ( "id" , new JsonSchemaProperty
127
+ {
128
+ Type = JsonObjectType . String ,
129
+ Description = "The globally unique ID for the entity" ,
130
+ IsRequired = true
131
+ } ) ;
132
+ _ = schema . Properties . TryAdd ( "updatedAt" , new JsonSchemaProperty
133
+ {
134
+ Type = JsonObjectType . String ,
135
+ Description = "The ISO-8601 date/time string describing the last time the entity was updated with ms accuracy." ,
136
+ IsRequired = false
137
+ } ) ;
138
+ _ = schema . Properties . TryAdd ( "version" , new JsonSchemaProperty
139
+ {
140
+ Type = JsonObjectType . String ,
141
+ Description = "An opaque string that changes whenever the entity changes." ,
142
+ IsRequired = false
143
+ } ) ;
144
+
145
+ return ;
146
+ }
147
+
108
148
/// <summary>
109
149
/// Either reads or generates the required entity type schema.
110
150
/// </summary>
0 commit comments