API Part 7 – Swagger Comments

In the previous post, I introduced Swagger and showed how to set up your project for Swagger. In this post I will show how to add Swagger comments to annotate your program.

In earlier posts we looked at the database of cars and the Get method that retrieves the entire list. That can be quite a lot of data going over the wire. What we want instead is to send pages. I’ll show that briefly and then we’ll annotate that code.

In the CarController we’ll have a Get method that takes three parameters: showDeleted, pageNumber and pageSize. The first we’ve seen before, it determines whether the list returned to the caller will include our deleted records. The second, pageNumber, will designate which page of data we want to return (zero based). The third parameter, pageSize, will designate how many records to return per page.

Thus, if we were to write

Get(false,3,4)

we would expect to get back records 17, 18, 19 and 20, because page 0 would have records 1-4, page 1 would have 5-8, etc.

Here is the compete endpoint that will directly call our repository (we won’t bother with a service for this example).

public async Task<IEnumerable<Car>> Get([FromRoute] bool showDeleted, int pageNumber, int pageSize )
{
    return await _carRepository.Get(showDeleted, pageNumber, pageSize);
}

When the repository is called, the parameters are passed in, and it does its magic. For now, however, we are only concerned with documenting this method. We do that with XML comments, designated by three forward slash marks (///).

First, we will document the purpose of the endpoint; that is, what it does. We do that in the summary

/// <summary>
/// Get all the cars in the Database 
/// </summary>

Next, we want to document the parameters

/// <param name="returnDeletedRecords">If true, the method will return all the records,
/// including the ones that have been deleted</param>
/// <param name="pageOffset">which page to display</param>
/// <param name="pageSize">how many records to display per page</param>

Finally, I’m going to document the possible response codes. Note, these are, by no means, all that you can document, but they’ll give us a good idea of how it is done

/// <response code="200">Cars returned</response>
/// <response code="404">Specified Car not found</response>
/// <response code="500">An Internal Server Error prevented the request from being executed.</response>

When an error is encountered and we return one of these codes, the text we’ve specified goes along for the ride, which is enormously helpful to the calling client.

At the top of the swagger page is our summary

At each parameter is our designated text

Finally, each of the error codes is documented

It is a best practice to document all of the endpoints. Many developers go further, and document all of the methods in both the service and the repository; that is a decision to be made by the team. Since the endpoint is the only thing visible to the client, it has the greatest claim on your time and effort. Remember, “comments rust,” and that is as true for Swagger comments as any other.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in API, C#, Essentials and tagged . Bookmark the permalink.

2,572 Responses to API Part 7 – Swagger Comments

  1. Drew Buzzo's avatar Drew Buzzo says:

    analyticsreport – Color palette felt calming, nothing distracting, just focused, thoughtful design.

  2. LhanepiliA's avatar LhanepiliA says:

    Thank you, I have just been looking for info about this topic for a long time and yours is the best I’ve discovered till now. However, what about the conclusion? Are you positive in regards to the supply?
    viagraonline2

  3. a2a mcp's avatar a2a mcp says:

    Great addition to the series. I’ve found that taking the time to write good Swagger comments not only helps others understand my API, but it forces me to think more clearly about my own design decisions. It’s documentation that pays for itself.

  4. Great post, Jesse. Adding meaningful Swagger comments has been a game-changer for our team’s onboarding process. It really does turn the API documentation from a simple reference into a practical guide. I’m curious, do you have a preferred approach for keeping these XML comments in sync as the API evolves?

  5. Salome's avatar Salome says:

    The program works with multiple file systems, including UDF, which is often used for data storage on DVDs. Image Creation, This tool can browse for data from severely damaged discs and create an image file suitable for data recovery purposes. Handling Image Discs, Even if a disk has been extracted, RepairCDDVD can recover the information contained within it. Support for Other Media, Besides the CD/DVD disks, this application can also recover data from several other types of media. ISO Format Conversion, It allows users to make copies of virtual disks (ISO images), which can be recovered later without any hindrance. Portable Version Available, RepairCDDVD can also be used as a portable utility that can be taken to different computers without being installed. Speed and Usability, The program boasts an intuitive interface and fast algorithms that allow straightforward scanning and recovering of data. If you need to recover information from a CD or DVD, RepairCDDVD is certainly worth trying.

  6. Shayna's avatar Shayna says:

    The program works with multiple file systems, including UDF, which is often used for data storage on DVDs. Image Creation, This tool can browse for data from severely damaged discs and create an image file suitable for data recovery purposes. Handling Image Discs, Even if a disk has been extracted, RepairCDDVD can recover the information contained within it. Support for Other Media, Besides the CD/DVD disks, this application can also recover data from several other types of media. ISO Format Conversion, It allows users to make copies of virtual disks (ISO images), which can be recovered later without any hindrance. Portable Version Available, RepairCDDVD can also be used as a portable utility that can be taken to different computers without being installed. Speed and Usability, The program boasts an intuitive interface and fast algorithms that allow straightforward scanning and recovering of data. If you need to recover information from a CD or DVD, RepairCDDVD is certainly worth trying.

  7. Elnora's avatar Elnora says:

    The program works with multiple file systems, including UDF, which is often used for data storage on DVDs. Image Creation, This tool can browse for data from severely damaged discs and create an image file suitable for data recovery purposes. Handling Image Discs, Even if a disk has been extracted, RepairCDDVD can recover the information contained within it. Support for Other Media, Besides the CD/DVD disks, this application can also recover data from several other types of media. ISO Format Conversion, It allows users to make copies of virtual disks (ISO images), which can be recovered later without any hindrance. Portable Version Available, RepairCDDVD can also be used as a portable utility that can be taken to different computers without being installed. Speed and Usability, The program boasts an intuitive interface and fast algorithms that allow straightforward scanning and recovering of data. If you need to recover information from a CD or DVD, RepairCDDVD is certainly worth trying.

  8. Hector's avatar Hector says:

    The program works with multiple file systems, including UDF, which is often used for data storage on DVDs. Image Creation, This tool can browse for data from severely damaged discs and create an image file suitable for data recovery purposes. Handling Image Discs, Even if a disk has been extracted, RepairCDDVD can recover the information contained within it. Support for Other Media, Besides the CD/DVD disks, this application can also recover data from several other types of media. ISO Format Conversion, It allows users to make copies of virtual disks (ISO images), which can be recovered later without any hindrance. Portable Version Available, RepairCDDVD can also be used as a portable utility that can be taken to different computers without being installed. Speed and Usability, The program boasts an intuitive interface and fast algorithms that allow straightforward scanning and recovering of data. If you need to recover information from a CD or DVD, RepairCDDVD is certainly worth trying.

  9. Jessie's avatar Jessie says:

    This is really fascinating, You’re an overly professional blogger.
    I’ve joined your rss feed and look forward to seeking extra of your fantastic post.

    Additionally, I’ve shared your web site in my social
    networks

  10. Velma's avatar Velma says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  11. Monte's avatar Monte says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  12. Marica's avatar Marica says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  13. Donn's avatar Donn says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  14. Robertnug's avatar Robertnug says:

    Аренда оборудования для чистоты, переходите <a href=
    https://www.beststroy.ru/catalog/286/1027/1_1.html

  15. Jessie's avatar Jessie says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  16. Azucena's avatar Azucena says:

    เนื้อหานี้ อ่านแล้วเข้าใจง่าย ครับ
    ดิฉัน ไปอ่านเพิ่มเติมเกี่ยวกับ ข้อมูลเพิ่มเติม
    ที่คุณสามารถดูได้ที่
    Azucena
    น่าจะถูกใจใครหลายคน
    มีตัวอย่างประกอบชัดเจน
    ขอบคุณที่แชร์ ข้อมูลที่มีประโยชน์ นี้
    และหวังว่าจะได้เห็นโพสต์แนวนี้อีก

  17. Lizbeth's avatar Lizbeth says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  18. Eden's avatar Eden says:

    บทความนี้ น่าสนใจดี ครับ
    ผม ได้อ่านบทความที่เกี่ยวข้องกับ ข้อมูลเพิ่มเติม
    ดูต่อได้ที่ Eden
    สำหรับใครกำลังหาเนื้อหาแบบนี้
    เพราะอธิบายไว้ละเอียด
    ขอบคุณที่แชร์ ข้อมูลที่มีประโยชน์ นี้
    และอยากเห็นบทความดีๆ แบบนี้อีก

  19. admark – Overall, professional vibe here; trustworthy, polished, and pleasantly minimal throughout.

  20. Jody's avatar Jody says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  21. Brendon's avatar Brendon says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  22. Hassan's avatar Hassan says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  23. Tanika's avatar Tanika says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  24. Steve's avatar Steve says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  25. Sharyn's avatar Sharyn says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  26. Jacob's avatar Jacob says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  27. Ahmed's avatar Ahmed says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  28. Clemente's avatar Clemente says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  29. Simon's avatar Simon says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  30. Tia's avatar Tia says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  31. Zackary's avatar Zackary says:

    RepairCdDvD v2.7 is a data recovery tool designed for recovering information from damaged CD and DVD media, effectively restoring data from corrupted DVDs. This software proves very helpful in cases when discs are scratched or poorly recorded. The operations of the program are performed without any risk, and the process of disk repair is carried out by means of an ISO image.

  32. You’re so cool! I do not believve I’ve ead a single
    thing like this before. So great to find someone with a few unique thoughts
    on this issue. Really.. many thanks for starting this up.
    This site is something that is needed on the web, someone with a
    bit of originality!

    My blog diyarbakır escort bayan

  33. Luigi's avatar Luigi says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

  34. Great addition to the series. I’ve found that taking the time to write thorough Swagger comments has dramatically improved the onboarding experience for new developers on our team. It forces you to think about the API from the consumer’s perspective.

  35. Shawnswarp's avatar Shawnswarp says:

    Looking well creates a positive first impression.
    Your attire communicates volumes before a person even say a single word.
    This enhances your personal self-esteem and mood significantly.
    Your polished appearance signals competence in the office.
    https://style.balmain1.ru/rol-demny-gvasaliya-v-razvitii-ulichnoy-mody-6154394/
    Fashionable clothing let you to express your individual personality.
    Others often perceive stylish individuals as more successful and reliable.
    Ultimately, investing in your wardrobe is an investment in yourself.

  36. Leandro's avatar Leandro says:

    RepairCdDvD v2.7 is a software tool designed to retrieve data from scratched or damaged CDs and DVDs, including formats such as CD+R/RW and DVD+R/RW, BD.

Comments are closed.