-
Notifications
You must be signed in to change notification settings - Fork 18
Reference Resolution
References currently only work for "internal" as in, within the components section of the document. However any AsyncApiSchema (and by extension JsonSchema) type, can have a reference to the components section.
The default reference resolutions can be seen in the table below
| Action | Default |
|---|---|
| Writing | DoNotInlineReferences |
| Reading | ResolveReferences |
Making an object model that contains references will yield those references written to yaml/json by default Looking something like
channels:
mychannel:
publish:
message:
payload:
type: object
required:
- testB
properties:
testC:
$ref: '#/components/schemas/testC'
testB:
$ref: '#/components/schemas/testB'
components:
schemas:
testD:
type: string
format: uuid
testC:
type: object
properties:
testD:
$ref: '#/components/schemas/testD'
testB:
type: boolean
description: testSetting InlineReferences to true, will yield a document looking like the following
channels:
mychannel:
publish:
message:
payload:
type: object
required:
- testB
properties:
testC:
type: object
properties:
testD:
type: string
format: uuid
testB:
type: boolean
description: test
components: { }Notice that all of the references are in-lined, and removed from the components section, as they are not needed anymore.
You can set the ReferenceResolution mode by using custom (non-default) AsyncApiWriterSettings and setting the ReferenceInline property according to your needs.
Note that the default is DoNotInlineReferences.
var outputString = new StringWriter(CultureInfo.InvariantCulture);
var writer = new AsyncApiYamlWriter(outputString, new AsyncApiWriterSettings { ReferenceInline = ReferenceInlineSetting.InlineReferences });
asyncApiDocument.SerializeV2(writer);You can set the ReferenceResolution mode by using custom (non-default) AsyncApiReaderSettings and setting the ReferenceResolution property according to your needs.
Note that the default is ResolveReferences.
var reader = new AsyncApiStringReader(new AsyncApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences });