Using OpenAPI/Swagger for Testing and Code Generation in ASP.NET Core

Testing an API improves its reliability. Generating client-side code helps with getting started fast when building a client that consumes your API. OpenAPI can help with both. In this course, you'll learn how.
Course info
Rating
(20)
Level
Intermediate
Updated
Apr 12, 2019
Duration
1h 21m
Table of contents
Description
Course info
Rating
(20)
Level
Intermediate
Updated
Apr 12, 2019
Duration
1h 21m
Description

Testing an API improves its reliability. Generating client-side code helps with getting started fast when building a client that consumes your API. OpenAPI can help with both. In this course, Using OpenAPI/Swagger for Testing and Code Generation in ASP.NET Core, you will gain the ability to test an API and generate code from it. First, you will learn what OpenAPI (Swagger) is. Next, you will discover how it can help with code generation. Finally, you will explore how to test your API, from manual to automated and command-line testing. When you’re finished with this course, you will have the skills and knowledge of .NET Core and OpenAPI needed to test your API and generate client-side code from it.

About the author
About the author

Kevin Dockx is a freelance solution architect (mobile/web), author & consultant, living in Antwerp (Belgium).

More from the author
Testing with EF Core
Intermediate
1h 12m
Jun 14, 2019
More courses by Kevin Dockx
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi everyone. My name is Kevin. Welcome to my course, Using OpenAPI/Swagger for Testing and Code Generation in ASP.NET Core. I'm a Microsoft MVP and freelance solution architect currently focused on security in APIs. In this course, we're going to learn how to test an API, which will improve its reliability and generate code from its OpenAPI Specification, which can help with building clients that consume the API. Some of the major topics that we will cover include generating DTOs and clients from an OpenAPI or Swagger Specification, manually testing an API, automating API tests, and using a command-line interface tool, HTTP-REPL, to interact with your API. By the end of this course, you'll know all about API testing and the power of OpenAPI in regards to code generation. Before beginning the course, you should be familiar with .NET Core and C#. I hope you'll join me on this journey to learn all about API testing and code generation with the Using OpenAPI/Swagger for Testing and Code Generation in ASP.NET Core course, at Pluralsight.

Getting Started with OpenAPI/Swagger
Swagger, or OpenAPI, is often used for generating documentation for your API, but it's much broader than that. In this course, you'll learn how OpenAPI can help in generating code and creating tests for your API. I'm Kevin, and I'll guide you through it. We're starting the course by looking at the course prerequisites and tooling and framework versions we're going to use. Then we'll immediately dive into the demo application we're starting from, and we'll follow it up by looking at different use cases for OpenAPI. We'll also have a look at a high-level overview of how it actually works. If you happen to have any questions, the best place to post them is on the Discussions tab on the course page. I check this regularly and like that questions and answers can help other people out as well. For very short questions that require a quick answer, you can contact me on Twitter, or just follow me if you want to know about my upcoming courses, user group events, or are interested in the technology I'm interested in. I mainly tweet regarding ASP.NET Core, security, and APIs these days. Let's have a look at the course prerequisites.

Generating Client-side Code from an OpenAPI Specification
An OpenAPI Specification can be used to generate client-side code from. In this module, you'll learn why that's useful and how to do it. I'm Kevin, and I'll guide you through it. We'll start by learning why client-side code generation can be beneficial or even necessary. Then we'll dive into the different tools that exist for client-side code generation. We'll use two of them to generate DTO classes and compare them. Lastly, we'll learn what other kind of client-code can be generated next to DTO classes; full clients for interacting with an API in different languages. We'll also learn how to do that. Let's dive in.

Using OpenAPI to Test an API
Most people who've used Swagger to document an API know they can manually test the API by sending requests via the generated documentation user interface. If that's possible, that means that an OpenAPI Spec contains all the necessary information to create requests from. We can take this a few steps further and take the manual part out of the equation. That's what we'll do in this module. I'm Kevin, and I'll guide you through it. We'll start by having a look at why you should test your API and what's meant with API testing, from manual testing to automated testing. After that, we'll look at the options we have in regards to API testing, and we'll demo different approaches, manual and automated API testing via Postman and Newman and command-line interface testing with HTTP-REPL. In all of these, OpenAPI will play an essential role. Let's dive in.