Adopt http\parameters\basic from cadl ranch (#4241)

fixes: https://github.com/microsoft/typespec/issues/3974
This commit is contained in:
Jorge Rangel 2024-08-22 14:16:01 -05:00 коммит произвёл GitHub
Родитель ff56d83bc0
Коммит 15be039d0c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
16 изменённых файлов: 656 добавлений и 1 удалений

Просмотреть файл

@ -56,7 +56,6 @@ $failingSpecs = @(
Join-Path 'http' 'client' 'structure' 'two-operation-group'
Join-Path 'http' 'encode' 'datetime'
Join-Path 'http' 'encode' 'duration'
Join-Path 'http' 'parameters' 'basic'
Join-Path 'http' 'parameters' 'body-optionality'
Join-Path 'http' 'parameters' 'collection-format'
Join-Path 'http' 'parameters' 'spread'

Просмотреть файл

@ -40,6 +40,11 @@
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-parameters-basic": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/parameters/basic -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",

Просмотреть файл

@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.ClientModel;
using System.Threading.Tasks;
using NUnit.Framework;
using Parameters.Basic;
using Parameters.Basic.Models;
namespace TestProjects.CadlRanch.Tests.Http.Parameters.Basic
{
public class BasicParametersTests : CadlRanchTestBase
{
[CadlRanchTest]
public Task ExplicitBodySimple() => Test(async (host) =>
{
var client = new BasicClient(host, null).GetExplicitBodyClient();
var body = new User("foo");
ClientResult response = await client.SimpleAsync(body);
Assert.AreEqual(204, response.GetRawResponse().Status);
});
[CadlRanchTest]
public Task ImplicitBodySimple() => Test(async (host) =>
{
var client = new BasicClient(host, null).GetImplicitBodyClient();
var name = "foo";
ClientResult response = await client.SimpleAsync(name);
Assert.AreEqual(204, response.GetRawResponse().Status);
});
}
}

Просмотреть файл

@ -0,0 +1,6 @@
{
"output-folder": ".",
"namespace": "Parameters.Basic",
"library-name": "Parameters.Basic",
"use-model-reader-writer": true
}

Просмотреть файл

@ -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}") = "Parameters.Basic", "src\Parameters.Basic.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

Просмотреть файл

@ -0,0 +1,22 @@
// <auto-generated/>
#nullable disable
using System;
using System.ClientModel.Primitives;
namespace Parameters.Basic
{
public partial class BasicClient
{
public BasicClient() : this(new Uri("http://localhost:3000"), new BasicClientOptions()) => throw null;
public BasicClient(Uri endpoint, BasicClientOptions options) => throw null;
public ClientPipeline Pipeline => throw null;
public virtual ExplicitBody GetExplicitBodyClient() => throw null;
public virtual ImplicitBody GetImplicitBodyClient() => throw null;
}
}

Просмотреть файл

@ -0,0 +1,12 @@
// <auto-generated/>
#nullable disable
using System.ClientModel.Primitives;
namespace Parameters.Basic
{
public partial class BasicClientOptions : ClientPipelineOptions
{
}
}

Просмотреть файл

@ -0,0 +1,26 @@
// <auto-generated/>
#nullable disable
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Threading.Tasks;
using Parameters.Basic.Models;
namespace Parameters.Basic
{
public partial class ExplicitBody
{
protected ExplicitBody() => throw null;
public ClientPipeline Pipeline => throw null;
public virtual ClientResult Simple(BinaryContent content, RequestOptions options) => throw null;
public virtual Task<ClientResult> SimpleAsync(BinaryContent content, RequestOptions options) => throw null;
public virtual ClientResult Simple(User body) => throw null;
public virtual Task<ClientResult> SimpleAsync(User body) => throw null;
}
}

Просмотреть файл

@ -0,0 +1,25 @@
// <auto-generated/>
#nullable disable
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Threading.Tasks;
namespace Parameters.Basic
{
public partial class ImplicitBody
{
protected ImplicitBody() => throw null;
public ClientPipeline Pipeline => throw null;
public virtual ClientResult Simple(BinaryContent content, RequestOptions options) => throw null;
public virtual Task<ClientResult> SimpleAsync(BinaryContent content, RequestOptions options) => throw null;
public virtual ClientResult Simple(string name) => throw null;
public virtual Task<ClientResult> SimpleAsync(string name) => throw null;
}
}

Просмотреть файл

@ -0,0 +1,36 @@
// <auto-generated/>
#nullable disable
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
namespace Parameters.Basic.Models
{
public partial class SimpleRequest : IJsonModel<SimpleRequest>
{
void IJsonModel<SimpleRequest>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;
SimpleRequest IJsonModel<SimpleRequest>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;
protected virtual SimpleRequest JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;
BinaryData IPersistableModel<SimpleRequest>.Write(ModelReaderWriterOptions options) => throw null;
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) => throw null;
SimpleRequest IPersistableModel<SimpleRequest>.Create(BinaryData data, ModelReaderWriterOptions options) => throw null;
protected virtual SimpleRequest PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) => throw null;
string IPersistableModel<SimpleRequest>.GetFormatFromOptions(ModelReaderWriterOptions options) => throw null;
public static implicit operator BinaryContent(SimpleRequest simpleRequest) => throw null;
public static explicit operator SimpleRequest(ClientResult result) => throw null;
}
}

Просмотреть файл

@ -0,0 +1,16 @@
// <auto-generated/>
#nullable disable
namespace Parameters.Basic.Models
{
public partial class SimpleRequest
{
public string Name
{
get => throw null;
set => throw null;
}
}
}

Просмотреть файл

@ -0,0 +1,36 @@
// <auto-generated/>
#nullable disable
using System;
using System.ClientModel;
using System.ClientModel.Primitives;
using System.Text.Json;
namespace Parameters.Basic.Models
{
public partial class User : IJsonModel<User>
{
void IJsonModel<User>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) => throw null;
User IJsonModel<User>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;
protected virtual User JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => throw null;
BinaryData IPersistableModel<User>.Write(ModelReaderWriterOptions options) => throw null;
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) => throw null;
User IPersistableModel<User>.Create(BinaryData data, ModelReaderWriterOptions options) => throw null;
protected virtual User PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) => throw null;
string IPersistableModel<User>.GetFormatFromOptions(ModelReaderWriterOptions options) => throw null;
public static implicit operator BinaryContent(User user) => throw null;
public static explicit operator User(ClientResult result) => throw null;
}
}

Просмотреть файл

@ -0,0 +1,18 @@
// <auto-generated/>
#nullable disable
namespace Parameters.Basic.Models
{
public partial class User
{
public User(string name) => throw null;
public string Name
{
get => throw null;
set => throw null;
}
}
}

Просмотреть файл

@ -0,0 +1,13 @@
// <auto-generated/>
#nullable disable
namespace Parameters.Basic.Models
{
public static partial class ParametersBasicModelFactory
{
public static SimpleRequest SimpleRequest(string name = default) => throw null;
public static User User(string name = default) => throw null;
}
}

Просмотреть файл

@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Parameters.Basic client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Parameters.Basic</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Parameters.Basic</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.4" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,345 @@
{
"$id": "1",
"Name": "Parameters.Basic",
"ApiVersions": [],
"Enums": [],
"Models": [
{
"$id": "2",
"Kind": "model",
"Name": "SimpleRequest",
"CrossLanguageDefinitionId": "Parameters.Basic.ImplicitBody.simple.Request.anonymous",
"Usage": "Spread,Json",
"Decorators": [],
"Properties": [
{
"$id": "3",
"Name": "name",
"SerializedName": "name",
"Description": "",
"Type": {
"$id": "4",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string",
"Decorators": []
},
"IsRequired": true,
"IsReadOnly": false,
"Decorators": []
}
]
},
{
"$id": "5",
"Kind": "model",
"Name": "User",
"CrossLanguageDefinitionId": "Parameters.Basic.ExplicitBody.User",
"Usage": "Input,Json",
"Description": "This is a simple model.",
"Decorators": [],
"Properties": [
{
"$id": "6",
"Name": "name",
"SerializedName": "name",
"Description": "",
"Type": {
"$id": "7",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string",
"Decorators": []
},
"IsRequired": true,
"IsReadOnly": false,
"Decorators": []
}
]
}
],
"Clients": [
{
"$id": "8",
"Name": "BasicClient",
"Description": "Test for basic parameters cases.",
"Operations": [],
"Protocol": {
"$id": "9"
},
"Parameters": [
{
"$id": "10",
"Name": "endpoint",
"NameInRequest": "endpoint",
"Type": {
"$id": "11",
"Kind": "url",
"Name": "url",
"CrossLanguageDefinitionId": "TypeSpec.url"
},
"Location": "Uri",
"IsApiVersion": false,
"IsResourceParameter": false,
"IsContentType": false,
"IsRequired": true,
"IsEndpoint": true,
"SkipUrlEncoding": false,
"Explode": false,
"Kind": "Client",
"DefaultValue": {
"$id": "12",
"Type": {
"$id": "13",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string"
},
"Value": "http://localhost:3000"
}
}
],
"Decorators": []
},
{
"$id": "14",
"Name": "ExplicitBody",
"Operations": [
{
"$id": "15",
"Name": "simple",
"ResourceName": "ExplicitBody",
"Accessibility": "public",
"Parameters": [
{
"$id": "16",
"Name": "endpoint",
"NameInRequest": "endpoint",
"Type": {
"$id": "17",
"Kind": "url",
"Name": "url",
"CrossLanguageDefinitionId": "TypeSpec.url"
},
"Location": "Uri",
"IsApiVersion": false,
"IsResourceParameter": false,
"IsContentType": false,
"IsRequired": true,
"IsEndpoint": true,
"SkipUrlEncoding": false,
"Explode": false,
"Kind": "Client",
"DefaultValue": {
"$id": "18",
"Type": {
"$id": "19",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string"
},
"Value": "http://localhost:3000"
}
},
{
"$id": "20",
"Name": "contentType",
"NameInRequest": "Content-Type",
"Description": "Body parameter's content type. Known values are application/json",
"Type": {
"$id": "21",
"Kind": "constant",
"ValueType": {
"$id": "22",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string",
"Decorators": []
},
"Value": "application/json",
"Decorators": []
},
"Location": "Header",
"IsApiVersion": false,
"IsContentType": true,
"IsEndpoint": false,
"Explode": false,
"IsRequired": true,
"Kind": "Constant",
"Decorators": []
},
{
"$id": "23",
"Name": "body",
"NameInRequest": "body",
"Type": {
"$ref": "5"
},
"Location": "Body",
"IsApiVersion": false,
"IsContentType": false,
"IsEndpoint": false,
"Explode": false,
"IsRequired": true,
"Kind": "Method",
"Decorators": []
}
],
"Responses": [
{
"$id": "24",
"StatusCodes": [
204
],
"BodyMediaType": "Json",
"Headers": [],
"IsErrorResponse": false
}
],
"HttpMethod": "PUT",
"RequestBodyMediaType": "Json",
"Uri": "{endpoint}",
"Path": "/parameters/basic/explicit-body/simple",
"RequestMediaTypes": [
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true,
"CrossLanguageDefinitionId": "Parameters.Basic.ExplicitBody.simple",
"Decorators": []
}
],
"Protocol": {
"$id": "25"
},
"Parent": "BasicClient",
"Parameters": [
{
"$ref": "16"
}
],
"Decorators": []
},
{
"$id": "26",
"Name": "ImplicitBody",
"Operations": [
{
"$id": "27",
"Name": "simple",
"ResourceName": "ImplicitBody",
"Accessibility": "public",
"Parameters": [
{
"$id": "28",
"Name": "endpoint",
"NameInRequest": "endpoint",
"Type": {
"$id": "29",
"Kind": "url",
"Name": "url",
"CrossLanguageDefinitionId": "TypeSpec.url"
},
"Location": "Uri",
"IsApiVersion": false,
"IsResourceParameter": false,
"IsContentType": false,
"IsRequired": true,
"IsEndpoint": true,
"SkipUrlEncoding": false,
"Explode": false,
"Kind": "Client",
"DefaultValue": {
"$id": "30",
"Type": {
"$id": "31",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string"
},
"Value": "http://localhost:3000"
}
},
{
"$id": "32",
"Name": "contentType",
"NameInRequest": "Content-Type",
"Description": "Body parameter's content type. Known values are application/json",
"Type": {
"$id": "33",
"Kind": "constant",
"ValueType": {
"$id": "34",
"Kind": "string",
"Name": "string",
"CrossLanguageDefinitionId": "TypeSpec.string",
"Decorators": []
},
"Value": "application/json",
"Decorators": []
},
"Location": "Header",
"IsApiVersion": false,
"IsContentType": true,
"IsEndpoint": false,
"Explode": false,
"IsRequired": true,
"Kind": "Constant",
"Decorators": []
},
{
"$id": "35",
"Name": "simpleRequest",
"NameInRequest": "simpleRequest",
"Type": {
"$ref": "2"
},
"Location": "Body",
"IsApiVersion": false,
"IsContentType": false,
"IsEndpoint": false,
"Explode": false,
"IsRequired": true,
"Kind": "Spread",
"Decorators": []
}
],
"Responses": [
{
"$id": "36",
"StatusCodes": [
204
],
"BodyMediaType": "Json",
"Headers": [],
"IsErrorResponse": false
}
],
"HttpMethod": "PUT",
"RequestBodyMediaType": "Json",
"Uri": "{endpoint}",
"Path": "/parameters/basic/implicit-body/simple",
"RequestMediaTypes": [
"application/json"
],
"BufferResponse": true,
"GenerateProtocolMethod": true,
"GenerateConvenienceMethod": true,
"CrossLanguageDefinitionId": "Parameters.Basic.ImplicitBody.simple",
"Decorators": []
}
],
"Protocol": {
"$id": "37"
},
"Parent": "BasicClient",
"Parameters": [
{
"$ref": "28"
}
],
"Decorators": []
}
]
}