0

I try to run some C# code in Rider with Swagger file and it does not work.

I installed Swagger, Swagger plugin. The swagger.yaml file has works and the API can be viewed in the browser.

That's the lines at the beginning of the code:

using IO.Swagger.Api;
using IO.Swagger.Client;
using IO.Swagger.Model;

The project does not recognize the swagger file and the "IO" at the "using" appear in red.

I'd love to know how I upload the Swagger file to a project.

dr.list
  • 3
  • 4
  • Are you trying to connect to a service from which you have the swagger file, or are you writing a service and need it to produce a swagger file? Can you describe the steps you took step by step and where you are stuck? – nvoigt Aug 01 '19 at 08:28
  • I have swagger file That works correctly. I try to use some function in the c# project from the REST-API that the swagger file include. – dr.list Aug 01 '19 at 08:42
  • 1
    What is a "swagger file"? Is it the actual swagger file? The JSON? How do you want to include it? Did you generate a client from it? Like C# code? Please describe the exact steps you have taken so far, otherwise we won't be able to help you. – nvoigt Aug 01 '19 at 08:45
  • Sorry I'm misunderstood. Thank you very much for your help. The swagger file is yaml file that include documentation of the REST-API. I don't know how to attach it to the project.I don't know if that's what needs to be done. I just want use some function that appears in the rest-api. what i did until now is to take a GET request from the rest-api and convert it to c# code. now, the "using" lines in the top of the code appear in red, And I conclude that I should attach the swagger.yaml file. Or am I wrong? – dr.list Aug 01 '19 at 09:16

1 Answers1

2

The swagger file is a description of what the service looks like. It's not executable code and it's not source code written in a programming language that you could just compile.

You will need a code generator that generates your source code in the language of your choice from this file. (When I say "need", I don't mean you must do it... you can type it all out yourself. But that would be time consuming and ultimately pointless because a generator will do a much better job than a human on average.)

As generator you can for example use:

For example with the swagger codegen (first link, follow the download and installation instructions), this line will generate a folder with C# code that you will need to include in your project:

java -jar ./swagger-codegen-cli-2.4.5.jar generate -i your.yaml -l csharp -o output_folder

You will need to replace your.yaml with your filename and output_folder with the folder you want the generated files to end up in.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Thanks! I used the https://generator.swagger.io/ . Now I have the folder with what is needed. How do I turn it into a library to use its functions? – dr.list Aug 01 '19 at 12:44
  • You create a new library project and copy all the files over. That's it. – nvoigt Aug 01 '19 at 12:57