Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
shell: bash
run: dotnet build ./all.csproj -f net${{ matrix.dotnet-version }}.0

- name: Check for breaking API changes
shell: bash
run: dotnet build src/Yamlify/Yamlify.csproj --no-restore -warnaserror:RS0016,RS0017

- name: Run tests
shell: bash
run: dotnet test ./all.csproj /p:BuildTestsOnly=true --no-build -f net${{ matrix.dotnet-version }}.0 -- RunConfiguration.MaxCpuCount=1
49 changes: 49 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<Project>

<PropertyGroup>
<!-- Common build settings -->
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup>
<!-- Package metadata -->
<Version Condition="$(Version) == ''">0.0.0</Version>
<Product>Yamlify</Product>
<Authors>SwissLife-OSS</Authors>
<Company>Swiss Life</Company>
<Copyright>Copyright © $(Company) $([System.DateTime]::Now.Year)</Copyright>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/SwissLife-OSS/Yamlify</PackageProjectUrl>
<PackageReleaseNotes>Release notes: https://github.com/SwissLife-OSS/Yamlify/releases/$(Version)</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup>
<!-- Source Link and symbols -->
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<RepositoryUrl>https://github.com/SwissLife-OSS/Yamlify.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
22 changes: 11 additions & 11 deletions src/Yamlify.SourceGenerator/YamlSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static bool IsCandidateClass(SyntaxNode node)
var indentSequenceItems = true;
var ignoreNullValues = false;
var ignoreEmptyObjects = false;
var discriminatorPosition = DiscriminatorPositionMode.Ordered;
var discriminatorPosition = DiscriminatorPositionMode.PropertyOrder;

foreach (var attributeData in classSymbol.GetAttributes())
{
Expand Down Expand Up @@ -248,7 +248,7 @@ private static string GenerateContextSource(ContextToGenerate ctx, Compilation c
sb.AppendLine();
sb.AppendLine("using System;");
sb.AppendLine("using System.Collections.Generic;");
sb.AppendLine("using Yamlify.Core;");
sb.AppendLine("using Yamlify;");
sb.AppendLine("using Yamlify.Serialization;");
sb.AppendLine();

Expand Down Expand Up @@ -369,7 +369,7 @@ private static void GenerateTypeInfoMethod(StringBuilder sb, TypeToGenerate type

sb.AppendLine($" properties.Add(new YamlPropertyInfo<{fullTypeName}, {propTypeName}>(");
sb.AppendLine($" name: \"{propName}\",");
sb.AppendLine($" yamlPropertyName: \"{yamlName}\",");
sb.AppendLine($" serializedName: \"{yamlName}\",");

if (prop.GetMethod is not null)
{
Expand Down Expand Up @@ -1481,11 +1481,11 @@ private static void GenerateWriteMethod(StringBuilder sb, TypeToGenerate type, I

// Write discriminator at the beginning if:
// 1. DiscriminatorPosition.First is configured, OR
// 2. DiscriminatorPosition.Ordered is configured but there's no matching property to attach the order to
// 2. DiscriminatorPosition.PropertyOrder is configured but there's no matching property to attach the order to
if (discriminatorPropertyName is not null && discriminatorValue is not null)
{
var shouldWriteDiscriminatorFirst = discriminatorPosition == DiscriminatorPositionMode.First
|| (discriminatorPosition == DiscriminatorPositionMode.Ordered && !discriminatorHasMatchingProperty);
|| (discriminatorPosition == DiscriminatorPositionMode.PropertyOrder && !discriminatorHasMatchingProperty);

if (shouldWriteDiscriminatorFirst)
{
Expand Down Expand Up @@ -1552,7 +1552,7 @@ private static void GenerateWriteMethod(StringBuilder sb, TypeToGenerate type, I
if (isDiscriminatorProperty)
{
// When DiscriminatorPosition.First (or no matching property), discriminator was already written - skip
// When DiscriminatorPosition.Ordered AND there IS a matching property, write the discriminator at this position
// When DiscriminatorPosition.PropertyOrder AND there IS a matching property, write the discriminator at this position
if (discriminatorPosition == DiscriminatorPositionMode.First || !discriminatorHasMatchingProperty)
{
continue;
Expand Down Expand Up @@ -2000,7 +2000,7 @@ private static void GeneratePropertyWrite(StringBuilder sb, string propName, ITy
sb.AppendLine($"{indent}{{");
sb.AppendLine($"{indent2}writer.WriteNull();");
sb.AppendLine($"{indent}}}");
sb.AppendLine($"{indent}else if (YamlSerializerOptions.IsAlreadySerialized(value.{propName}))");
sb.AppendLine($"{indent}else if (YamlSerializerOptions.CurrentResolver?.IsCycleReference(value.{propName}) == true)");
sb.AppendLine($"{indent}{{");
sb.AppendLine($"{indent2}// Circular reference detected - write null to break the cycle");
sb.AppendLine($"{indent2}writer.WriteNull();");
Expand Down Expand Up @@ -3088,7 +3088,7 @@ private static void GenerateCollectionWrite(StringBuilder sb, string propName, I
// Use flow style for empty collections to output [] instead of nothing
sb.AppendLine($" if (value.{propName} is System.Collections.ICollection {{ Count: 0 }})");
sb.AppendLine(" {");
sb.AppendLine(" writer.WriteSequenceStart(Yamlify.Core.CollectionStyle.Flow);");
sb.AppendLine(" writer.WriteSequenceStart(Yamlify.CollectionStyle.Flow);");
sb.AppendLine(" writer.WriteSequenceEnd();");
sb.AppendLine(" }");
sb.AppendLine(" else");
Expand Down Expand Up @@ -3203,7 +3203,7 @@ private static void GenerateElementWrite(StringBuilder sb, string varName, IType
sb.AppendLine($"{indent}{{");
sb.AppendLine($"{indent} writer.WriteNull();");
sb.AppendLine($"{indent}}}");
sb.AppendLine($"{indent}else if (YamlSerializerOptions.IsAlreadySerialized({varName}))");
sb.AppendLine($"{indent}else if (YamlSerializerOptions.CurrentResolver?.IsCycleReference({varName}) == true)");
sb.AppendLine($"{indent}{{");
sb.AppendLine($"{indent} // Circular reference detected - write null to break the cycle");
sb.AppendLine($"{indent} writer.WriteNull();");
Expand Down Expand Up @@ -3432,7 +3432,7 @@ public ContextToGenerate(
bool indentSequenceItems = true,
bool ignoreNullValues = false,
bool ignoreEmptyObjects = false,
DiscriminatorPositionMode discriminatorPosition = DiscriminatorPositionMode.Ordered)
DiscriminatorPositionMode discriminatorPosition = DiscriminatorPositionMode.PropertyOrder)
{
ClassName = className;
Namespace = ns;
Expand Down Expand Up @@ -3487,7 +3487,7 @@ internal enum DiscriminatorPositionMode
/// <summary>
/// The discriminator property is written according to its YamlPropertyOrder or declaration order.
/// </summary>
Ordered = 0,
PropertyOrder = 0,

/// <summary>
/// The discriminator property is always written first.
Expand Down
4 changes: 1 addition & 3 deletions src/Yamlify.SourceGenerator/Yamlify.SourceGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
<ImplicitUsings>disable</ImplicitUsings>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IsRoslynComponent>true</IsRoslynComponent>

<!-- Package metadata - not published separately, bundled with Yamlify -->
<!-- Not published separately, bundled with Yamlify -->
<IsPackable>false</IsPackable>

<!-- Suppress analyzer release tracking warning (bundled with main package) -->
Expand Down
22 changes: 22 additions & 0 deletions src/Yamlify/Common/CollectionStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Yamlify;

/// <summary>
/// Specifies the collection style used in YAML presentation.
/// </summary>
public enum CollectionStyle : byte
{
/// <summary>
/// Any style (for reader) or auto-detect best style (for writer).
/// </summary>
Any = 0,

/// <summary>
/// Block style using indentation.
/// </summary>
Block,

/// <summary>
/// Flow style using explicit indicators ([], {}).
/// </summary>
Flow
}
2 changes: 1 addition & 1 deletion src/Yamlify/Core/Mark.cs → src/Yamlify/Common/Mark.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Yamlify.Core;
namespace Yamlify;

/// <summary>
/// Represents a position within a YAML stream, including line and column information.
Expand Down
37 changes: 37 additions & 0 deletions src/Yamlify/Common/ScalarStyle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
namespace Yamlify;

/// <summary>
/// Specifies the scalar style used in YAML presentation.
/// </summary>
public enum ScalarStyle : byte
{
/// <summary>
/// Any style (for reader) or auto-detect best style (for writer).
/// </summary>
Any = 0,

/// <summary>
/// Plain (unquoted) scalar style.
/// </summary>
Plain,

/// <summary>
/// Single-quoted scalar style ('value').
/// </summary>
SingleQuoted,

/// <summary>
/// Double-quoted scalar style ("value").
/// </summary>
DoubleQuoted,

/// <summary>
/// Literal block scalar style (|).
/// </summary>
Literal,

/// <summary>
/// Folded block scalar style (>).
/// </summary>
Folded
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Yamlify.Core;
namespace Yamlify;

/// <summary>
/// Specifies the type of YAML token encountered by the <see cref="Utf8YamlReader"/>.
Expand Down
79 changes: 0 additions & 79 deletions src/Yamlify/Core/YamlStyles.cs

This file was deleted.

Loading