To Import a REST Schema to a Visual Studio Solution
- You generate Visual Studio packages from the REST schema.
- You include the generated Visual Studio packages in your Visual Studio solution.
The following sections provide instructions on these stages, as well as an example of the use of the imported REST schema.
To Generate Visual Studio Packages from a REST Schema
- Obtain the swagger.json file you need.
- Open the website https://editor.swagger.io.
- Insert the contents of the swagger.json file into the
website's edit box.
The website suggests that you convert the JSON contents to YAML format.
- Click OK to agree to the suggestion or
Cancel to leave the contents in JSON format; neither
of these actions affects the result of parsing the file.
The website engine parses the REST schema contained in the swagger.json file and create the visual representation of the REST schema.
- On the Generate Client menu, invoke the
csharp command.
The csharp-client-generated.zip archive is downloaded to your computer. The archive contains the IO.Swagger Visual Studio solution, two Visual C# projects (IO.Swagger and IO.Swagger.Test), and other files.
- Extract the csharp-client-generated.zip archive.
- Make sure that the IO.Swagger solution can be built.
override
keyword and the absence of the
BaseValidate
method. To fix these errors, remove the misused
override
keyword and the entire command that contains the
nonexistent BaseValidate
method.To Add the Generated Projects to a Visual Studio Solution
- In Visual Studio, create a C# project.
- In your project, add a reference to the Newtonsoft.Json
library as follows:
- In Solution Explorer, right-click your project.
- Click Manage NuGet Packages.
- Select the Browse tab.
- Search for the Newtonsoft.Json library, and install it.
- In the folders containing the unpacked contents from the
csharp-client-generated.zip archives, rename the
IO.Swagger projects and the
IO.Swagger
namespaces to avoid the name conflict.You do not have to add the IO.Swagger.Test projects to the solution of your C# project.
- Add the former IO.Swagger projects to the solution of your C# project.
- In your project, add a reference to the RestSharp.dll library.
- Add your code that uses the REST API to your project.Tip:You can find other examples in the AcumaticaRESTAPIClientForCSharp repository on GitHub.