OpenApiLINQPadDriver 0.0.3-alpha
This is a prerelease version of OpenApiLINQPadDriver.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package OpenApiLINQPadDriver --version 0.0.3-alpha
NuGet\Install-Package OpenApiLINQPadDriver -Version 0.0.3-alpha
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenApiLINQPadDriver" Version="0.0.3-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OpenApiLINQPadDriver --version 0.0.3-alpha
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OpenApiLINQPadDriver, 0.0.3-alpha"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OpenApiLINQPadDriver as a Cake Addin #addin nuget:?package=OpenApiLINQPadDriver&version=0.0.3-alpha&prerelease // Install OpenApiLINQPadDriver as a Cake Tool #tool nuget:?package=OpenApiLINQPadDriver&version=0.0.3-alpha&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
OpenApiLINQPadDriver for LINQPad 7
Description
OpenApiLINQPadDriver is LINQPad 7 dynamic data context driver for creating C# clients based on Open API/Swagger specifications
- Specification is read using NJsonSchema and clients are generated using NSwag
Websites
- This project
- Original project for LINQPad 5
- UI is heavily inspired by CsvLINQPadDriver
Downloads
generation of lpx6 files is on the roadmap, for now we only support instalation via nuget
Prerequisites
Installation
LINQPad 7
NuGet
- Open LINQPad 7.
- Click
Add connection
link. - Click button
View more drivers...
- Click radio button
Show all drivers
and typeOpenApiLINQPadDriver
(for now it is also required to checkInclude Prerelease
checkbox) - Install.
- In case of working in environments without internet access it is possible to manually download nuget package and configure
Package Source
to point to a folder where it is located
Usage
Open API Connection can be added the same way as any other connection.
- Click
Add Connection
- Select
OpenApi Driver
- Enter
Open Api Json Uri
or clickGet from disk
and pick it from file - Manually enter
API Uri
or clickGet from swagger.json
, if servers are found in the specification uri of the first one will be picked - Set settings
- Click
OK
- Client should start generation, you can use it by right clicking on it and choosing
Use in Current Query
or by picking it fromConnection
select - It is possible to drag method name from the tree view on the left to the query
- Example code using PetStore API
async Task Main()
{
var newPetId = System.Random.Shared.NextInt64();
await PetClient.AddPetAsync(new Pet()
{
Id = newPetId,
Name = "Dino",
Category = new Category
{
Id = 123,
Name = "Dog"
}
});
await PetClient.GetPetByIdAsync(newPetId).Dump();
}
Refreshing client
- Right click on the connection and click
Refresh
- Or use shortcut
Shift+Alt+D
Configuration Options
Client Generation
- Endpoint grouping - how methods will be grouped in generated client
Multiple clients from first tag and operationName
- usually first tag corresponds to ASP.NET controller, so this will group methods by controllerSingle client from OperationId and OperationName
- this will put all endpoints in one class
- Json library - library used in generated client for serialization/deserialization, for specification reading NJsonSchema uses
Newstonsoft.Json
System.Text.Json
Newstonsoft.Json
- Class style
POCOs (Plain Old C# Objects)
Classes implementing the INotifyPropertyChanged interface
Classes implementing the Prism base class
- WIP, the library that is required is not added to the compilationRecords - read only POCOs (Plain Old C# Objects)
- Generate sync methods - by default sync methods will not be generated
Misc
- Debug info: show additional driver debug info, e.g. generated data context sources and add
Execution Times
explorer item with exectuion times of parts of the generation pipeline - Remember this connection: connection will be available on next run.
- Contains production data: files contain production data.
PrepareRequestFunction
- Each generated client has
PrepareRequestFunction
Func, forMultiple clients from first tag and operationName
mode, helper set only Func is also generted to set them all at once - This Func will be run on each method exectuion before making a http request, it is run in
PrepareRequest
partial methods generated by NSwag - It can be used to set additional headers or other http client settings
- Example usage
async Task Main()
{
PrepareRequestFunction = (httpClient, requestMessage, url) =>
{
requestMessage.Headers.Add("UserId", "9");
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "<token>");
};
}
async Task Main()
{
PrepareRequestFunction = PrepareRequest;
}
private void PrepareRequest(HttpClient httpClient, HttpRequestMessage requestMessage, string url)
{
requestMessage.Headers.Add("UserId", "9");
requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "<token>");
}
Known Issues
- Code does not compile when there are parameters with the same name, but with case differences in the single endpoint and they come from different locations eg
[FromQuery] int test, [FromHeader] int Test
related issue
Credits
Tools
Libraries
- NJsonSchema
- NSwag
- Newtonsoft.Json - required by NSwag, included to bump version
Development
- OpenApiLINQPadDriver.csproj contains special
Debug_Publish_To_LINQPad_Folder
debug build configuration, if it is chosen, code will be build only targetingnet7.0-windows
with additional properties: https://github.com/romfir/OpenApiLINQPadDriver/blob/master/OpenApiLINQPadDriver/OpenApiLINQPadDriver.csproj#L50-L56 - LINQPad can pick drivers from
\LINQPad\Drivers\DataContext\NetCore
folder - Additionaly when exceptions will be thrown it will be possible to attach a debugger: https://github.com/romfir/OpenApiLINQPadDriver/blob/master/OpenApiLINQPadDriver/OpenApiContextDriver.cs#L11-L20
Roadmap
- Allow injection of own httpClient
- Unit tests
PrepareRequest
with string builder overloadProcessResponse
PrepareRequest
andProcessResponse
async overload that could be set via a setting- Methods parameters and responses in tree view
- Auto dump response
- Auth helper methods eg.
SetBearerToken
- Check if it is possible to add summary to generated methods
- Add
Prism.Mvvm
to compilation when prism class style is picked - When multiple servers are found allow selection
- LINQPad 5 support
- Examples (include in the nuget)
- Expose JsonSerializerSettings setter on multi client setup
- Expose ReadResponseAsString on multi client setup
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0-windows7.0 is compatible. net7.0-windows was computed. net7.0-windows7.0 is compatible. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0-windows7.0
- LINQPad.Reference (>= 1.3.0)
- Newtonsoft.Json (>= 13.0.3)
- NJsonSchema (>= 10.9.0)
- NJsonSchema.CodeGeneration (>= 10.9.0)
- NJsonSchema.CodeGeneration.CSharp (>= 10.9.0)
- NSwag.CodeGeneration (>= 13.20.0)
- NSwag.CodeGeneration.CSharp (>= 13.20.0)
- NSwag.Core (>= 13.20.0)
-
net7.0-windows7.0
- LINQPad.Reference (>= 1.3.0)
- Newtonsoft.Json (>= 13.0.3)
- NJsonSchema (>= 10.9.0)
- NJsonSchema.CodeGeneration (>= 10.9.0)
- NJsonSchema.CodeGeneration.CSharp (>= 10.9.0)
- NSwag.CodeGeneration (>= 13.20.0)
- NSwag.CodeGeneration.CSharp (>= 13.20.0)
- NSwag.Core (>= 13.20.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.8-alpha | 103 | 6/1/2024 |
0.0.7-alpha | 112 | 2/5/2024 |
0.0.6-alpha | 103 | 1/14/2024 |
0.0.5-alpha | 105 | 12/27/2023 |
0.0.4-alpha | 107 | 9/10/2023 |
0.0.3-alpha | 92 | 9/10/2023 |
0.0.2-alpha | 86 | 9/8/2023 |
0.0.1-alpha | 88 | 9/8/2023 |