-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from jiripeli/prerelease
1.0.14-pre.1 - examples for a parameter type other than body + examples
- Loading branch information
Showing
22 changed files
with
313 additions
and
82 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
9 changes: 0 additions & 9 deletions
9
samples/NSwagWithExamples/Models/Examples/PersonBirthExample.cs
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
samples/NSwagWithExamples/Models/Examples/PersonExample.cs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
samples/NSwagWithExamples/Models/Examples/PersonSpecificAgeExample.cs
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...Examples/Models/Examples/PeopleExample.cs → .../Models/Examples/Persons/PeopleExample.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
26 changes: 26 additions & 0 deletions
26
samples/NSwagWithExamples/Models/Examples/Persons/PersonExamples.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,26 @@ | ||
using System; | ||
using NSwag.Examples; | ||
using RandomNameGeneratorLibrary; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons; | ||
|
||
public class PersonExample : IExampleProvider<Person> | ||
{ | ||
private readonly IPersonNameGenerator _nameGenerator; | ||
|
||
// Use dependency injection to resolve any registered service | ||
public PersonExample(IPersonNameGenerator nameGenerator) | ||
{ | ||
_nameGenerator = nameGenerator; | ||
} | ||
|
||
public Person GetExample() => new Person( | ||
_nameGenerator.GenerateRandomFirstName(), | ||
_nameGenerator.GenerateRandomLastName() | ||
); | ||
} | ||
|
||
public class PersonBirthExample : IExampleProvider<DateTime> | ||
{ | ||
public DateTime GetExample() => DateTime.UtcNow.Date; | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonAge18Example.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,9 @@ | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Age 18", ExampleType = ExampleType.Request)] | ||
public class PersonAge18Example : IExampleProvider<int> | ||
{ | ||
public int GetExample() => 18; | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonAge69Example.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,9 @@ | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Age 69", ExampleType = ExampleType.Request)] | ||
public class PersonAge69Example : IExampleProvider<int> | ||
{ | ||
public int GetExample() => 69; | ||
} |
10 changes: 10 additions & 0 deletions
10
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonRequestExampleCindy.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,10 @@ | ||
using System; | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Cindy", ExampleType = ExampleType.Request)] | ||
public class PersonRequestExampleCindy : IExampleProvider<Person> | ||
{ | ||
public Person GetExample() => new Person("Cindy", "Crowford", new DateTime(1966, 2, 20)); | ||
} |
10 changes: 10 additions & 0 deletions
10
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonRequestExampleTom.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,10 @@ | ||
using System; | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Tom", ExampleType = ExampleType.Request)] | ||
public class PersonRequestExampleTom : IExampleProvider<Person> | ||
{ | ||
public Person GetExample() => new Person("Tom", "Hanks", new DateTime(1956, 7, 9)); | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonTextExample1.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,9 @@ | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Search text 'inspektor'", ExampleType = ExampleType.Request)] | ||
public class PersonTextExample1 : IExampleProvider<string> | ||
{ | ||
public string GetExample() => "inspektor"; | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonTextExample2.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,9 @@ | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Search text 'podez'", ExampleType = ExampleType.Request)] | ||
public class PersonTextExample2 : IExampleProvider<string> | ||
{ | ||
public string GetExample() => "podez"; | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/NSwagWithExamples/Models/Examples/Persons/Requests/PersonTextExample3.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,9 @@ | ||
using NSwag.Examples; | ||
|
||
namespace NSwagWithExamples.Models.Examples.Persons.Requests; | ||
|
||
[ExampleAnnotation(Name = "Search text 'ra'", ExampleType = ExampleType.Request)] | ||
public class PersonTextExample3 : IExampleProvider<string> | ||
{ | ||
public string GetExample() => "ra"; | ||
} |
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 |
---|---|---|
@@ -1,8 +1,43 @@ | ||
namespace NSwagWithExamples.Models; | ||
using System; | ||
|
||
namespace NSwagWithExamples.Models; | ||
|
||
public class Person | ||
{ | ||
private static readonly Random Random = new Random(DateTime.Now.Microsecond); | ||
|
||
public string FirstName { get; set; } | ||
public int Id { get; set; } | ||
public int Id { get; internal set; } | ||
public string LastName { get; set; } | ||
public DateTime BirthDay { get; set; } | ||
|
||
public Person() | ||
{ | ||
} | ||
public Person(int id, string firstName, string lastName, DateTime? birthDay = null) | ||
{ | ||
Id = id; | ||
FirstName = firstName; | ||
LastName = lastName; | ||
BirthDay = birthDay ?? new DateTime(Random.Next(1920, DateTime.Now.Year), Random.Next(1, 13), Random.Next(1, 29)); | ||
} | ||
|
||
public Person(string firstName, string lastName, DateTime? birthDay = null) | ||
{ | ||
FirstName = firstName; | ||
LastName = lastName; | ||
BirthDay = birthDay ?? new DateTime(Random.Next(1920, DateTime.Now.Year), Random.Next(1, 13), Random.Next(1, 29)); | ||
} | ||
|
||
public int Age | ||
{ | ||
get | ||
{ | ||
var today = DateTime.Today; | ||
var age = today.Year - BirthDay.Year; | ||
if (BirthDay.Date > today.AddYears(-age)) age--; | ||
return age; | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.