C
C#6mo ago
kmanjt

Resolving External $ref Paths With Nested Refs in NSwag for OpenAPI Specification in C#

When attempting to generate the C# client, I encounter errors like System.InvalidOperationException: Could not resolve the path '#/components/schemas/SomeSchema'. This error suggests that NSwag cannot resolve the external references, even though the paths are correctly specified. Here is what the ref looks like:
components:
schemas:
SomeSchema:
$ref: './external_definitions.yml#/components/schemas/SomeSchema'
components:
schemas:
SomeSchema:
$ref: './external_definitions.yml#/components/schemas/SomeSchema'
EDIT: Here is an example of the SomeSchema definition - the issue are the nested references I believe:
SomeSchema:
type: object
properties:
Identifier:
$ref: '#/components/schemas/UniqueIdentifier'
nullable: true
Status:
$ref: '#/components/schemas/StatusType'
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
DeploymentMetadata:
$ref: '#/components/schemas/DeploymentMetadataType'
nullable: true
SomeSchema:
type: object
properties:
Identifier:
$ref: '#/components/schemas/UniqueIdentifier'
nullable: true
Status:
$ref: '#/components/schemas/StatusType'
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
DeploymentMetadata:
$ref: '#/components/schemas/DeploymentMetadataType'
nullable: true
Has anyone successfully resolved external $ref paths with nested schemas using NSwag?
1 Reply
Want results from more Discord servers?
Add your server