简体   繁体   English

元数据,OpenAPI和Swagger之间的ServiceStack混淆

[英]ServiceStack confusion between metadata, OpenAPI, and Swagger

I'm working on documentation for an API server implemented using ServiceStack. 我正在处理使用ServiceStack实现的API服务器的文档。 I have a few questions. 我有几个问题。 If it makes more sense, I can move these to separate posts. 如果更有意义,我可以将其移至不同的职位。

  1. IgnoreDataMember is mentioned in multiple places as the way to hide DTO properties from metadata, but that's not an option if you publish the message to queue since that works via serialization and it skips those fields... IgnoreDataMember在很多地方都提到了从元数据中隐藏DTO属性的方法,但是如果您将消息发布到队列中,则不是一种选择,因为它可以通过序列化工作,并且会跳过这些字段...

  2. The Exclude attribute [Exclude(Feature.Metadata)] is supposed to hide DTO's from the meatadata page. Exclude属性[Exclude(Feature.Metadata)]应该可以在Meatadata页面中隐藏DTO。 While it works at top-level classes, it doesn't filter out properties of a base class. 尽管它可以在顶级类上运行,但不会过滤掉基类的属性。 In other words if MyBaseDto is marked to exlude, but MyEndpointDto inherits from MyBaseDto, properties from both classes are shown. 换句话说,如果将MyBaseDto标记为排除,但MyEndpointDto继承自MyBaseDto,则会显示两个类的属性。 Is this a bug? 这是错误吗?

  3. Removing services from metadata works really well, but I don't see how to remove them from Swagger/OpenAPI. 从元数据中删除服务确实很好,但是我看不到如何从Swagger / OpenAPI中删除它们。 I can implement the OperationFilter callback, but there's no obvious way there to actually remove anything. 我可以实现OperationFilter回调,但是实际上没有任何方法可以删除任何内容。 If I use the ResourceFilterPattern regex property, it works by DTO, not route. 如果我使用ResourceFilterPattern regex属性,则它通过DTO(而不是路由)工作。 I'd love to remove any route that starts with /internal for instance. 我想删除例如以/ internal开头的任何路由。

  4. The LogoUrl property of the OpenApiFeature and SwaggerFeature doesn't seem to actually affect the page anywhere. OpenApiFeature和SwaggerFeature的LogoUrl属性似乎并未真正影响任何地方的页面。 Is there another step to take? 还需要采取其他步骤吗?

  5. On the Swagger UI page, why does every route include the text " XX is not defined!" 在Swagger UI页面上,为什么每个路由都包含文本“未定义XX!”。 I'm not sure what's it's supposed to be pull from. 我不确定应该从中提取什么。

  6. I need help understanding how OpenAPI and Swagger fit together. 我需要帮助来了解OpenAPI和Swagger如何配合使用。 Why are they two separate features? 为什么它们有两个独立的功能? If I just add the OpenAPI feature, I can still bring up the Swagger UI. 如果仅添加OpenAPI功能,我仍然可以调出Swagger UI。 What does the Swagger feature bring to the table? Swagger功能为您带来了什么?

The difference between ServiceStack's Swagger Feature and Open API is that Swagger Feature implements the older Swagger 1.2 spec where as Open API implements the newer Swagger 2.0 spec which has been renamed from Swagger. ServiceStack的Swagger功能Open API之间的区别在于Swagger功能实现了较早的Swagger 1.2规范,而Open API则实现了从Swagger重命名的较新的Swagger 2.0规范 If you're unsure which to use, use the newer Open API. 如果不确定使用哪个,请使用较新的Open API。

Swagger UI is just the UI and ServiceStack bundles a version of the Swagger UI which works with both the older Swagger 1.2 spec as well as the newer Open API 2.0 spec. Swagger UI只是UI,ServiceStack捆绑了Swagger UI的一个版本,该版本可与旧版Swagger 1.2规范以及新版Open API 2.0规范一起使用。

[Exclude(Feature.Metadata)] or [ExcludeMetadata] works as intended, annotate it on DTOs you wish to exclude from ServiceStack's metadata services which also removes them being included in the returned Swagger/Open API spec + UI. [Exclude(Feature.Metadata)][ExcludeMetadata]可以按预期工作,在您希望从ServiceStack的元数据服务中排除的DTO上进行注释,这些DTO也会将其包含在返回的Swagger / Open API规范+ UI中。

You can use the ApiDeclarationFilter to modify the entire OpenApiDeclaration before it's returned, you can remove routes by removing them from the Paths Dictionary and Types definitions from being included by removing them from Definitions Dictionary. 您可以使用ApiDeclarationFilter修改整个OpenApiDeclaration然后再将其返回,也可以通过从“ Paths字典”中删除它们来删除路由,并通过从“ Definitions字典”中删除它们来将其包括在内。 You can submit other feature requests for missing features you want implemented . 您可以针对要实现的缺少功能提交其他功能请求。

The LogoUrl has been fixed for Open API and we've also added LogoHref so you can change the url that the logo goes to which by default refreshes the Swagger UI page. LogoUrl已针对Open API进行了修复,我们还添加了LogoHref因此您可以更改徽标所指向的url,默认情况下将刷新Swagger UI页面。 This change is available from v4.5.13 that's now available on MyGet . v4.5.13提供了此更改,现在MyGet上可用

Open API is the spec Swagger UI is the UI Open API是规范Swagger UI是UI

The purpose of both Open API and Swagger plugins is to implement the Swagger specification which is a generic and machine readable json format to describe Service APIs. Open API和Swagger插件的目的都是实现Swagger规范,这是一种通用且可机读的json格式,用于描述Service API。 Only one of the benefits is to provide a dynamic UI which ServiceStack provides by bundling the Swagger UI that works with their respective API versions. 好处之一只是提供ServiceStack通过捆绑可与各自API版本一起使用的Swagger UI来提供的动态UI。 Other purposes of implementing the Open API spec include enabling automated tooling like generating a Azure AutoRest client or importing your Service into Azure's Management API . 实施Open API规范的其他目的包括启用自动化工具,例如生成Azure AutoRest客户端或将服务导入Azure的Management API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM