Skip to content

Commit

Permalink
Fixes #1399: Fix OpenAPI codes in ODataRoutingSample
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Feb 5, 2025
1 parent 5b87e2b commit c860cdc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public ContentResult GetV2OpenApi(string data)
return CreateContent(document);
}

[HttpGet("v3/$openapi")]
public ContentResult GetV3OpenApi(string data)
{
OpenApiDocument document = CreateDocument("v3");
return CreateContent(document);
}

private ContentResult CreateContent(OpenApiDocument document)
{
HttpContext httpContext = Request.HttpContext;
Expand Down
21 changes: 5 additions & 16 deletions sample/ODataRoutingSample/OpenApi/ODataPathTranslater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public static ODataPath Translate(this ODataPathTemplate pathTemplate, IEdmModel
case PropertySegmentTemplate property:
// TODO:
return null;
//PropertySegmentTemplate property = (PropertySegmentTemplate)segment;
//newSegments.Add(property.ConvertTo());
//break;

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

case ValueSegmentTemplate value:
return null;
//ValueSegmentTemplate value = (ValueSegmentTemplate)segment;
//newSegments.Add(value.ConvertTo());
//break;

case NavigationLinkSegmentTemplate navigationLink:
return null;
//NavigationLinkSegmentTemplate navigationLink = (NavigationLinkSegmentTemplate)segment;
//newSegments.Add(navigationLink.ConvertTo());
//break;

case CountSegmentTemplate count:
newSegments.Add(count.ConvertTo());
break;

case PathTemplateSegmentTemplate:
return null;
//KeySegmentTemplate key = (KeySegmentTemplate)segment;
//newSegments.Add(key.ConvertTo());
//break;

case DynamicSegmentTemplate:
return null;
//KeySegmentTemplate key = (KeySegmentTemplate)segment;
//newSegments.Add(key.ConvertTo());
//break;

case NavigationLinkTemplateSegmentTemplate navigationLinkTemplate:
return null;

default:
throw new NotSupportedException();
return null;
// throw new NotSupportedException("Please update codes here, maybe just return null if you add some new OData endpoints into this sample.");
}
}

Expand Down
17 changes: 15 additions & 2 deletions sample/ODataRoutingSample/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,21 @@ If you run the sample and send the following request in a Web brower:
{
"$ref": "#/components/parameters/skip"
},

....
}
```

You can use `$format=application/{yaml|json};version={2.0|3.0}` to get openApi in different format and version.

You may notice the above Raw OpenAPI document can achieve using the middleware or using the controller (ODataOpenApiController).

By default, the sample enables the OpenAPI middleware using

```C#
// If you want to use /$openapi, enable the middleware.
app.UseODataOpenApi();
```

So the OpenAPI request is handled by middleware and the controller action is not hit by default.

If you want to use/test the `ODataOpenApiController`, please simply remove 'app.UseODataOpenApi();`. Then the controller/action will be called.

0 comments on commit c860cdc

Please sign in to comment.