0
    /// <summary>
    /// updates information of a job
    /// </summary>
    /// <param name="job"></param>
    /// <returns>Ok or Error</returns>
    /// <example>
    /// {
    ///     "info_id": 1,
    ///     "some_other_id": 2
    /// }
    /// </example>
    [HttpPost]
    [Route("api/job/update")]
    public IHttpActionResult update(Models.Job job) {
    }

    //the model
    public class Job {
        [Required(AllowEmptyStrings = false)]
        [Range(1, Int64.MaxValue)]
        public Int64 info_id { get; set; }
        public Int64? some_other_id{ get; set; }
        public DateTime last_log_time { get; set; }
    }

Imagine the setup above. I would like to show the example JSON written inside the doc block of update in the documentation. However, there is shown the serialized JSON of an object typed Job with default values instead.

enter image description here

I don't want developers to think they could or should provide last_log_time to function update. This property shall be shown in a response message, but not sent to the api.
How can I customize the examples for the requests formats per function? Ideally I would state it inside the doc block as shown (the API should only take requests in JSON-format), or maybe per annotations on the properties of the Job-class.

How can we hide a property in WebAPI? the answer provodided here does not help because, as stated above, last_log_time shall be given in the response. If I annotate it with [IgnoreDataMember] it will be ignored globally.

ctindex
  • 93
  • 9

1 Answers1

0

You can add [ApiExplorerSettings(IgnoreApi = true)] to your last_log_time property, but it only hides last_log_time in body parameters.

If you want to hide in sample format, you need customize source code of method WriteSampleObjectUsingFormatter at file Areas\HelpPage\SampleGeneration\HelpPageSampleGenerator.cs

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62