Skip to content

Commit 1c25f3c

Browse files
committed
Adding YAML definition in WWI OData services
1 parent dc09a86 commit 1c25f3c

3 files changed

Lines changed: 2404 additions & 10 deletions

File tree

samples/databases/wide-world-importers/wwi-app/wwi-app.csproj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
33
<TargetFramework>netcoreapp2.0</TargetFramework>
44
<!-- PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback -->
55
<SignAssembly>false</SignAssembly>
66
<AssemblyOriginatorKeyFile>hrkljush.snk</AssemblyOriginatorKeyFile>
77
</PropertyGroup>
88
<ItemGroup>
9-
<Compile Remove="Areas\**" />
10-
<Compile Remove="SqlServerRestApi\**" />
11-
<Compile Remove="wwwroot\public\**" />
12-
<Content Remove="Areas\**" />
13-
<Content Remove="SqlServerRestApi\**" />
149
<Content Remove="wwwroot\public\**" />
15-
<EmbeddedResource Remove="Areas\**" />
16-
<EmbeddedResource Remove="SqlServerRestApi\**" />
1710
<EmbeddedResource Remove="wwwroot\public\**" />
18-
<None Remove="Areas\**" />
19-
<None Remove="SqlServerRestApi\**" />
2011
<None Remove="wwwroot\public\**" />
2112
</ItemGroup>
2213
<ItemGroup>
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<#@ output extension=".yaml"#>
2+
<#@ assembly name="Newtonsoft.Json" #>
3+
<#@ template language="C#" hostspecific="True" #>
4+
<#
5+
var o = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(this.Host.ResolvePath("..") + "\\appsettings.json"));
6+
var json = o["ApiModel"].ToString();
7+
TableDef[] config = Newtonsoft.Json.JsonConvert.DeserializeObject<TableDef[]>(json);
8+
#>
9+
swagger: "2.0"
10+
info:
11+
description: "OData service exposing information from WideWorldImporters database."
12+
version: "1.0.0"
13+
title: "Wide World Importers"
14+
termsOfService: "http://swagger.io/terms/"
15+
contact:
16+
email: "sqlserversamples@microsoft.com"
17+
license:
18+
name: "Apache 2.0"
19+
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
20+
host: "localhost:64958"
21+
basePath: "/OData"
22+
tags:
23+
<# foreach(var t in config) {#>
24+
<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #>
25+
- name: "<#= t.Table #>"
26+
description: "Information about <#= t.Table #>"
27+
<# } #>
28+
schemes:
29+
- "https"
30+
- "http"
31+
paths:
32+
<# foreach(var t in config) {#>
33+
<# if(string.IsNullOrEmpty(t.ODataColumns)) continue; #>
34+
35+
/<#= t.Table #>:
36+
get:
37+
tags:
38+
- "<#= t.Table #>"
39+
summary: "Find information about <#= t.Table #>"
40+
description: "Multiple status values can be provided with comma separated strings"
41+
operationId: "<#= t.Table #>"
42+
produces:
43+
- "application/json"
44+
parameters:
45+
- name: "$select"
46+
in: "query"
47+
description: "Selecting the properties that should be returned by service"
48+
required: false
49+
type: "array"
50+
items:
51+
type: "string"
52+
enum:<# foreach(var c in t.ODataColumns.Split(',')) {#>
53+
- "<#= c #>"<# } #>
54+
collectionFormat: "multi"
55+
- name: "$orderby"
56+
in: "query"
57+
description: "Ordering results by properties"
58+
required: false
59+
type: "array"
60+
items:
61+
type: "string"
62+
enum:<# foreach(var c in t.ODataColumns.Split(',')) {#>
63+
- "<#= c #>"
64+
- "<#= c #> asc"
65+
- "<#= c #> desc"<# } #>
66+
collectionFormat: "multi"
67+
- name: "$top"
68+
in: "query"
69+
description: "Selecting the properties that should be returned by service"
70+
required: false
71+
type: "integer"
72+
- name: "$skip"
73+
in: "query"
74+
description: "Selecting the properties that should be returned by service"
75+
required: false
76+
type: "integer"
77+
- name: "$apply"
78+
in: "query"
79+
description: "aggregation function that should be applied on the results"
80+
required: false
81+
type: "string"
82+
- name: "$filter"
83+
in: "query"
84+
description: "Condition that returned items must satisfy"
85+
required: false
86+
type: "string"
87+
responses:
88+
200:
89+
description: "Provided information about <#= t.Table #>."
90+
400:
91+
description: "The OData request is not valid"
92+
500:
93+
description: "Cannot process request"<# } #>
94+
<#+
95+
public class TableDef {
96+
public string Schema {get; set;}
97+
public string Table {get; set;}
98+
public string ODataColumns {get; set;}
99+
public bool IsReadOnly {get; set;}
100+
}
101+
#>

0 commit comments

Comments
 (0)