Skip to content

Commit

Permalink
fix: first batch of broken references in unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Feb 6, 2025
1 parent ca80001 commit fbc9d63
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 340 deletions.
111 changes: 35 additions & 76 deletions tests/Kiota.Builder.Tests/ContentTypeMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.Interfaces;
using Microsoft.OpenApi.Models.References;
using Moq;
using Xunit;

Expand Down Expand Up @@ -82,22 +83,6 @@ public void Dispose()
[Theory]
public void GeneratesTheRightReturnTypeBasedOnContentAndStatus(string contentType, string statusCode, bool addModel, string acceptedContentType, string returnType)
{
var myObjectSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
};
var document = new OpenApiDocument
{
Paths = new OpenApiPaths
Expand All @@ -112,7 +97,7 @@ public void GeneratesTheRightReturnTypeBasedOnContentAndStatus(string contentTyp
[statusCode] = new OpenApiResponse {
Content = {
[contentType] = new OpenApiMediaType {
Schema = addModel ? myObjectSchema : null
Schema = addModel ? new OpenApiSchemaReference("myobject") : null
}
}
},
Expand All @@ -125,11 +110,23 @@ public void GeneratesTheRightReturnTypeBasedOnContentAndStatus(string contentTyp
{
Schemas = new Dictionary<string, IOpenApiSchema> {
{
"myobject", myObjectSchema
"myobject", new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
}
}
}
}
};
document.RegisterComponents();
document.SetReferenceHostDocument();
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(
mockLogger.Object,
Expand Down Expand Up @@ -175,22 +172,6 @@ public void GeneratesTheRightReturnTypeBasedOnContentAndStatus(string contentTyp
[Theory]
public void GeneratesTheRightParameterTypeBasedOnContentAndStatus(string contentType, bool addModel, string acceptedContentType, string parameterType)
{
var myObjectSchema = new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
};
var document = new OpenApiDocument
{
Paths = new OpenApiPaths
Expand All @@ -203,7 +184,7 @@ public void GeneratesTheRightParameterTypeBasedOnContentAndStatus(string content
RequestBody = new OpenApiRequestBody {
Content = {
[contentType] = new OpenApiMediaType {
Schema = addModel ? myObjectSchema : null
Schema = addModel ? new OpenApiSchemaReference("myobject") : null
}
}
},
Expand All @@ -219,11 +200,23 @@ public void GeneratesTheRightParameterTypeBasedOnContentAndStatus(string content
{
Schemas = new Dictionary<string, IOpenApiSchema> {
{
"myobject", myObjectSchema
"myobject", new OpenApiSchema
{
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
}
}
}
}
};
document.RegisterComponents();
document.SetReferenceHostDocument();
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(
mockLogger.Object,
Expand Down Expand Up @@ -267,21 +260,7 @@ public void GeneratesTheRightAcceptHeaderBasedOnContentAndStatus(string contentM
{
["200"] = new OpenApiResponse {
Content = contentMediaTypes.Split(',').Select(x => new {Key = x.Trim(), value = new OpenApiMediaType {
Schema = new OpenApiSchema {
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
}
Schema = new OpenApiSchemaReference("myobject"),
}
}).ToDictionary(x => x.Key, x => x.value)
},
Expand All @@ -303,16 +282,13 @@ public void GeneratesTheRightAcceptHeaderBasedOnContentAndStatus(string contentM
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
}
}
}
}
};
document.RegisterComponents();
document.SetReferenceHostDocument();
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(
mockLogger.Object,
Expand Down Expand Up @@ -356,21 +332,7 @@ public void GeneratesTheRightContentTypeHeaderBasedOnContentAndStatus(string con
RequestBody = new OpenApiRequestBody
{
Content = contentMediaTypes.Split(',').Select(x => new {Key = x.Trim(), value = new OpenApiMediaType {
Schema = new OpenApiSchema {
Type = JsonSchemaType.Object,
Properties = new Dictionary<string, IOpenApiSchema> {
{
"id", new OpenApiSchema {
Type = JsonSchemaType.String,
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
}
Schema = new OpenApiSchemaReference("myobject"),
}
}).ToDictionary(x => x.Key, x => x.value)
},
Expand All @@ -391,16 +353,13 @@ public void GeneratesTheRightContentTypeHeaderBasedOnContentAndStatus(string con
}
}
},
Reference = new OpenApiReference
{
Id = "myobject",
Type = ReferenceType.Schema
},
}
}
}
}
};
document.RegisterComponents();
document.SetReferenceHostDocument();
var mockLogger = new Mock<ILogger<KiotaBuilder>>();
var builder = new KiotaBuilder(
mockLogger.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,6 @@ public void GetsNoDeprecationOnOperationWithDeprecatedReferenceResponseSchema()
{
Schema = new OpenApiSchema
{
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = "someSchema"
},
Deprecated = true,
Extensions = new Dictionary<string, IOpenApiExtension>
{
Expand Down Expand Up @@ -303,11 +298,6 @@ public void GetsNoDeprecationOnOperationWithDeprecatedReferenceRequestSchema()
{
Schema = new OpenApiSchema
{
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = "someSchema"
},
Deprecated = true,
Extensions = new Dictionary<string, IOpenApiExtension>
{
Expand Down Expand Up @@ -404,11 +394,6 @@ public void GetsNoDeprecationInformationOnParameterWithDeprecatedReferenceSchema
Deprecated = false,
Schema = new OpenApiSchema
{
Reference = new OpenApiReference
{
Id = "id",
Type = ReferenceType.Schema
},
Deprecated = true,
Extensions = new Dictionary<string, IOpenApiExtension>
{
Expand Down Expand Up @@ -468,11 +453,6 @@ public void GetsNoDeprecationInformationOnParameterWithDeprecatedReferenceConten
{
Schema = new OpenApiSchema
{
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = "id"
},
Deprecated = true,
Extensions = new Dictionary<string, IOpenApiExtension>
{
Expand Down
Loading

0 comments on commit fbc9d63

Please sign in to comment.