I'm creating automatic type-safe REST API (Refit) from Swagger document. I'm Creating Interface and model class manually like below.
I'm having huge number of Swagger files. So I want to do this dynamically, Please help me if anyone know.
What I have tried:
I'm Creating Interface and model class manually like below.
Swagger file:
<pre>"paths": {
"/configuration/v1/devices/{device_serial}": {
"get": {
"tags": [
"Devices"
],
"summary": "Get variablised template for a Switch.",
"description": " Response information.",
"x-deployed": true,
"operationId": "api.devices.get_device",
"produces": [
"multipart/form-data"
],
"parameters": [
{
"in": "path",
"name": "device_serial",
"description": "Serial number of the device.",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Successful operation.",
"schema": {
"type": "object",
"properties": {
"total": {
"type": "integer"
},
"data": {
"type": "string"
}
}
}
}
}
}
}
}
Interface code:
[Get("/configuration/v1/devices/{device_serial}")]
Task<DevicesResponse> GetDeviceVariabilisedTemplateAsync(
[AliasAs("device_serial")] string deviceSerial,
CancellationToken cancellationToken = default);
Model Class:
[DataContract]
public class DevicesResponse
{
[DataMember(Name = "total", EmitDefaultValue = false)]
public int? Total { get; set; } = default!;
[DataMember(Name = "data", EmitDefaultValue = false)]
public string? Data { get; set; } = default!;
}