Разрешение внешних путей $ref с вложенными ссылками в NSwag для спецификации OpenAPI на C#C#

Место общения программистов C#
Anonymous
Разрешение внешних путей $ref с вложенными ссылками в NSwag для спецификации OpenAPI на C#

Сообщение Anonymous »

Я использую NSwag в среде .NET для создания клиента C# на основе спецификации OpenAPI 3.0.1. Моя спецификация OpenAPI включает компоненты, определенные во внешних файлах, но NSwag не может разрешить эти внешние ссылки, особенно с вложенными схемами.
При попытке создать клиент C# я сталкиваюсь с такими ошибками, как System.InvalidOperationException: не удалось разрешить путь «#/компоненты/схемы/SomeSchema». Эта ошибка предполагает, что NSwag не может разрешить внешние ссылки, даже если пути указаны правильно.
Вот как выглядит ссылка:

Код: Выделить всё

components:
schemas:
SomeSchema:
$ref: './external_definitions.yml#/components/schemas/SomeSchema'

РЕДАКТИРОВАТЬ: Вот пример определения SomeSchema - я считаю, что проблема во вложенных ссылках:

Код: Выделить всё

SomeSchema:
type: object
properties:
Version:
type: integer
nullable: true
Identifier:
$ref: '#/components/schemas/UniqueIdentifier'
nullable: true
Name:
type: string
nullable: true
Organization:
type: string
nullable: true
ModifiedTime:
type: string
format: date-time
nullable: true
ModifiedBy:
type: string
nullable: true
Status:
$ref: '#/components/schemas/StatusType'
nullable: true
Details:
type: string
nullable: true
Labels:
type: array
items:
type: string
nullable: true
Category:
type: string
nullable: true
ReviewPeriod:
type: string
format: time-span
nullable: true
UpdateFrequency:
type: string
format: time-span
nullable: true
Calculations:
type: array
items:
$ref: '#/components/schemas/CalculationType'
nullable: true
DataSources:
type: array
items:
$ref: '#/components/schemas/DataSourceType'
nullable: true
Dimensions:
type: array
items:
$ref: '#/components/schemas/DimensionFilterType'
nullable: true
Conditions:
type: array
items:
$ref: '#/components/schemas/ConditionType'
nullable: true
Outputs:
type: array
items:
$ref: '#/components/schemas/OutputType'
nullable: true
ExtendedConfig:
$ref: '#/components/schemas/AdvancedConfigType'
nullable: true
AutoAdjustmentConfig:
$ref: '#/components/schemas/AdjustmentConfigType'
nullable: true
EnrichmentConfig:
$ref: '#/components/schemas/EnrichmentConfigType'
nullable: true
Metadata:
type: object
additionalProperties:
type: string
nullable: true
HandlingNullData:
$ref: '#/components/schemas/NullDataHandlingType'
nullable: true
DeploymentMetadata:
$ref: '#/components/schemas/DeploymentMetadataType'
nullable: true
Я подтвердил, что пути к файлам верны относительно места выполнения NSwag.
Пытался упростить $ref, чтобы он ссылался на более простые схемы, которые работали, но вложенные схемы не помогли.
p>
Причина, по которой я это делаю, заключается в том, что я хочу, чтобы спецификация шлюза использовала схемы для спецификации из другой службы и чтобы избежать их дублирования.
Другой вариант, который, казалось, работал, заключался в том, чтобы ссылаться на вложенные схемы, но их слишком много, и в конечном итоге это становится для меня очень запутанным.
Кто-нибудь успешно разрешил внешние $ ref-пути с вложенными схемами с использованием NSwag?
Есть ли какие-либо конкретные конфигурации или обходные пути в NSwag или NJsonSchema, которые мне могут не хватать, чтобы лучше справиться с этой ситуацией?
Буду очень признателен за любую помощь или указания на то, что может пойти не так или как это исправить.
РЕДАКТИРОВАТЬ:
Я пытался извлечь общие компоненты в собственный OpenAPI. spec, а затем использовать его в других спецификациях, спецификация компонентов была определена следующим образом - игнорируйте любые очевидные синтаксические ошибки:
data.yml:
< pre class="lang-yaml Prettyprint-override">

Код: Выделить всё

components:
schemas:
SomeSchema:
type: object
properties:
Version:
type: integer
nullable: true
Identifier:
$ref: './data.yml#/components/schemas/UniqueIdentifier'
nullable: true
Name:
type: string
nullable: true
Organization:
type: string
nullable: true
ModifiedTime:
type: string
format: date-time
nullable: true
ModifiedBy:
type: string
nullable: true
Status:
$ref: './data.yml#/components/schemas/StatusType'
nullable: true
Details:
type: string
nullable: true
Labels:
type: array
items:
type: string
nullable: true
Category:
type: string
nullable: true
ReviewPeriod:
type: string
format: time-span
nullable: true
UpdateFrequency:
type: string
format: time-span
nullable: true
Calculations:
type: array
items:
$ref: './data.yml#/components/schemas/CalculationType'
nullable: true
DataSources:
type: array
items:
$ref: './data.yml#/components/schemas/DataSourceType'
nullable: true
Dimensions:
type: array
items:
$ref: './data.yml#/components/schemas/DimensionFilterType'
nullable: true
Conditions:
type: array
items:
$ref: './data.yml#/components/schemas/ConditionType'
nullable: true
Outputs:
type: array
items:
$ref: './data.yml#/components/schemas/OutputType'
nullable: true
ExtendedConfig:
$ref: './data.yml#/components/schemas/AdvancedConfigType'
nullable: true
AutoAdjustmentConfig:
$ref: './data.yml#/components/schemas/AdjustmentConfigType'
nullable: true
EnrichmentConfig:
$ref: './data.yml#/components/schemas/EnrichmentConfigType'
nullable: true
Metadata:
type: object
additionalProperties:
type: string
nullable: true
HandlingNullData:
$ref: './data.yml#/components/schemas/NullDataHandlingType'
nullable: true
DeploymentMetadata:
$ref: './data.yml#/components/schemas/DeploymentMetadataType'
nullable: true
Однако я получаю ошибки во втором последнем свойстве при ссылке на SomeSchema из другого файла спецификации в том же каталоге с использованием той же ссылки - так что, похоже, он работает для большинства схем, но не все?
РЕДАКТИРОВАТЬ 05.12.2024: Проблема по-прежнему возникает при более глубокой вложенности. Я проверил это, удалив свойство HandlingNullData, и сбои все равно были. >
Любая помощь приветствуется, спасибо

Подробнее здесь: https://stackoverflow.com/questions/784 ... ecificatio

Вернуться в «C#»