New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add swagger model APIs #520
Conversation
/// <summary> | ||
/// Represents an <see cref="ODataSwaggerConverter"/> used to converter an Edm model to Swagger model. | ||
/// </summary> | ||
public class ODataSwaggerConverter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E2E test case to show how customers can create a controller or action to return swagger spec, when a request uri is:
~/service.root/swagger.json, or ~/service.root/$swagger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my new updated. Thanks
b31d111
to
7994f5c
Compare
@OData/odata-team I update the PR. Would you please take a look? Thanks |
} | ||
|
||
/// <summary> | ||
/// Convert the Edm model to Swagger model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Converts? Same for verbs below. Since Verbs above are all have suffixes. Just keep consistent, with or without suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good.
Merged. Thanks. |
Many thanks to OData team for adding swagger generation. However, there is still a problem with the resulting swagger output in interoperability with Azure. For example, AutoRest is a tool which generates client code from swagger.json and it requires OperationIDs on all operations. https://github.com/Azure/autorest The swagger being output from WebAPIOData is missing the required OperationIDs. Not sure if this can be fixed before 5.8 release but it would be really swell if the resulting swagger was Azure compliant. |
Wait, you guys added Swagger generation to OData and didn't tell me about it? Shame on you @markdstafford for losing touch with me. :) BUT SERIOUSLY. Where's a sample, I need to party on this with Justice. |
@bradygaster the swagger gen was merged but not yet released. You can clone and build to try it out. The sample code is in the test here: I'm afraid, cuz they didn't use swashbuckle, we cannot override and affect the swagger output. Hope I'm wrong on that. |
@joshbooker, we added operationId for operations in PR #552, would you please try it out and let us know any issues, thanks. |
Wow...Thanks! ...Ask and you a shall receive! I haven't tried this yet, but have one more suggestion: OperationIds are used in AutoRest to generate Classes using a naming convention. For example, consider the following swagger: "paths": { If there is an underscore in the OperationId, AutoRest will use the convention [ClassName_MethodName] to generate a Customers class having .Get and .GetById as methods. It would be really swell if OData swagger used this convention for OperationIds. Also see this early example of how WebAPI team handles multi parameter operations: I believe WebAPI team recently settled on a swashbuckle IOperationFilter that handles this, but cannot find a blog about that. Maybe @bradygaster has more info. |
PS...Is any of the OData swagger gen override-able? It would be great if we could have more control over swagger output. Did you consider allowing APIExplorer and using swashbuckle as the rest of WebAPI team is doing? |
@joshbooker , we updated the naming convention for operationId in #552, and the swagger format could be customized by overriding methods in |
@bradygaster - ;) You of all people know how high on my priority list this is. To be clear, there's a big loss of fidelity still and a lot of work to do even just within our bits. |
@markdstafford thanks for the comments and your teams fast turn around is impressive. Perhaps look at swashbuckle ISwaggerProvider for wrapping your custom swagger gen. Curious whether that would enable post-gen customization of swag via swagger.config making this more on par with webAPI method for affecting swagger output. Thanks for listening. |
yes indeed i know how high a pri this is for you @markdstafford and like @joshbooker i sincerely appreciate the efforts you're putting into this. |
Does this work for RESTier? I tried this in vanilla WebAPI\OData project and was indeed able to get swagger output by building system.web.odata and then using code from the PR#552 test project (SwaggerController, SwaggerPathHandler, SwaggerPathSegment, SwaggerRoutingCovention, etc.) Let me know if I'm off track here - basically I'm hoping:
Thanks for listening. |
@joshbooker Our original design to support $swagger is same as $metadata. However, it's rejected by some reason. If you want to get the original implementation, please let me know. I can share it. |
The goal of swagger support in OData v4 Web API is with flexibility and can be customized. This requires:
|
Thanks for your replies. |
@markdstafford Here is an example of extending Swashbuckle for OData by wrapping your converter in ISwaggerProvider. https://github.com/rbeauchamp/Swashbuckle.OData |
Not sure if anyone's still listening to this closed PR but.... |
@joshbooker Sorry, I don't listen to this closed PR recently. I re-open it to track on. |
@joshbooker you can find our original implementation here. Thanks. |
@joshbooker The |
@xuzhg @congysu Thanks all for reopening. Just to clarify...
If you simply add ODataSwaggerProvider.cs to System.Web.OData then you're done. Thanks again for listening. |
Welcome @joshbooker, @rbeauchamp's contribution to the OData/WebApi repo. Re-opened #302. |
FYI, item 3) from @joshbooker's comment above is now supported in Swashbuckle.OData. See rbeauchamp/Swashbuckle.OData#8 |
Closed it. Please file new issues if you find any problem related to the swagger support. Thanks. |
Add the Utility method for Swagger converter