-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added examples and other OpenAPI 3 features
- Loading branch information
Showing
39 changed files
with
297 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/NSwag.Core.Tests/Serialization/ExampleSerializationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NJsonSchema; | ||
using Xunit; | ||
|
||
namespace NSwag.Core.Tests.Serialization | ||
{ | ||
public class ExampleSerializationTests | ||
{ | ||
[Fact] | ||
public async Task When_document_has_response_examples_then_it_is_serialized_in_Swagger() | ||
{ | ||
//// Arrange | ||
var document = CreateDocument(); | ||
|
||
//// Act | ||
var json = document.ToJson(SchemaType.Swagger2); | ||
|
||
//// Assert | ||
Assert.Contains(@"""examples"": 1", json); // response examples | ||
Assert.Contains(@"""example"": 2", json); // parameter example | ||
Assert.DoesNotContain(@"""ParameterExamples""", json); // parameter examples | ||
} | ||
|
||
[Fact] | ||
public async Task When_document_has_response_examples_then_it_is_not_serialized_in_OpenApi() | ||
{ | ||
//// Arrange | ||
var document = CreateDocument(); | ||
|
||
//// Act | ||
var json = document.ToJson(SchemaType.OpenApi3); | ||
|
||
//// Assert | ||
Assert.DoesNotContain(@"""examples"": 1", json); // response examples | ||
Assert.Contains(@"""example"": 2", json); // parameter example | ||
Assert.Contains(@"""ParameterExamples""", json); // parameter examples | ||
} | ||
|
||
private static SwaggerDocument CreateDocument() | ||
{ | ||
var document = new SwaggerDocument(); | ||
document.Paths["foo"] = new SwaggerOperations | ||
{ | ||
{ | ||
SwaggerOperationMethod.Get, | ||
new SwaggerOperation | ||
{ | ||
Parameters = | ||
{ | ||
new SwaggerParameter | ||
{ | ||
Kind = SwaggerParameterKind.Query, | ||
Example = 2, | ||
Examples = new Dictionary<string, SwaggerExample> | ||
{ | ||
{ | ||
"ParameterExamples", | ||
new SwaggerExample | ||
{ | ||
Description = "Bar" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
Responses = | ||
{ | ||
{ | ||
"200", | ||
new SwaggerResponse | ||
{ | ||
Examples = 1 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
return document; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//----------------------------------------------------------------------- | ||
// <copyright file="JsonExpectedSchema.cs" company="NSwag"> | ||
// Copyright (c) Rico Suter. All rights reserved. | ||
// </copyright> | ||
// <license>https://github.com/NSwag/NSwag/blob/master/LICENSE.md</license> | ||
// <author>Rico Suter, mail@rsuter.com</author> | ||
//----------------------------------------------------------------------- | ||
|
||
using Newtonsoft.Json; | ||
using NJsonSchema; | ||
|
||
namespace NSwag | ||
{ | ||
/// <summary>Specifies a schema which is expected.</summary> | ||
public class JsonExpectedSchema | ||
{ | ||
/// <summary>Gets or sets the description.</summary> | ||
[JsonProperty(PropertyName = "description", DefaultValueHandling = DefaultValueHandling.Ignore)] | ||
public string Description { get; set; } | ||
|
||
/// <summary>Gets or sets the schema.</summary> | ||
[JsonProperty(PropertyName = "schema", DefaultValueHandling = DefaultValueHandling.Ignore)] | ||
public JsonSchema4 Schema { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.