<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe" -->

---
title: How to generate code from OpenAPI definition with Visual...
description: A walkthrough shows how to use Visual Studio 2019's Service Reference wizard to generate a C# API client from an OpenAPI/Swagger definition, using NSwag under...
canonical: https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to generate code from OpenAPI definition with Visual Studio 2019 | daily.dev
og:description: A walkthrough shows how to use Visual Studio 2019's Service Reference wizard to generate a C# API client from an OpenAPI/Swagger definition, using NSwag under...
og:url: https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe
og:image: https://api.daily.dev/og/posts/8aaxKKrfE.png
og:image:alt: How to generate code from OpenAPI definition with Visual Studio 2019
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to generate code from OpenAPI definition with Visual Studio 2019

**[Code4IT](https://daily.dev/sources/code4it)** · 10 min read · 0 upvotes · 0 comments

## Summary

A walkthrough shows how to use Visual Studio 2019's Service Reference wizard to generate a C# API client from an OpenAPI/Swagger definition, using NSwag under the hood. It covers locating the OpenAPI JSON file, adding a service reference, viewing the generated swaggerClient.cs code, and examining the generated models and methods. The generated method names are criticized as meaningless (e.g., MarvelMoviesAllAsync, MarvelMovies3Async) because they don't reflect HTTP verbs or intent, with a suggestion to wrap the client in a custom class with better naming. Usage examples show calling the generated client to fetch and post movie data.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/openapi-code-generation-vs2019>

## Questions this post answers

### How do I generate a C# API client from an OpenAPI/Swagger definition in Visual Studio 2019?

Right-click the project in Solution Explorer, choose Add > Service Reference, select OpenAPI, and provide the location of the OpenAPI JSON file plus a namespace. Visual Studio installs NSwag.ApiDescription.Client, Microsoft.Extensions.ApiDescription.Client, and Newtonsoft.Json, then generates a swaggerClient.cs file under the obj folder viewable via 'View generated code'.

_daily.dev surfaces walkthroughs like this for developers automating API client generation with OpenAPI._

### Why are the method names generated by Visual Studio's OpenAPI client generator so unclear, like MarvelMovies3Async?

The generator names methods based on the endpoint path rather than the HTTP verb or purpose, so when multiple operations (GET, POST, DELETE) share the same route, they get numbered suffixes like MarvelMoviesAsync, MarvelMovies2Async, and MarvelMovies3Async instead of descriptive names like GetMarvelMoviesById or DeleteMarvelMovie. Wrapping the client in a custom class with clearer method names is recommended.

_developers wrestling with generated client code readability can find similar workarounds on daily.dev._

## Similar posts on daily.dev

- [Full-stack static typing with OpenAPI TypeScript and Microsoft.AspNetCore.OpenApi](https://daily.dev/posts/full-stack-static-typing-with-openapi-typescript-and-microsoft-aspnetcore-openapi-irja8ajaq) · John Reilly · 3 upvotes · 0 comments
- [Combining API versioning with OpenAPI in .NET 10 applications](https://daily.dev/posts/combining-api-versioning-with-openapi-in-net-10-applications-gmga4jjr0) · ASP.NET Blog · 25 upvotes · 0 comments
- [Swagger In A Box: NPM, APIs, and Swagger Codegen](https://daily.dev/posts/swagger-in-a-box-npm-apis-and-swagger-codegen-ks4ldkveh) · Atomic Spin · 6 upvotes · 0 comments
- [Create Type-Safe API Clients: A Complete Guide](https://daily.dev/posts/create-type-safe-api-clients-a-complete-guide-d2bdv9pzr) · Platformatic · 3 upvotes · 0 comments

---

Tags: [#c#](https://daily.dev/tags/c#), [#visual-studio](https://daily.dev/tags/visual-studio), [#openapi](https://daily.dev/tags/openapi)

[View this post on daily.dev](https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to generate code from OpenAPI definition with Visual Studio 2019","url":"https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe"},"datePublished":"2026-10-04T13:07:22.891Z","dateModified":"2026-10-04T13:16:58.024Z","description":"A walkthrough shows how to use Visual Studio 2019's Service Reference wizard to generate a C# API client from an OpenAPI/Swagger definition, using NSwag under...","image":"https://media.daily.dev/image/upload/s--2-1xRawN--/f_auto/v1722860399/public/Placeholder%2011","thumbnailUrl":"https://media.daily.dev/image/upload/s--2-1xRawN--/f_auto/v1722860399/public/Placeholder%2011","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"c#,visual-studio,openapi","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"How to generate code from OpenAPI definition with Visual Studio 2019"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-generate-code-from-openapi-definition-with-visual-studio-2019-8aaxkkrfe#faq","mainEntity":[{"@type":"Question","name":"How do I generate a C# API client from an OpenAPI/Swagger definition in Visual Studio 2019?","acceptedAnswer":{"@type":"Answer","text":"Right-click the project in Solution Explorer, choose Add > Service Reference, select OpenAPI, and provide the location of the OpenAPI JSON file plus a namespace. Visual Studio installs NSwag.ApiDescription.Client, Microsoft.Extensions.ApiDescription.Client, and Newtonsoft.Json, then generates a swaggerClient.cs file under the obj folder viewable via 'View generated code'. daily.dev surfaces walkthroughs like this for developers automating API client generation with OpenAPI."}},{"@type":"Question","name":"Why are the method names generated by Visual Studio's OpenAPI client generator so unclear, like MarvelMovies3Async?","acceptedAnswer":{"@type":"Answer","text":"The generator names methods based on the endpoint path rather than the HTTP verb or purpose, so when multiple operations (GET, POST, DELETE) share the same route, they get numbered suffixes like MarvelMoviesAsync, MarvelMovies2Async, and MarvelMovies3Async instead of descriptive names like GetMarvelMoviesById or DeleteMarvelMovie. Wrapping the client in a custom class with clearer method names is recommended. developers wrestling with generated client code readability can find similar workarounds on daily.dev."}}]}
```

