Skip to content

Commit c860cdc

Browse files
committed
Fixes #1399: Fix OpenAPI codes in ODataRoutingSample
1 parent 5b87e2b commit c860cdc

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

sample/ODataRoutingSample/Controllers/ODataOpenApiController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public ContentResult GetV2OpenApi(string data)
5656
return CreateContent(document);
5757
}
5858

59+
[HttpGet("v3/$openapi")]
60+
public ContentResult GetV3OpenApi(string data)
61+
{
62+
OpenApiDocument document = CreateDocument("v3");
63+
return CreateContent(document);
64+
}
65+
5966
private ContentResult CreateContent(OpenApiDocument document)
6067
{
6168
HttpContext httpContext = Request.HttpContext;

sample/ODataRoutingSample/OpenApi/ODataPathTranslater.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ public static ODataPath Translate(this ODataPathTemplate pathTemplate, IEdmModel
5151
case PropertySegmentTemplate property:
5252
// TODO:
5353
return null;
54-
//PropertySegmentTemplate property = (PropertySegmentTemplate)segment;
55-
//newSegments.Add(property.ConvertTo());
56-
//break;
5754

5855
case NavigationSegmentTemplate navigation:
5956
newSegments.Add(navigation.ConvertTo());
@@ -77,34 +74,26 @@ public static ODataPath Translate(this ODataPathTemplate pathTemplate, IEdmModel
7774

7875
case ValueSegmentTemplate value:
7976
return null;
80-
//ValueSegmentTemplate value = (ValueSegmentTemplate)segment;
81-
//newSegments.Add(value.ConvertTo());
82-
//break;
8377

8478
case NavigationLinkSegmentTemplate navigationLink:
8579
return null;
86-
//NavigationLinkSegmentTemplate navigationLink = (NavigationLinkSegmentTemplate)segment;
87-
//newSegments.Add(navigationLink.ConvertTo());
88-
//break;
8980

9081
case CountSegmentTemplate count:
9182
newSegments.Add(count.ConvertTo());
9283
break;
9384

9485
case PathTemplateSegmentTemplate:
9586
return null;
96-
//KeySegmentTemplate key = (KeySegmentTemplate)segment;
97-
//newSegments.Add(key.ConvertTo());
98-
//break;
9987

10088
case DynamicSegmentTemplate:
10189
return null;
102-
//KeySegmentTemplate key = (KeySegmentTemplate)segment;
103-
//newSegments.Add(key.ConvertTo());
104-
//break;
90+
91+
case NavigationLinkTemplateSegmentTemplate navigationLinkTemplate:
92+
return null;
10593

10694
default:
107-
throw new NotSupportedException();
95+
return null;
96+
// throw new NotSupportedException("Please update codes here, maybe just return null if you add some new OData endpoints into this sample.");
10897
}
10998
}
11099

sample/ODataRoutingSample/readme.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,21 @@ If you run the sample and send the following request in a Web brower:
9090
{
9191
"$ref": "#/components/parameters/skip"
9292
},
93-
94-
93+
....
94+
}
9595
```
9696

9797
You can use `$format=application/{yaml|json};version={2.0|3.0}` to get openApi in different format and version.
98+
99+
You may notice the above Raw OpenAPI document can achieve using the middleware or using the controller (ODataOpenApiController).
100+
101+
By default, the sample enables the OpenAPI middleware using
102+
103+
```C#
104+
// If you want to use /$openapi, enable the middleware.
105+
app.UseODataOpenApi();
106+
```
107+
108+
So the OpenAPI request is handled by middleware and the controller action is not hit by default.
109+
110+
If you want to use/test the `ODataOpenApiController`, please simply remove 'app.UseODataOpenApi();`. Then the controller/action will be called.

0 commit comments

Comments
 (0)