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

Adopt JSON merge patch cadl-ranch spec #5143

Merged
merged 2 commits into from
Nov 19, 2024
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
1 change: 0 additions & 1 deletion packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ function IsSpecDir {
}

$failingSpecs = @(
Join-Path 'http' 'payload' 'json-merge-patch'
Join-Path 'http' 'payload' 'pageable'
Join-Path 'http' 'resiliency' 'srv-driven'
Join-Path 'http' 'special-headers' 'conditional-request'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-payload-json-merge-patch": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/payload/json-merge-patch -p StubLibraryPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-payload-media-type": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/payload/media-type -p StubLibraryPlugin",
"commandName": "Executable",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.


using System;
using System.ClientModel;
using System.Threading.Tasks;
using NUnit.Framework;
using Payload.JsonMergePatch;
using Payload.JsonMergePatch.Models;

namespace TestProjects.CadlRanch.Tests.Http.Payload.JsonMergePatch
{
public class JsonMergePatchTests : CadlRanchTestBase
{
[CadlRanchTest]
public Task CreateResource() => Test(async (host) =>
{
var response = await new JsonMergePatchClient(host, null).CreateResourceAsync(new Resource("Madge")
{
Description = "desc",
Map = { { "key", new InnerModel { Name = "InnerMadge", Description = "innerDesc" } } },
Array = { new InnerModel { Name = "InnerMadge", Description = "innerDesc" } },
IntValue = 1,
FloatValue = 1.1f,
InnerModel = new InnerModel { Name = "InnerMadge", Description = "innerDesc" },
IntArray = { 1, 2, 3 }
});
Assert.AreEqual(200, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task UpdateOptionalResource() => Test(async (host) =>
{
var response = await new JsonMergePatchClient(host, null).UpdateOptionalResourceAsync(BinaryContent.Create(
new BinaryData(
new
{
description = (string?)null,
map = new { key = new { description = (string?)null }, key2 = (string?)null },
array = (object[]?)null,
intValue = (int?)null,
floatValue = (float?)null,
innerModel = (InnerModel?)null,
intArray = (int[]?)null
})));
Assert.AreEqual(200, response.GetRawResponse().Status);
});

[CadlRanchTest]
public Task UpdateResource() => Test(async (host) =>
{
var response = await new JsonMergePatchClient(host, null).UpdateResourceAsync(BinaryContent.Create(
new BinaryData(
new
{
description = (string?)null,
map = new { key = new { description = (string?)null }, key2 = (string?)null },
array = (object[]?)null,
intValue = (int?)null,
floatValue = (float?)null,
innerModel = (InnerModel?)null,
intArray = (int[]?)null
})));
Assert.AreEqual(200, response.GetRawResponse().Status);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Http\Payload\JsonMergePatch\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"output-folder": ".",
"namespace": "Payload.JsonMergePatch",
"library-name": "Payload.JsonMergePatch",
"use-model-reader-writer": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Payload.JsonMergePatch", "src\Payload.JsonMergePatch.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Threading.Tasks;
using Payload.JsonMergePatch.Models;

namespace Payload.JsonMergePatch
{
public partial class JsonMergePatchClient
{
public JsonMergePatchClient() : this(new Uri("http://localhost:3000"), new JsonMergePatchClientOptions()) => throw null;

public JsonMergePatchClient(Uri endpoint, JsonMergePatchClientOptions options) => throw null;

public ClientPipeline Pipeline => throw null;

public virtual ClientResult CreateResource(BinaryContent content, RequestOptions options = null) => throw null;

public virtual Task<ClientResult> CreateResourceAsync(BinaryContent content, RequestOptions options = null) => throw null;

public virtual ClientResult<Resource> CreateResource(Resource body) => throw null;

public virtual Task<ClientResult<Resource>> CreateResourceAsync(Resource body) => throw null;

public virtual ClientResult UpdateResource(BinaryContent content, RequestOptions options = null) => throw null;

public virtual Task<ClientResult> UpdateResourceAsync(BinaryContent content, RequestOptions options = null) => throw null;

public virtual ClientResult UpdateOptionalResource(BinaryContent content, RequestOptions options = null) => throw null;

public virtual Task<ClientResult> UpdateOptionalResourceAsync(BinaryContent content, RequestOptions options = null) => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <auto-generated/>

#nullable disable

using System.ClientModel.Primitives;

namespace Payload.JsonMergePatch
{
public partial class JsonMergePatchClientOptions : ClientPipelineOptions
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace Payload.JsonMergePatch.Models
{
public partial class InnerModel : IJsonModel<InnerModel>
{
void IJsonModel<InnerModel>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;

protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;

InnerModel IJsonModel<InnerModel>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;

protected virtual InnerModel JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;

BinaryData IPersistableModel<InnerModel>.Write(ModelReaderWriterOptions options) => throw null;

protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) => throw null;

InnerModel IPersistableModel<InnerModel>.Create(BinaryData data, ModelReaderWriterOptions options) => throw null;

protected virtual InnerModel PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) => throw null;

string IPersistableModel<InnerModel>.GetFormatFromOptions(ModelReaderWriterOptions options) => throw null;

public static implicit operator BinaryContent(InnerModel innerModel) => throw null;

public static explicit operator InnerModel(ClientResult result) => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// <auto-generated/>

#nullable disable

namespace Payload.JsonMergePatch.Models
{
public partial class InnerModel
{
public InnerModel() => throw null;

public string Name
{
get => throw null;
set => throw null;
}

public string Description
{
get => throw null;
set => throw null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// <auto-generated/>

#nullable disable

using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;

namespace Payload.JsonMergePatch.Models
{
public partial class Resource : IJsonModel<Resource>
{
void IJsonModel<Resource>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;

protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;

Resource IJsonModel<Resource>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;

protected virtual Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;

BinaryData IPersistableModel<Resource>.Write(ModelReaderWriterOptions options) => throw null;

protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) => throw null;

Resource IPersistableModel<Resource>.Create(BinaryData data, ModelReaderWriterOptions options) => throw null;

protected virtual Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) => throw null;

string IPersistableModel<Resource>.GetFormatFromOptions(ModelReaderWriterOptions options) => throw null;

public static implicit operator BinaryContent(Resource resource) => throw null;

public static explicit operator Resource(ClientResult result) => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// <auto-generated/>

#nullable disable

using System.Collections.Generic;

namespace Payload.JsonMergePatch.Models
{
public partial class Resource
{
public Resource(string name) => throw null;

public string Name
{
get => throw null;
set => throw null;
}

public string Description
{
get => throw null;
set => throw null;
}

public IDictionary<string, InnerModel> Map => throw null;

public IList<InnerModel> Array => throw null;

public int? IntValue
{
get => throw null;
set => throw null;
}

public float? FloatValue
{
get => throw null;
set => throw null;
}

public InnerModel InnerModel
{
get => throw null;
set => throw null;
}

public IList<int> IntArray => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// <auto-generated/>

#nullable disable

using System.Collections.Generic;

namespace Payload.JsonMergePatch.Models
{
public static partial class PayloadJsonMergePatchModelFactory
{
public static Resource Resource(string name = default, string description = default, IDictionary<string, InnerModel> map = default, IEnumerable<InnerModel> array = default, int? intValue = default, float? floatValue = default, InnerModel innerModel = default, IEnumerable<int> intArray = default) => throw null;

public static InnerModel InnerModel(string name = default, string description = default) => throw null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Payload.JsonMergePatch client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Payload.JsonMergePatch</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Payload.JsonMergePatch</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.ClientModel" Version="1.1.0-beta.4" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>
</Project>
Loading
Loading