修复 WebApi OpenAPI Schema 生成不符合规范的问题 - #138
Open
kimdiego2098 wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for touchsocket canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题说明
UseOpenApi生成的openapi.json无法被 Swagger Editor 等标准 OpenAPI 工具正常解析,主要存在以下问题:type被输出为String、Integer、Array等大写值,不符合 OpenAPI 规范。components.schemas中的对象 Schema 使用$ref指向自身,形成循环引用。$ref。修改内容
object + properties,避免自引用。GetSchemaName生成泛型 Schema 名称和引用。type: integernullable: trueGuid和Uri类型处理。[JsonPropertyName]显式名称。修复示例
修复前:
{ "$ref": "#/components/schemas/Variable", "properties": { "Name": { "type": "String" } } }修复后:
{ "type": "object", "properties": { "name": { "type": "string" } } }