Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/90 known types #165

Merged
merged 52 commits into from
Apr 20, 2023
Merged

Feature/90 known types #165

merged 52 commits into from
Apr 20, 2023

Conversation

Sevitas
Copy link
Contributor

@Sevitas Sevitas commented Oct 31, 2022

Motivation

Fixes #90. Scenarios 1 and 2.

Checklist

  • Code follows coding conventions held in this repo
  • Automated tests have been added
  • Tests are passing
  • Docs have been updated (if applicable)
  • Temporary settings (e.g. variables used during development and testing) have been reverted to defaults

How to test

Test that models are generated for senarios 1 and 2 and everything else works without a change.

@Sevitas Sevitas requested a review from a team as a code owner October 31, 2022 05:59
# Conflicts:
#	src/Kontent.Ai.ModelGenerator.Core/CodeGeneratorBase.cs
#	src/Kontent.Ai.ModelGenerator.Core/Common/ClassCodeGeneratorFactory.cs
#	src/Kontent.Ai.ModelGenerator.Core/Common/ClassDefinition.cs
#	src/Kontent.Ai.ModelGenerator.Core/Common/Property.cs
#	src/Kontent.Ai.ModelGenerator.Core/Configuration/CodeGeneratorOptions.cs
#	src/Kontent.Ai.ModelGenerator.Core/DeliveryCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/BaseClassCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/ClassCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/DeliveryClassCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/DeliveryClassCodeGeneratorBase.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/ManagementClassCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Generators/Class/PartialClassCodeGenerator.cs
#	src/Kontent.Ai.ModelGenerator.Core/Helpers/TextHelpers.cs
#	src/Kontent.Ai.ModelGenerator/Program.cs
#	src/Kontent.Ai.ModelGenerator/ValidationExtensions.cs
#	test/Kontent.Ai.ModelGenerator.Tests/CodeGeneratorTestsBase.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Common/ClassCodeGeneratorFactoryTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Common/PropertyTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/DeliveryCodeGeneratorTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Generators/Class/BaseClassCodeGeneratorTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Generators/Class/DeliveryClassCodeGeneratorTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Generators/Class/ManagementClassCodeGeneratorTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Helpers/ManagementElementHelperTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/Helpers/TextHelpersTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/ManagementCodeGeneratorTests.cs
#	test/Kontent.Ai.ModelGenerator.Tests/TestHelper.cs
#	test/Kontent.Ai.ModelGenerator.Tests/ValidationExtensionsTests.cs
# Conflicts:
#	test/Kontent.Ai.ModelGenerator.Tests/Kontent.Ai.ModelGenerator.Tests.csproj
@Simply007
Copy link
Contributor

Please adjust https://github.com/kontent-ai/model-generator-net/blob/feature/90_known_types/src/Kontent.Ai.ModelGenerator/appSettings.json to respect new options and cover related tests if necessary.

@Simply007
Copy link
Contributor

I would emphasize the Api key with the example for the section: https://github.com/kontent-ai/model-generator-net/tree/feature/90_known_types#customizing-models---extended-delivery-models

Copy link
Contributor

@Simply007 Simply007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casing problem

By running .\KontentModelGenerator.exe -p ABC -e true -k XYZ for project 6d7f2b4b-9432-012e-f6be-c9feb74c3912 (@Sevitas - you are invited) => it is because faulty casing -> the original property is JustMessages -> the typed one is JustmessagesTypes and trying to load from Justmessages (see the m vs. M).


Opt in for IContentItem

  1. I also got for *.Generated. inheritance from IContentItem. I would add this as non-default behavior. => I would extend the structuredmodel argument with another enum flag i.e. linkedItems (I am open to another name) because it probably (not sure) applies on the subPages element too.

  2. Introduce IContentItem into the DAPI SDK Abstractions (I think the minor release is fine) and do not generate it.

@Sevitas Sevitas requested a review from Simply007 March 9, 2023 11:36
Copy link
Contributor

@Simply007 Simply007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • rename the extendeddelivermodels - it is delivery everywhere we use it

  • I am getting a warnings fron self-contained.ps1

    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\ServiceCollectionExtensions.cs(24,9): warning IL2026: Using member 'Microsoft.Extensions.Configur
    ation.ConfigurationBinder.Bind(IConfiguration, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. C
    annot statically analyze the type of instance so its members may be trimmed. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGen 
    erator.csproj]
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Options\ArgHelpers.cs(97,32): warning IL2070: 'this' argument does not satisfy 'DynamicallyAccess 
    edMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The parameter 'type' of method 'Kontent.Ai.ModelGenerator.Options.ArgHelpers.ProgramO 
    ptionsData.ProgramOptionsData(Type, String)' does not have matching annotations. The source value must declare at least the same requirements as those declared 
     on the target location it is assigned to. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Options\ArgHelpers.cs(105,32): warning IL2070: 'this' argument does not satisfy 'DynamicallyAcces 
    sedMemberTypes.PublicProperties' in call to 'System.Type.GetProperties()'. The parameter 'optionsType' of method 'Kontent.Ai.ModelGenerator.Options.ArgHelpers. 
    ProgramOptionsData.ProgramOptionsData(Type, Type, String)' does not have matching annotations. The source value must declare at least the same requirements as  
    those declared on the target location it is assigned to. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]       
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Program.cs(38,13): warning IL2026: Using member 'Microsoft.Extensions.DependencyInjection.Options 
    ConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, IConfiguration)' which has 'RequiresUnreferencedCodeAttribute' can break funct 
    ionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved. [C:\projects\mod 
    el-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
      Kontent.Ai.ModelGenerator -> C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\bin\Release\net6.0\linux-x64\KontentModelGenerator.dll
      Optimizing assemblies for size. This process might take a while.
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Program.cs(38,13): Trim analysis warning IL2026: Kontent.Ai.ModelGenerator.Program.<Main>d__0.Mov
    eNext(): Using member 'Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, IConfig
    uration)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their membe 
    rs trimmed. Ensure all required members are preserved. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Options\ArgHelpers.cs(105,13): Trim analysis warning IL2070: Kontent.Ai.ModelGenerator.Options.Ar 
    gHelpers.ProgramOptionsData.ProgramOptionsData(Type, Type, String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call  
    to 'System.Type.GetProperties()'. The parameter 'optionsType' of method 'Kontent.Ai.ModelGenerator.Options.ArgHelpers.ProgramOptionsData.ProgramOptionsData(Typ 
    e, Type, String)' does not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it  
    is assigned to. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Options\ArgHelpers.cs(97,13): Trim analysis warning IL2070: Kontent.Ai.ModelGenerator.Options.Arg 
    Helpers.ProgramOptionsData.ProgramOptionsData(Type, String): 'this' argument does not satisfy 'DynamicallyAccessedMemberTypes.PublicProperties' in call to 'Sys 
    tem.Type.GetProperties()'. The parameter 'type' of method 'Kontent.Ai.ModelGenerator.Options.ArgHelpers.ProgramOptionsData.ProgramOptionsData(Type, String)' do 
    es not have matching annotations. The source value must declare at least the same requirements as those declared on the target location it is assigned to. [C:\ 
    projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\ServiceCollectionExtensions.cs(24,9): Trim analysis warning IL2026: Kontent.Ai.ModelGenerator.Ser 
    viceCollectionExtensions.LoadOptionsConfiguration(IServiceCollection, IConfiguration, String): Using member 'Microsoft.Extensions.Configuration.ConfigurationBi 
    nder.Bind(IConfiguration, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Cannot statically anal 
    yze the type of instance so its members may be trimmed. [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]        
    ILLink : Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataSet.WriteXmlSch 
    ema(DataSet, XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.GetSchema uses TypeDescr 
    iptor and XmlSerialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model- 
    generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    ILLink : Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataSet.Read 
    XmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.ReadXml uses  
    XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model-generator-n 
    et\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    ILLink : Trim analysis warning IL2026: System.Data.DataSet.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataSet.Wri 
    teXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataSet.WriteXml uses XmlSerial 
    ization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model-generator-net\src\Ko 
    ntent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    ILLink : Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.GetSchema(): Using member 'System.Data.DataTable.GetXmlS 
    chema()' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.GetSchema uses TypeDescriptor and XmlS 
    erialization underneath which are not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model-generator-net\ 
    src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    ILLink : Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.ReadXml(XmlReader): Using member 'System.Data.DataTable. 
    ReadXmlSerializableInternal(XmlReader)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.ReadXml 
     uses XmlSerialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model-gener 
    ator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    ILLink : Trim analysis warning IL2026: System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter): Using member 'System.Data.DataTable 
    .WriteXmlInternal(XmlWriter)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. DataTable.WriteXml uses Xml 
    Serialization underneath which is not trimming safe. Members from serialized types may be trimmed if not referenced directly. [C:\projects\model-generator-net\ 
    src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\anglesharp\0.17.1\lib\netstandard2.0\AngleSharp.dll : warning IL2104: Assembly 'AngleSharp' produced trim warnings. Fo 
    r more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]  
    C:\Users\OndrejChrastina\.nuget\packages\humanizer.core\2.14.1\lib\net6.0\Humanizer.dll : warning IL2104: Assembly 'Humanizer' produced trim warnings. For more
     information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]        
    C:\Users\OndrejChrastina\.nuget\packages\kontent.ai.delivery\17.4.0\lib\net6.0\Kontent.Ai.Delivery.dll : warning IL2104: Assembly 'Kontent.Ai.Delivery' produce 
    d trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.Mode 
    lGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\kontent.ai.management\4.4.0\lib\net6.0\Kontent.Ai.Management.dll : warning IL2104: Assembly 'Kontent.Ai.Management' pr 
    oduced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai 
    .ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\microsoft.codeanalysis.common\4.5.0\lib\netcoreapp3.1\Microsoft.CodeAnalysis.dll : warning IL2104: Assembly 'Microsoft 
    .CodeAnalysis' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGen 
    erator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\microsoft.codeanalysis.csharp.workspaces\4.5.0\lib\netcoreapp3.1\Microsoft.CodeAnalysis.CSharp.Workspaces.dll : warnin 
    g IL2104: Assembly 'Microsoft.CodeAnalysis.CSharp.Workspaces' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\proje 
    cts\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\microsoft.codeanalysis.workspaces.common\4.5.0\lib\netcoreapp3.1\Microsoft.CodeAnalysis.Workspaces.dll : warning IL210 
    4: Assembly 'Microsoft.CodeAnalysis.Workspaces' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-gene 
    rator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll : warning IL2104: Assembly 'Newtonsoft.Json' produced tr 
    im warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGen 
    erator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\scrutor\4.2.0\lib\net6.0\Scrutor.dll : warning IL2104: Assembly 'Scrutor' produced trim warnings. For more information 
     see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\system.composition.convention\6.0.0\lib\net6.0\System.Composition.Convention.dll : warning IL2104: Assembly 'System.Co 
    mposition.Convention' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.M 
    odelGenerator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\system.composition.hosting\6.0.0\lib\net6.0\System.Composition.Hosting.dll : warning IL2104: Assembly 'System.Composit 
    ion.Hosting' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.ModelGener 
    ator\Kontent.Ai.ModelGenerator.csproj]
    C:\Users\OndrejChrastina\.nuget\packages\system.composition.typedparts\6.0.0\lib\net6.0\System.Composition.TypedParts.dll : warning IL2104: Assembly 'System.Co 
    mposition.TypedParts' produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [C:\projects\model-generator-net\src\Kontent.Ai.M 
    odelGenerator\Kontent.Ai.ModelGenerator.csproj]
  • I would use FirstOrDefault also for AtMost = 1 linked items - what do you think?

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Simply007

This comment was marked as duplicate.

@Sevitas Sevitas requested a review from Simply007 April 6, 2023 13:21
README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
Copy link
Contributor

@Simply007 Simply007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
tested locally and from nuget

@Sevitas Sevitas merged commit 5a0b662 into master Apr 20, 2023
@Sevitas Sevitas deleted the feature/90_known_types branch April 20, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IEnumerable<object> Generated for known types
3 participants