Skip to content

Releases: kane-armstrong/rest-api-from-sql

v0.2.0 - 2021-08-03

03 Aug 07:53
Compare
Choose a tag to compare
v0.2.0 - 2021-08-03 Pre-release
Pre-release

REST API Generator

This is a simple, unambitious code generation tool. It looks at the schema of a SQL database
and generates a REST API for it, with typical CRUD endpoints that support both filtering on
primary key and (optionally) on unique key, as additional endpoints.

See the samples folder for an example of how to call the executable and the output of a successful invocation.

Example PowerShell invocation:

.\apigen.exe `
-c "Server=localhost;Initial Catalog=Chinook;Persist Security Info=False;Integrated Security=true;" `
-s "ChinookApi" `
-d "c:\temp\generated code\Chinook" `
-p "ChinookApi" 

The apigen.exe executable can be found in the releases page, or compiled using dotnet build. The executable will then be in the
rest-api-from-sql\src\RestApiFromSqlSchema.Console\bin\Debug\net5.0 folder.

Quick summary of the generated API:

  • ASP.NET 5.0 (C#)
  • Swagger support
  • Generates one class per table
  • Generates an EntityFramework DbContext with support for both primary and composite keys
  • Generates an API controller for each entity (typical CRUD, i.e.. paginated index, get by id/unique key, create, edit, delete)
  • Maps schema/table name to namespace/type name, e.g. HumanResources.Shift becomes namespace HumanResources { public class Shift { ... } }
  • Always includes both schema and table name when naming or referencing things (to avoid ambiguity errors)
  • Modifies class/property names as necessary for syntax/conflict purposes (annotates using data annotations to keep the ORM happy)

Limitations:

  • Does not support tables without primary keys
  • Does not support generating navigation properties
  • Does not support the SQL hierarchyid system data type (currently maps to string, but untested for create/edit)

v0.1.0 - 2018-12-05

04 Dec 11:45
Compare
Choose a tag to compare
v0.1.0 - 2018-12-05 Pre-release
Pre-release

REST API Generator

This is a simple, unamabitious code generation tool. It looks at the schema of a SQL database
and generates a REST API for it, with typical CRUD endpoints that support both filtering on
primary key and (optionally) on unique key, as additional endpoints.

Quick summary of the generated API:

  • ASP.NET Core 2.1
  • Swagger support
  • Generates one class per table
  • Generates an EntityFramework DbContext with support for both primary and composite keys
  • Generates an API controller for each entity (typical CRUD, i.e.. paginated index, get by id/unique key, create, edit, delete)
  • Maps schema/table name to namespace/type name, e.g. HumanResources.Shift becomes namespace HumanResources { public class Shift { ... } }
  • Always includes both schema and table name when naming or referencing things (to avoid ambiguity errors)
  • Modifies class/property names as necessary for syntax/conflict purposes (annotates using data annotations to keep the ORM happy)

Limitations:

  • Does not support tables without primary keys
  • Does not support generating navigation properties
  • Does not support the SQL hierarchyid system data type (currently maps to string, but untested for create/edit)
  • Does not support the geometry system data type (can't fix until 2.2)
  • No tests

Planned:

  • Generate FluentValidation validators and plug them into the MVC request pipeline with a filter to map ModelState validation errors
    to an error schema
  • Avoid IDENTITY_INSERT errors on write (e.g. separate object with the IDENTITY column removed on generated
    POST endpoints)

Maybes:

  • Support generating an alternative API - CQRS/Mediator/ProjectTo
  • Implement support for other database engines (sort of already there as the schema exploration is behind an interface and
    pluggable via builder - but makes liberal use of schema names, not all engines treat schema the same way MSSQL does)