Skip to content

double-em/Restluent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Restluent (Work in progress)

Restluent is supposed to be a Fluent Api Client generator.
The only thing needed is an OpenAPI Standard Schema eg. from Swagger.

Todo (Proof of Concept):

  • Example API
  • Open API Component parsing from a Json file
  • SourceGenerated classes from parsed components
  • Fluent Api builder
  • Couple the Api Client with the generated classes
  • HttpClient request handling
  • Unit Tests

Concept

Schema Example

If given a schema with the following components:

"components": {
    "schemas": {
        "WeatherForecast": {
            "type": "object",
            "properties": {
                "date": {
                    "type": "string",
                    "format": "date-time"
                },
                "temperatureC": {
                    "type": "integer",
                    "format": "int32"
                },
                "temperatureF": {
                    "type": "integer",
                    "format": "int32",
                    "readOnly": true
                },
                "summary": {
                    "type": "string",
                    "nullable": true
                }
            },
            "additionalProperties": false
        }
    }
}

Generated Example

There should be generated a class as:

// Auto-generated code
using System;

namespace Restluent
{
    public class WeatherForecast
    {
        public string date { get; set; }
        public int temperatureC { get; set; }
        public int temperatureF { get; set; }
        public string summary { get; set; }
    }
}

Usage Example

With a generated class like:

public class Customer
{
    public Guid Id { get; set; }

    public string Name { get; set; } = null!;
    
    public bool WithCompanies { get; set; }
}

Then the usage should be:

var customer = RestluentApi.Customers()
    .Where(c => c.Name == "tester")
    .WithCompanies();

var newCustomer = RestluentApi.Customers()
    .Add(new CustomerVariables
    {
        Name = "Test"
    });