Skip to content

Commit

Permalink
Merge pull request #12 from DeeJayTC/11-api-from-json
Browse files Browse the repository at this point in the history
Allow creating APIs via JSON
  • Loading branch information
DeeJayTC committed Apr 10, 2022
2 parents c3d4e12 + 99733c0 commit 1505017
Show file tree
Hide file tree
Showing 60 changed files with 2,760 additions and 1,196 deletions.
77 changes: 77 additions & 0 deletions .editorconfig
Expand Up @@ -2,3 +2,80 @@

# CS1591: Fehledes XML-Kommentar für öffentlich sichtbaren Typ oder Element
dotnet_diagnostic.CS1591.severity = none
csharp_indent_labels = one_less_than_current
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_space_around_binary_operators = before_and_after

[*.{cs,vb}]
#### Naming styles ####

# Naming rules

dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i

dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case

dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
25 changes: 12 additions & 13 deletions README.md
@@ -1,14 +1,19 @@
# Turn your models into fully working APIs in minutes

<a href="https://tcdev.gitbook.io/"><img src="https://img.shields.io/badge/Docs-0.0.4-orange"></a>
<a href="https://tcdev.gitbook.io/"><img src="https://img.shields.io/badge/Docs-0.0.9-orange"></a>
<a href="https://twitter.com/intent/follow?screen_name=timcadenbach"><img src="https://img.shields.io/badge/Twitter-follow-blue"></a>
<img src="https://img.shields.io/github/workflow/status/DeeJayTC/net-dynamic-api/.NET/main?label=Main"> <img src="https://img.shields.io/github/workflow/status/DeeJayTC/net-dynamic-api/.NET/vnext?label=vnext"> <img src="https://img.shields.io/github/sponsors/deejaytc?label=Lovely%20Sponsors" />

Little Sneak here -> https://www.youtube.com/watch?v=25lxRLQuxrs

First of all this is a really early Alpha, consider things with care.

By using the API Generator, this little code snippet is a fully working CRUD API
The API Generator takes any class you like and generates a fully working CRUD API with Odata filter+select support, Database (SQL SQLLite or InMemory)
and also automatic migrations.
In future the service will evolve into a full instant "Database to API" Microservice with no boilerplate code needed.

```

By using the API Generator, this little code snippet is already a working CRUD API
```csharp
/// <summary>
/// This is the minimal sample, yes this is a working api ;)
/// </summary>
Expand All @@ -20,12 +25,10 @@ public class MinimalSample : IObjectBase<int>
public int Value { get; set; }
}
```
The API Generator takes any class you like and generates a fully working CRUD API with Odata filter+select enabled.
In future the service will evolve into a full instant "Database to API" Microservice with no boilerplate code needed.

Heres another sample:

```
```csharp
[Api("/people", ApiMethodsToGenerate.All )]
public class Person : Trackable,
IObjectBase<Guid>,
Expand All @@ -40,14 +43,10 @@ Heres another sample:
}
```


# How to use:
```
dotnet add package TCDev.ApiGenerator --version 0.0.4-alpha
```

# Getting Started & Docoumentation

[https://www.tcdev.de/tcdev-api-generator-getting-started](https://www.tcdev.de/tcdev-api-generator-getting-started)

[https://tcdev.gitbook.io/](https://tcdev.gitbook.io/)

# Samples
Expand Down
25 changes: 24 additions & 1 deletion TCDev.APIGenerator.sln
Expand Up @@ -24,13 +24,16 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Sample App", "Sample App",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleAppNuget", "sample\SampleAppNuget\SampleAppNuget.csproj", "{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TCDev.APIGenerator.DbFirst", "src\TCDev.APIGenerator.DbFirst\TCDev.APIGenerator.DbFirst.csproj", "{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TCDev.APIGenerator.Json", "src\TCDev.APIGenerator.DbFirst\TCDev.APIGenerator.Json.csproj", "{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleAppJson", "sample\SampleAppJson\SampleAppJson.csproj", "{25AE6B2A-822D-411B-AB65-068E9E0E41D5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
DebugWithSampleApp|Any CPU = DebugWithSampleApp|Any CPU
Release|Any CPU = Release|Any CPU
SampleAppJson|Any CPU = SampleAppJson|Any CPU
SampleAppNuget|Any CPU = SampleAppNuget|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
Expand All @@ -40,32 +43,40 @@ Global
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.DebugWithSampleApp|Any CPU.Build.0 = DebugWithSampleApp|Any CPU
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.Release|Any CPU.Build.0 = Release|Any CPU
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.SampleAppJson|Any CPU.Build.0 = SampleAppJson|Any CPU
{FE869C02-6C9A-4D9B-BBE2-56F1B21B2A55}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.Debug|Any CPU.Build.0 = Debug|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.DebugWithSampleApp|Any CPU.Build.0 = DebugWithSampleApp|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.Release|Any CPU.ActiveCfg = Release|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.Release|Any CPU.Build.0 = Release|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{303BF897-594C-4911-91CF-3887A8B8E839}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{0C8E23AD-AC5D-41D4-9F67-0ECF3D1C4BE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C8E23AD-AC5D-41D4-9F67-0ECF3D1C4BE1}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{0C8E23AD-AC5D-41D4-9F67-0ECF3D1C4BE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C8E23AD-AC5D-41D4-9F67-0ECF3D1C4BE1}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{0C8E23AD-AC5D-41D4-9F67-0ECF3D1C4BE1}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{EDEA4DF4-49DF-4205-9B8E-61D76F26BA8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDEA4DF4-49DF-4205-9B8E-61D76F26BA8D}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{EDEA4DF4-49DF-4205-9B8E-61D76F26BA8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDEA4DF4-49DF-4205-9B8E-61D76F26BA8D}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{EDEA4DF4-49DF-4205-9B8E-61D76F26BA8D}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.DebugWithSampleApp|Any CPU.Build.0 = DebugWithSampleApp|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.Release|Any CPU.Build.0 = Release|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.SampleAppJson|Any CPU.Build.0 = SampleAppJson|Any CPU
{94E59385-D259-40A1-A373-1FBD0A42CD63}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851}.SampleAppNuget|Any CPU.Build.0 = SampleAppNuget|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
Expand All @@ -74,8 +85,19 @@ Global
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.DebugWithSampleApp|Any CPU.Build.0 = DebugWithSampleApp|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.Release|Any CPU.Build.0 = Release|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4}.SampleAppNuget|Any CPU.Build.0 = SampleAppNuget|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.DebugWithSampleApp|Any CPU.ActiveCfg = DebugWithSampleApp|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.DebugWithSampleApp|Any CPU.Build.0 = DebugWithSampleApp|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.Release|Any CPU.Build.0 = Release|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.SampleAppJson|Any CPU.ActiveCfg = SampleAppJson|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.SampleAppJson|Any CPU.Build.0 = SampleAppJson|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.SampleAppNuget|Any CPU.ActiveCfg = SampleAppNuget|Any CPU
{25AE6B2A-822D-411B-AB65-068E9E0E41D5}.SampleAppNuget|Any CPU.Build.0 = SampleAppNuget|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -88,6 +110,7 @@ Global
{94E59385-D259-40A1-A373-1FBD0A42CD63} = {4189D7E0-F171-4267-AC64-C9A83BB1B559}
{BA9E04E6-4B66-4369-9B2F-C6CEC9499851} = {8CC9B68F-E1C2-45B3-8814-B9FF4E1B2AB8}
{7F3574D1-7421-4824-A0BB-522F3BC9BAC4} = {4189D7E0-F171-4267-AC64-C9A83BB1B559}
{25AE6B2A-822D-411B-AB65-068E9E0E41D5} = {8CC9B68F-E1C2-45B3-8814-B9FF4E1B2AB8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {315BF454-8B91-42C5-A113-B59C72AE69C8}
Expand Down
42 changes: 42 additions & 0 deletions sample/ApiGeneratorSampleApp/ApiDefinition.json
@@ -0,0 +1,42 @@
[

{
"name": "MakeJSON",
"route": "/MakeJSON",
"idType": "int",
"Fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Description",
"Type": "string"

}
]
},
{
"name": "CarJSON",
"route": "/CarJSON",
"idType": "int",
"Fields": [
{
"name": "Name",
"type": "string"
},
{
"name": "Description",
"Type": "string"
},
{
"name": "Make",
"type": "virtual MakeJSON"
},
{
"name": "MakeId",
"type": "int"
}
]
}
]
13 changes: 12 additions & 1 deletion sample/ApiGeneratorSampleApp/ApiGeneratorSampleApI.csproj
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<UserSecretsId>aspnet-ApiGeneratorSampleApp-56AA10DB-26A2-414F-AFD8-1D3546BD678D</UserSecretsId>
<Configurations>Debug;Release;DebugWithSampleApp;SampleAppNuget</Configurations>
<Configurations>Debug;Release;DebugWithSampleApp;SampleAppNuget;SampleAppJson</Configurations>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand All @@ -14,6 +14,10 @@
<DocumentationFile>ApiGeneratorSampleApI.xml</DocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SampleAppJson|AnyCPU'">
<DocumentationFile>ApiGeneratorSampleApI.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="GraphQL" Version="4.6.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
Expand All @@ -33,6 +37,13 @@

<ItemGroup>
<ProjectReference Include="..\..\src\TCDev.APIGenerator\TCDev.APIGenerator.csproj" />
<ProjectReference Include="..\..\src\TCDev.ApiGenerator.Json\TCDev.ApiGenerator.Json.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
<None Include="wwwroot\SwaggerDarkTheme.css">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
17 changes: 1 addition & 16 deletions sample/ApiGeneratorSampleApp/ApiGeneratorSampleApI.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sample/ApiGeneratorSampleApp/ApiGeneratorSampleApp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions sample/ApiGeneratorSampleApp/Model/Car.cs
@@ -1,8 +1,6 @@
using Swashbuckle.AspNetCore.Annotations;
using System;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using TCDev.ApiGenerator.Attributes;
using TCDev.ApiGenerator.Interfaces;

Expand All @@ -17,6 +15,8 @@ public class Car : IObjectBase<Guid>
[SwaggerIgnore]
public Guid Id { get; set; } = Guid.NewGuid();


[EmailAddress]
public string Name { get; set; }

public string Description { get; set; }
Expand Down
32 changes: 12 additions & 20 deletions sample/ApiGeneratorSampleApp/Model/MinimalSample.cs
@@ -1,28 +1,20 @@
using System;
using System.Text.Json.Serialization;
// TCDev.de 2022/03/24
// ApiGeneratorSampleApI.MinimalSample.cs
// https://github.com/DeeJayTC/net-dynamic-api

using TCDev.ApiGenerator.Attributes;
using TCDev.ApiGenerator.Interfaces;

namespace ApiGeneratorSampleApI.Model
{

/// <summary>
/// This is the minimal sample, yes this is a working api ;)
/// This is the minimal sample, yes this is a working api ;)
/// </summary>
[Api("/minimal")]
public class MinimalSample : IObjectBase<int>
{
public int Id { get; set; }
public string Name { get; set; }
public int Value { get; set; }
}

[JsonConverter(typeof(JsonStringEnumConverter))]
public enum OperationEnum
{
INSERT,
UPDATE,
DELETE
}

[Api("/minimal")]
public class MinimalSample : IObjectBase<int>
{
public string Name { get; set; }
public int Value { get; set; }
public int Id { get; set; }
}
}

0 comments on commit 1505017

Please sign in to comment.