|
9 | 9 | using System.Threading;
|
10 | 10 | using FluentAssertions;
|
11 | 11 | using Microsoft.OpenApi.Any;
|
12 |
| -using Microsoft.OpenApi.Extensions; |
13 | 12 | using Microsoft.OpenApi.Interfaces;
|
14 | 13 | using Microsoft.OpenApi.Models;
|
15 | 14 | using Microsoft.OpenApi.Validations;
|
16 | 15 | using Microsoft.OpenApi.Validations.Rules;
|
17 | 16 | using Microsoft.OpenApi.Writers;
|
18 |
| -using Newtonsoft.Json; |
19 | 17 | using Xunit;
|
20 | 18 | using Xunit.Abstractions;
|
21 | 19 |
|
@@ -1256,7 +1254,7 @@ public void GlobalSecurityRequirementShouldReferenceSecurityScheme()
|
1256 | 1254 | Assert.Same(securityRequirement.Keys.First(), openApiDoc.Components.SecuritySchemes.First().Value);
|
1257 | 1255 | }
|
1258 | 1256 | }
|
1259 |
| - |
| 1257 | + |
1260 | 1258 | [Fact]
|
1261 | 1259 | public void HeaderParameterShouldAllowExample()
|
1262 | 1260 | {
|
@@ -1535,5 +1533,222 @@ public void ParseDocumentWithWebhooksShouldSucceed()
|
1535 | 1533 | diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 });
|
1536 | 1534 | actual.Should().BeEquivalentTo(expected);
|
1537 | 1535 | }
|
| 1536 | + |
| 1537 | + [Fact] |
| 1538 | + public void ParseDocumentsWithReusablePathItemInWebhooksSucceeds() |
| 1539 | + { |
| 1540 | + // Arrange && Act |
| 1541 | + using var stream = Resources.GetStream("V3Tests/Samples/OpenApiDocument/documentWithReusablePaths.yaml"); |
| 1542 | + var actual = new OpenApiStreamReader().Read(stream, out var context); |
| 1543 | + |
| 1544 | + var components = new OpenApiComponents |
| 1545 | + { |
| 1546 | + Schemas = new Dictionary<string, OpenApiSchema> |
| 1547 | + { |
| 1548 | + ["pet"] = new OpenApiSchema |
| 1549 | + { |
| 1550 | + Type = "object", |
| 1551 | + Required = new HashSet<string> |
| 1552 | + { |
| 1553 | + "id", |
| 1554 | + "name" |
| 1555 | + }, |
| 1556 | + Properties = new Dictionary<string, OpenApiSchema> |
| 1557 | + { |
| 1558 | + ["id"] = new OpenApiSchema |
| 1559 | + { |
| 1560 | + Type = "integer", |
| 1561 | + Format = "int64" |
| 1562 | + }, |
| 1563 | + ["name"] = new OpenApiSchema |
| 1564 | + { |
| 1565 | + Type = "string" |
| 1566 | + }, |
| 1567 | + ["tag"] = new OpenApiSchema |
| 1568 | + { |
| 1569 | + Type = "string" |
| 1570 | + }, |
| 1571 | + }, |
| 1572 | + Reference = new OpenApiReference |
| 1573 | + { |
| 1574 | + Type = ReferenceType.Schema, |
| 1575 | + Id = "pet", |
| 1576 | + HostDocument = actual |
| 1577 | + } |
| 1578 | + }, |
| 1579 | + ["newPet"] = new OpenApiSchema |
| 1580 | + { |
| 1581 | + Type = "object", |
| 1582 | + Required = new HashSet<string> |
| 1583 | + { |
| 1584 | + "name" |
| 1585 | + }, |
| 1586 | + Properties = new Dictionary<string, OpenApiSchema> |
| 1587 | + { |
| 1588 | + ["id"] = new OpenApiSchema |
| 1589 | + { |
| 1590 | + Type = "integer", |
| 1591 | + Format = "int64" |
| 1592 | + }, |
| 1593 | + ["name"] = new OpenApiSchema |
| 1594 | + { |
| 1595 | + Type = "string" |
| 1596 | + }, |
| 1597 | + ["tag"] = new OpenApiSchema |
| 1598 | + { |
| 1599 | + Type = "string" |
| 1600 | + }, |
| 1601 | + }, |
| 1602 | + Reference = new OpenApiReference |
| 1603 | + { |
| 1604 | + Type = ReferenceType.Schema, |
| 1605 | + Id = "newPet", |
| 1606 | + HostDocument = actual |
| 1607 | + } |
| 1608 | + } |
| 1609 | + } |
| 1610 | + }; |
| 1611 | + |
| 1612 | + // Create a clone of the schema to avoid modifying things in components. |
| 1613 | + var petSchema = Clone(components.Schemas["pet"]); |
| 1614 | + |
| 1615 | + petSchema.Reference = new OpenApiReference |
| 1616 | + { |
| 1617 | + Id = "pet", |
| 1618 | + Type = ReferenceType.Schema, |
| 1619 | + HostDocument = actual |
| 1620 | + }; |
| 1621 | + |
| 1622 | + var newPetSchema = Clone(components.Schemas["newPet"]); |
| 1623 | + |
| 1624 | + newPetSchema.Reference = new OpenApiReference |
| 1625 | + { |
| 1626 | + Id = "newPet", |
| 1627 | + Type = ReferenceType.Schema, |
| 1628 | + HostDocument = actual |
| 1629 | + }; |
| 1630 | + components.PathItems = new Dictionary<string, OpenApiPathItem> |
| 1631 | + { |
| 1632 | + ["/pets"] = new OpenApiPathItem |
| 1633 | + { |
| 1634 | + Operations = new Dictionary<OperationType, OpenApiOperation> |
| 1635 | + { |
| 1636 | + [OperationType.Get] = new OpenApiOperation |
| 1637 | + { |
| 1638 | + Description = "Returns all pets from the system that the user has access to", |
| 1639 | + OperationId = "findPets", |
| 1640 | + Parameters = new List<OpenApiParameter> |
| 1641 | + { |
| 1642 | + new OpenApiParameter |
| 1643 | + { |
| 1644 | + Name = "tags", |
| 1645 | + In = ParameterLocation.Query, |
| 1646 | + Description = "tags to filter by", |
| 1647 | + Required = false, |
| 1648 | + Schema = new OpenApiSchema |
| 1649 | + { |
| 1650 | + Type = "array", |
| 1651 | + Items = new OpenApiSchema |
| 1652 | + { |
| 1653 | + Type = "string" |
| 1654 | + } |
| 1655 | + } |
| 1656 | + }, |
| 1657 | + new OpenApiParameter |
| 1658 | + { |
| 1659 | + Name = "limit", |
| 1660 | + In = ParameterLocation.Query, |
| 1661 | + Description = "maximum number of results to return", |
| 1662 | + Required = false, |
| 1663 | + Schema = new OpenApiSchema |
| 1664 | + { |
| 1665 | + Type = "integer", |
| 1666 | + Format = "int32" |
| 1667 | + } |
| 1668 | + } |
| 1669 | + }, |
| 1670 | + Responses = new OpenApiResponses |
| 1671 | + { |
| 1672 | + ["200"] = new OpenApiResponse |
| 1673 | + { |
| 1674 | + Description = "pet response", |
| 1675 | + Content = new Dictionary<string, OpenApiMediaType> |
| 1676 | + { |
| 1677 | + ["application/json"] = new OpenApiMediaType |
| 1678 | + { |
| 1679 | + Schema = new OpenApiSchema |
| 1680 | + { |
| 1681 | + Type = "array", |
| 1682 | + Items = petSchema |
| 1683 | + } |
| 1684 | + }, |
| 1685 | + ["application/xml"] = new OpenApiMediaType |
| 1686 | + { |
| 1687 | + Schema = new OpenApiSchema |
| 1688 | + { |
| 1689 | + Type = "array", |
| 1690 | + Items = petSchema |
| 1691 | + } |
| 1692 | + } |
| 1693 | + } |
| 1694 | + } |
| 1695 | + } |
| 1696 | + }, |
| 1697 | + [OperationType.Post] = new OpenApiOperation |
| 1698 | + { |
| 1699 | + RequestBody = new OpenApiRequestBody |
| 1700 | + { |
| 1701 | + Description = "Information about a new pet in the system", |
| 1702 | + Required = true, |
| 1703 | + Content = new Dictionary<string, OpenApiMediaType> |
| 1704 | + { |
| 1705 | + ["application/json"] = new OpenApiMediaType |
| 1706 | + { |
| 1707 | + Schema = newPetSchema |
| 1708 | + } |
| 1709 | + } |
| 1710 | + }, |
| 1711 | + Responses = new OpenApiResponses |
| 1712 | + { |
| 1713 | + ["200"] = new OpenApiResponse |
| 1714 | + { |
| 1715 | + Description = "Return a 200 status to indicate that the data was received successfully", |
| 1716 | + Content = new Dictionary<string, OpenApiMediaType> |
| 1717 | + { |
| 1718 | + ["application/json"] = new OpenApiMediaType |
| 1719 | + { |
| 1720 | + Schema = petSchema |
| 1721 | + }, |
| 1722 | + } |
| 1723 | + } |
| 1724 | + } |
| 1725 | + } |
| 1726 | + }, |
| 1727 | + Reference = new OpenApiReference |
| 1728 | + { |
| 1729 | + Type = ReferenceType.PathItem, |
| 1730 | + Id = "/pets", |
| 1731 | + HostDocument = actual |
| 1732 | + } |
| 1733 | + } |
| 1734 | + }; |
| 1735 | + |
| 1736 | + var expected = new OpenApiDocument |
| 1737 | + { |
| 1738 | + Info = new OpenApiInfo |
| 1739 | + { |
| 1740 | + Title = "Webhook Example", |
| 1741 | + Version = "1.0.0" |
| 1742 | + }, |
| 1743 | + Webhooks = components.PathItems, |
| 1744 | + Components = components |
| 1745 | + }; |
| 1746 | + |
| 1747 | + // Assert |
| 1748 | + actual.Should().BeEquivalentTo(expected); |
| 1749 | + context.Should().BeEquivalentTo( |
| 1750 | + new OpenApiDiagnostic() { SpecificationVersion = OpenApiSpecVersion.OpenApi3_0 }); |
| 1751 | + |
| 1752 | + } |
1538 | 1753 | }
|
1539 | 1754 | }
|
0 commit comments