Skip to content

Commit c86f03a

Browse files
committed
added samples for aspnet 2.2
1 parent b1b4c47 commit c86f03a

File tree

102 files changed

+10847
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+10847
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Swagger Codegen Ignore
2+
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.14-SNAPSHOT
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio 15
3+
VisualStudioVersion = 15.0.26114.2
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "IO.Swagger", "src\IO.Swagger\IO.Swagger.csproj", "{3C799344-F285-4669-8FD5-7ED9B795D5C5}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{3C799344-F285-4669-8FD5-7ED9B795D5C5}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
EndGlobal
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
5+
<clear />
6+
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" />
7+
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
8+
</packageSources>
9+
</configuration>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# IO.Swagger - ASP.NET Core 2.2 Server
2+
3+
This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
4+
5+
## Run
6+
7+
Linux/OS X:
8+
9+
```
10+
sh build.sh
11+
```
12+
13+
Windows:
14+
15+
```
16+
build.bat
17+
```
18+
19+
## Run in Docker
20+
21+
```
22+
cd src/IO.Swagger
23+
docker build -t io.swagger .
24+
docker run -p 5000:5000 io.swagger
25+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
:: Generated by: https://github.com/swagger-api/swagger-codegen.git
2+
::
3+
4+
@echo off
5+
6+
dotnet restore src\IO.Swagger
7+
dotnet build src\IO.Swagger
8+
echo Now, run the following to start the project: dotnet run -p src\IO.Swagger\IO.Swagger.csproj --launch-profile web.
9+
echo.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Generated by: https://github.com/swagger-api/swagger-codegen.git
4+
#
5+
6+
dotnet restore src/IO.Swagger/ && \
7+
dotnet build src/IO.Swagger/ && \
8+
echo "Now, run the following to start the project: dotnet run -p src/IO.Swagger/IO.Swagger.csproj --launch-profile web"
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
PID
2+
3+
## Ignore Visual Studio temporary files, build results, and
4+
## files generated by popular Visual Studio add-ons.
5+
6+
# User-specific files
7+
*.suo
8+
*.user
9+
*.userosscache
10+
*.sln.docstates
11+
12+
# User-specific files (MonoDevelop/Xamarin Studio)
13+
*.userprefs
14+
15+
# Build results
16+
[Dd]ebug/
17+
[Dd]ebugPublic/
18+
[Rr]elease/
19+
[Rr]eleases/
20+
x64/
21+
x86/
22+
build/
23+
bld/
24+
[Bb]in/
25+
[Oo]bj/
26+
27+
# Visual Studio 2015 cache/options directory
28+
.vs/
29+
30+
# MSTest test Results
31+
[Tt]est[Rr]esult*/
32+
[Bb]uild[Ll]og.*
33+
34+
# NUNIT
35+
*.VisualState.xml
36+
TestResult.xml
37+
38+
# Build Results of an ATL Project
39+
[Dd]ebugPS/
40+
[Rr]eleasePS/
41+
dlldata.c
42+
43+
# DNX
44+
project.lock.json
45+
artifacts/
46+
47+
*_i.c
48+
*_p.c
49+
*_i.h
50+
*.ilk
51+
*.meta
52+
*.obj
53+
*.pch
54+
*.pdb
55+
*.pgc
56+
*.pgd
57+
*.rsp
58+
*.sbr
59+
*.tlb
60+
*.tli
61+
*.tlh
62+
*.tmp
63+
*.tmp_proj
64+
*.log
65+
*.vspscc
66+
*.vssscc
67+
.builds
68+
*.pidb
69+
*.svclog
70+
*.scc
71+
72+
# Chutzpah Test files
73+
_Chutzpah*
74+
75+
# Visual C++ cache files
76+
ipch/
77+
*.aps
78+
*.ncb
79+
*.opensdf
80+
*.sdf
81+
*.cachefile
82+
83+
# Visual Studio profiler
84+
*.psess
85+
*.vsp
86+
*.vspx
87+
88+
# TFS 2012 Local Workspace
89+
$tf/
90+
91+
# Guidance Automation Toolkit
92+
*.gpState
93+
94+
# ReSharper is a .NET coding add-in
95+
_ReSharper*/
96+
*.[Rr]e[Ss]harper
97+
*.DotSettings.user
98+
99+
# JustCode is a .NET coding add-in
100+
.JustCode
101+
102+
# TeamCity is a build add-in
103+
_TeamCity*
104+
105+
# DotCover is a Code Coverage Tool
106+
*.dotCover
107+
108+
# NCrunch
109+
_NCrunch_*
110+
.*crunch*.local.xml
111+
112+
# MightyMoose
113+
*.mm.*
114+
AutoTest.Net/
115+
116+
# Web workbench (sass)
117+
.sass-cache/
118+
119+
# Installshield output folder
120+
[Ee]xpress/
121+
122+
# DocProject is a documentation generator add-in
123+
DocProject/buildhelp/
124+
DocProject/Help/*.HxT
125+
DocProject/Help/*.HxC
126+
DocProject/Help/*.hhc
127+
DocProject/Help/*.hhk
128+
DocProject/Help/*.hhp
129+
DocProject/Help/Html2
130+
DocProject/Help/html
131+
132+
# Click-Once directory
133+
publish/
134+
135+
# Publish Web Output
136+
*.[Pp]ublish.xml
137+
*.azurePubxml
138+
# TODO: Comment the next line if you want to checkin your web deploy settings
139+
# but database connection strings (with potential passwords) will be unencrypted
140+
*.pubxml
141+
*.publishproj
142+
143+
# NuGet Packages
144+
*.nupkg
145+
# The packages folder can be ignored because of Package Restore
146+
**/packages/*
147+
# except build/, which is used as an MSBuild target.
148+
!**/packages/build/
149+
# Uncomment if necessary however generally it will be regenerated when needed
150+
#!**/packages/repositories.config
151+
152+
# Windows Azure Build Output
153+
csx/
154+
*.build.csdef
155+
156+
# Windows Store app package directory
157+
AppPackages/
158+
159+
# Visual Studio cache files
160+
# files ending in .cache can be ignored
161+
*.[Cc]ache
162+
# but keep track of directories ending in .cache
163+
!*.[Cc]ache/
164+
165+
# Others
166+
ClientBin/
167+
[Ss]tyle[Cc]op.*
168+
~$*
169+
*~
170+
*.dbmdl
171+
*.dbproj.schemaview
172+
*.pfx
173+
*.publishsettings
174+
node_modules/
175+
bower_components/
176+
orleans.codegen.cs
177+
178+
# RIA/Silverlight projects
179+
Generated_Code/
180+
181+
# Backup & report files from converting an old project file
182+
# to a newer Visual Studio version. Backup files are not needed,
183+
# because we have git ;-)
184+
_UpgradeReport_Files/
185+
Backup*/
186+
UpgradeLog*.XML
187+
UpgradeLog*.htm
188+
189+
# SQL Server files
190+
*.mdf
191+
*.ldf
192+
193+
# Business Intelligence projects
194+
*.rdl.data
195+
*.bim.layout
196+
*.bim_*.settings
197+
198+
# Microsoft Fakes
199+
FakesAssemblies/
200+
201+
# Node.js Tools for Visual Studio
202+
.ntvs_analysis.dat
203+
204+
# Visual Studio 6 build log
205+
*.plg
206+
207+
# Visual Studio 6 workspace options file
208+
*.opt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.ComponentModel.DataAnnotations;
2+
using System.Reflection;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.AspNetCore.Mvc.Controllers;
5+
using Microsoft.AspNetCore.Mvc.Filters;
6+
using Microsoft.AspNetCore.Mvc.ModelBinding;
7+
8+
namespace IO.Swagger.Attributes
9+
{
10+
/// <summary>
11+
/// Model state validation attribute
12+
/// </summary>
13+
public class ValidateModelStateAttribute : ActionFilterAttribute
14+
{
15+
/// <summary>
16+
/// Called before the action method is invoked
17+
/// </summary>
18+
/// <param name="context"></param>
19+
public override void OnActionExecuting(ActionExecutingContext context)
20+
{
21+
// Per https://blog.markvincze.com/how-to-validate-action-parameters-with-dataannotation-attributes/
22+
var descriptor = context.ActionDescriptor as ControllerActionDescriptor;
23+
if (descriptor != null)
24+
{
25+
foreach (var parameter in descriptor.MethodInfo.GetParameters())
26+
{
27+
object args = null;
28+
if (context.ActionArguments.ContainsKey(parameter.Name))
29+
{
30+
args = context.ActionArguments[parameter.Name];
31+
}
32+
33+
ValidateAttributes(parameter, args, context.ModelState);
34+
}
35+
}
36+
37+
if (!context.ModelState.IsValid)
38+
{
39+
context.Result = new BadRequestObjectResult(context.ModelState);
40+
}
41+
}
42+
43+
private void ValidateAttributes(ParameterInfo parameter, object args, ModelStateDictionary modelState)
44+
{
45+
foreach (var attributeData in parameter.CustomAttributes)
46+
{
47+
var attributeInstance = parameter.GetCustomAttribute(attributeData.AttributeType);
48+
49+
var validationAttribute = attributeInstance as ValidationAttribute;
50+
if (validationAttribute != null)
51+
{
52+
var isValid = validationAttribute.IsValid(args);
53+
if (!isValid)
54+
{
55+
modelState.AddModelError(parameter.Name, validationAttribute.FormatErrorMessage(parameter.Name));
56+
}
57+
}
58+
}
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)