Skip to content

Commit

Permalink
Merge pull request #187 from atc-net/feature/dictionary_support
Browse files Browse the repository at this point in the history
Adding support for dictionaries in models
  • Loading branch information
perkops authored Oct 12, 2023
2 parents fbe4569 + 90a1b74 commit f9ec8e1
Show file tree
Hide file tree
Showing 33 changed files with 180 additions and 87 deletions.
19 changes: 19 additions & 0 deletions sample/Demo.ApiDesign/SingleFileVersion/Api.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,31 @@ components:
nullable: true
oneOf:
- $ref: '#/components/schemas/Address'
tags:
type: object
additionalProperties:
type: string
desiredProperties1:
type: object
additionalProperties:
type: string
desiredProperties2:
type: object
nullable: true
additionalProperties:
type: string
desiredProperties3:
type: object
nullable: true
additionalProperties:
type: integer
required:
- firstName
- lastName
- myDateTime
- email
- gender
- tags
CreateUsersRequest:
description: A list of users.
type: array
Expand Down
6 changes: 3 additions & 3 deletions sample/src/Demo.Api.Full/Demo.Api.Full.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.Rest" Version="2.0.349" />
<PackageReference Include="Atc.Rest.Extended" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.Rest" Version="2.0.360" />
<PackageReference Include="Atc.Rest.Extended" Version="2.0.360" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//------------------------------------------------------------------------------
// This code was auto-generated by ApiGenerator 2.0.265.35674.
// This code was auto-generated by ApiGenerator 2.0.413.49179.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
Expand All @@ -9,7 +9,7 @@ namespace Demo.Api.Generated.Contracts.Users;
/// <summary>
/// Request to create a user.
/// </summary>
[GeneratedCode("ApiGenerator", "2.0.265.35674")]
[GeneratedCode("ApiGenerator", "2.0.413.49179")]
public class CreateUserRequest
{
[Required]
Expand Down Expand Up @@ -50,7 +50,16 @@ public class CreateUserRequest

public Address? MyNullableAddress { get; set; }

[Required]
public Dictionary<string, string> Tags { get; set; }

public Dictionary<string, string> DesiredProperties1 { get; set; }

public Dictionary<string, string>? DesiredProperties2 { get; set; }

public Dictionary<string, int>? DesiredProperties3 { get; set; }

/// <inheritdoc />
public override string ToString()
=> $"{nameof(FirstName)}: {FirstName}, {nameof(LastName)}: {LastName}, {nameof(MyNullableDateTime)}: ({MyNullableDateTime}), {nameof(MyDateTime)}: ({MyDateTime}), {nameof(Email)}: {Email}, {nameof(Homepage)}: ({Homepage}), {nameof(Gender)}: {Gender}, {nameof(MyNullableAddress)}: ({MyNullableAddress})";
=> $"{nameof(FirstName)}: {FirstName}, {nameof(LastName)}: {LastName}, {nameof(MyNullableDateTime)}: ({MyNullableDateTime}), {nameof(MyDateTime)}: ({MyDateTime}), {nameof(Email)}: {Email}, {nameof(Homepage)}: ({Homepage}), {nameof(Gender)}: {Gender}, {nameof(MyNullableAddress)}: ({MyNullableAddress}), {nameof(Tags)}: ({Tags}), {nameof(DesiredProperties1)}: ({DesiredProperties1}), {nameof(DesiredProperties2)}: ({DesiredProperties2}), {nameof(DesiredProperties3)}: ({DesiredProperties3})";
}
6 changes: 3 additions & 3 deletions sample/src/Demo.Api.Generated/Demo.Api.Generated.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -25,8 +25,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.Rest" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.Rest" Version="2.0.360" />
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions sample/src/Demo.Api.Generated/Resources/ApiSpecification.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -779,12 +779,31 @@ components:
nullable: true
oneOf:
- $ref: '#/components/schemas/Address'
tags:
type: object
additionalProperties:
type: string
desiredProperties1:
type: object
additionalProperties:
type: string
desiredProperties2:
type: object
nullable: true
additionalProperties:
type: string
desiredProperties3:
type: object
nullable: true
additionalProperties:
type: integer
required:
- firstName
- lastName
- myDateTime
- email
- gender
- tags
CreateUsersRequest:
description: A list of users.
type: array
Expand Down
8 changes: 4 additions & 4 deletions sample/src/Demo.Api/Demo.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -16,9 +16,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.Rest" Version="2.0.349" />
<PackageReference Include="Atc.Rest.Extended" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.Rest" Version="2.0.360" />
<PackageReference Include="Atc.Rest.Extended" Version="2.0.360" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.9" />
Expand Down
4 changes: 2 additions & 2 deletions sample/src/Demo.Domain/Demo.Domain.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand All @@ -20,7 +20,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="11.6.0" />
<PackageReference Include="FluentValidation" Version="11.7.1" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions sample/test/Demo.Api.Tests/Demo.Api.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.XUnit" Version="2.0.349" />
<PackageReference Include="Atc.XUnit" Version="2.0.360" />
<PackageReference Include="AutoFixture" Version="4.18.0" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 7 additions & 7 deletions sample/test/Demo.Domain.Tests/Demo.Domain.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.XUnit" Version="2.0.349" />
<PackageReference Include="Atc.XUnit" Version="2.0.360" />
<PackageReference Include="AutoFixture" Version="4.18.0" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="4.18.0" />
<PackageReference Include="AutoFixture.Xunit2" Version="4.18.0" />
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.349" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.360" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.360" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.360" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.Rest" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.Rest" Version="2.0.360" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.OpenApi" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.OpenApi" Version="2.0.360" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ private static List<PropertyParameters> ExtractPropertiesParameters(
dataType = openApiParameter.AnyOf.Count == 1
? openApiParameter.AnyOf[0].GetDataType()
: openApiParameter.GetDataType();

if ("Object".Equals(dataType, StringComparison.Ordinal) &&
openApiParameter.AdditionalProperties is not null)
{
// A defined Object with AdditionalProperties is a Dictionary - https://swagger.io/docs/specification/data-models/dictionaries/
var additionalPropertiesDataType = openApiParameter.AdditionalProperties.GetDataType();
dataType = $"Dictionary<string, {additionalPropertiesDataType}>";
}
}

var isSimpleType = useListForDataType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.349" />
<PackageReference Include="Atc.OpenApi" Version="2.0.349" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.6" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.6" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.CodeDocumentation" Version="2.0.360" />
<PackageReference Include="Atc.OpenApi" Version="2.0.360" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.9" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,8 @@ private void ValidateSchemas(
{
case OpenApiDataTypeConstants.Object:
{
if (!value.IsObjectReferenceTypeDeclared())
if (!value.IsObjectReferenceTypeDeclared() &&
value.AdditionalProperties is null)
{
logItems.Add(logItemFactory.Create(LogCategoryType.Error, ValidationRuleNameConstants.Schema10, $"Implicit object definition on property '{key}' in type '{schema.Reference.ReferenceV3}' is not supported."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public async Task<Version> GetAtcApiGeneratorVersion()
{
var version = await atcApiNugetClient.RetrieveLatestVersionForPackageId(
"Atc.Rest.ApiGenerator",
CancellationToken.None) ?? new Version(2, 0, 313, 0);
CancellationToken.None) ?? new Version(2, 0, 360, 0);

var assemblyVersion = CliHelper.GetCurrentVersion();

return assemblyVersion.GreaterThan(version)
? assemblyVersion
: new Version(2, 0, 313, 0);
: new Version(2, 0, 360, 0);
}

public async Task<IList<(string PackageId, string PackageVersion, string? SubElements)>> GetPackageReferencesBaseLineForHostProject(
Expand Down
14 changes: 7 additions & 7 deletions src/Atc.Rest.ApiGenerator/Atc.Rest.ApiGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.349" />
<PackageReference Include="Atc.CodeAnalysis.CSharp" Version="2.0.349" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.349" />
<PackageReference Include="Atc.DotNet" Version="2.0.349" />
<PackageReference Include="Atc.OpenApi" Version="2.0.349" />
<PackageReference Include="Atc" Version="2.0.360" />
<PackageReference Include="Atc.CodeAnalysis.CSharp" Version="2.0.360" />
<PackageReference Include="Atc.Console.Spectre" Version="2.0.360" />
<PackageReference Include="Atc.DotNet" Version="2.0.360" />
<PackageReference Include="Atc.OpenApi" Version="2.0.360" />
<PackageReference Include="Atc.Rest.Client" Version="1.0.55" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.6" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit f9ec8e1

Please sign in to comment.