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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,128 @@ query GetUsers @http(method: GET, route: "/users") {
// assert
Assert.Contains("/users", document);
}

[Fact]
public async Task SelfRef_Input_Type_Via_Mutation_Body()
{
// arrange
var storage = new TestOpenApiDefinitionStorage(
"""
mutation SubmitSelfRef($input: SelfReferencingInput! @body)
@http(method: POST, route: "/self-ref") {
submitSelfRef(input: $input)
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var document = await GetOpenApiDocumentAsync(client);

// assert
document.MatchSnapshot(postFix: TestEnvironment.TargetFramework, extension: ".json");
}

[Fact]
public async Task SelfRef_Output_Type_Via_Query()
{
// arrange
var storage = new TestOpenApiDefinitionStorage(
"""
query GetTree @http(method: GET, route: "/tree") {
tree {
value
children {
value
}
}
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var document = await GetOpenApiDocumentAsync(client);

// assert
document.MatchSnapshot(postFix: TestEnvironment.TargetFramework, extension: ".json");
}

[Fact]
public async Task Indirect_Input_Type_Via_Mutation_Body()
{
// arrange
// A -> B -> A: the body inlines IndirectParentInput, then the cycle closes through
// the IndirectMiddleInput and IndirectParentInput components.
var storage = new TestOpenApiDefinitionStorage(
"""
mutation SubmitIndirect($input: IndirectParentInput! @body)
@http(method: POST, route: "/indirect-input") {
submitIndirect(input: $input)
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var document = await GetOpenApiDocumentAsync(client);

// assert
document.MatchSnapshot(postFix: TestEnvironment.TargetFramework, extension: ".json");
}

[Fact]
public async Task Indirect_Output_Type_Via_Query()
{
// arrange
// A -> B -> A selected a couple of levels deep so the expansion is bounded by the
// selection set rather than the type cycle.
var storage = new TestOpenApiDefinitionStorage(
"""
query GetIndirect @http(method: GET, route: "/indirect-output") {
indirect {
value
middle {
label
parent {
value
middle {
label
}
}
}
}
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var document = await GetOpenApiDocumentAsync(client);

// assert
document.MatchSnapshot(postFix: TestEnvironment.TargetFramework, extension: ".json");
}

[Fact]
public async Task Indirect_Input_Type_With_Two_Sibling_Occurrences()
{
// arrange
// The same input type appears at two sibling positions and both must emit a $ref.
var storage = new TestOpenApiDefinitionStorage(
"""
mutation SubmitTwoChildren($input: TwoChildrenInput! @body)
@http(method: POST, route: "/two-children") {
submitTwoChildren(input: $input)
}
""");
var server = CreateTestServer(storage);
var client = server.CreateClient();

// act
var document = await GetOpenApiDocumentAsync(client);

// assert
document.MatchSnapshot(postFix: TestEnvironment.TargetFramework, extension: ".json");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"localDateTime",
"localTime",
"long",
"nonNullDeprecated",
"object",
"short",
"string",
Expand Down Expand Up @@ -183,36 +184,23 @@
"description": "The `Long` scalar type represents a signed 64-bit integer.",
"format": "int64"
},
"object": {
"required": [
"field1A"
],
"type": "object",
"properties": {
"field1A": {
"required": [
"field1B"
],
"type": "object",
"properties": {
"field1B": {
"required": [
"field1C"
],
"type": "object",
"properties": {
"field1C": {
"pattern": "^\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,9})?$",
"type": "string",
"description": "field1C description"
}
},
"description": "field1B description"
}
},
"description": "field1A description"
"nonNullDeprecated": {
"type": "integer",
"description": "nonNullDeprecated description",
"format": "int32",
"deprecated": true
},
"nullableObject": {
"allOf": [
{
"$ref": "#/components/schemas/Object1NullableInput"
}
}
],
"description": "nullableObject description",
"deprecated": true
},
"object": {
"$ref": "#/components/schemas/Object1NonNullableInput"
},
"short": {
"type": "integer",
Expand Down Expand Up @@ -1095,6 +1083,87 @@
},
"components": {
"schemas": {
"Object1NonNullableInput": {
"required": [
"field1A"
],
"type": "object",
"properties": {
"field1A": {
"allOf": [
{
"$ref": "#/components/schemas/Object2NonNullableInput"
}
],
"description": "field1A description"
}
}
},
"Object1NullableInput": {
"type": "object",
"properties": {
"field1A": {
"allOf": [
{
"$ref": "#/components/schemas/Object2NullableInput"
}
],
"description": "field1A description"
}
}
},
"Object2NonNullableInput": {
"required": [
"field1B"
],
"type": "object",
"properties": {
"field1B": {
"allOf": [
{
"$ref": "#/components/schemas/Object3NonNullableInput"
}
],
"description": "field1B description"
}
}
},
"Object2NullableInput": {
"type": "object",
"properties": {
"field1B": {
"allOf": [
{
"$ref": "#/components/schemas/Object3NullableInput"
}
],
"description": "field1B description"
}
}
},
"Object3NonNullableInput": {
"required": [
"field1C"
],
"type": "object",
"properties": {
"field1C": {
"pattern": "^\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,9})?$",
"type": "string",
"description": "field1C description"
}
}
},
"Object3NullableInput": {
"type": "object",
"properties": {
"field1C": {
"pattern": "^\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{1,9})?$",
"type": "string",
"description": "field1C description"
}
}
},
"UserAddress": {
"required": [
"street"
Expand Down
Loading
Loading