generate swagger.json on build

This commit is contained in:
YuukanOO 2020-12-18 15:06:24 +01:00 committed by Julien LEICHER
parent af913b7ba6
commit 5f389ae5f8
No known key found for this signature in database
GPG Key ID: BE0761B6A007EB96
2 changed files with 168 additions and 0 deletions

View File

@ -3,6 +3,7 @@
<PropertyGroup> <PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn> <NoWarn>$(NoWarn);1591</NoWarn>
<!-- <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> -->
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -11,11 +12,20 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="NSwag.AspNetCore" Version="13.9.4" /> <PackageReference Include="NSwag.AspNetCore" Version="13.9.4" />
<PackageReference Include="NSwag.MSBuild" Version="13.9.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<!-- Permet de générer le fichier de description de l'api à chaque build qui sera utile pour la génération du client -->
<Target Name="NSwag" AfterTargets="Build">
<Exec EnvironmentVariables="ASPNETCORE_ENVIRONMENT=Development" Command="$(NSwagExe_Net50) aspnetcore2openapi /assembly:$(TargetDir)Api.dll /output:swagger.json" />
</Target>
</Project> </Project>

158
Apps/Api/swagger.json Normal file
View File

@ -0,0 +1,158 @@
{
"x-generator": "NSwag v13.9.4.0 (NJsonSchema v10.3.1.0 (Newtonsoft.Json v12.0.0.0))",
"openapi": "3.0.0",
"info": {
"title": "Hacker news like API in .Net",
"version": "1.0.0"
},
"paths": {
"/api/links": {
"get": {
"tags": [
"Links"
],
"summary": "Retrieve all links already posted.",
"operationId": "Links_GetLinks",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LinkDto"
}
}
}
}
},
"400": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ProblemDetails"
}
}
}
}
}
},
"post": {
"tags": [
"Links"
],
"summary": "Post a new link.",
"operationId": "Links_CreateLink",
"requestBody": {
"x-name": "command",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AddLinkCommand"
}
}
},
"required": true,
"x-position": 1
},
"responses": {
"200": {
"description": "",
"content": {
"application/octet-stream": {
"schema": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"LinkDto": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"format": "guid"
},
"url": {
"type": "string",
"nullable": true
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"createdByName": {
"type": "string",
"nullable": true
},
"upVotes": {
"type": "integer",
"format": "int32"
},
"downVotes": {
"type": "integer",
"format": "int32"
}
}
},
"ProblemDetails": {
"type": "object",
"additionalProperties": {
"nullable": true
},
"properties": {
"type": {
"type": "string",
"nullable": true
},
"title": {
"type": "string",
"nullable": true
},
"status": {
"type": "integer",
"format": "int32",
"nullable": true
},
"detail": {
"type": "string",
"nullable": true
},
"instance": {
"type": "string",
"nullable": true
},
"extensions": {
"type": "object",
"nullable": true,
"additionalProperties": {}
}
}
},
"AddLinkCommand": {
"type": "object",
"additionalProperties": false,
"required": [
"url"
],
"properties": {
"url": {
"type": "string",
"format": "uri",
"minLength": 1
}
}
}
}
}
}