Skip to content

Reference Resolution

Alex Wichmann edited this page Feb 22, 2023 · 1 revision

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

ActionDefault
WritingDoNotInlineReferences
ReadingResolveReferences

Writing

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: objectrequired:
- testBproperties:
testC:
$ref: '#/components/schemas/testC'testB:
$ref: '#/components/schemas/testB'components:
schemas:
testD:
type: stringformat: uuidtestC:
type: objectproperties:
testD:
$ref: '#/components/schemas/testD'testB:
type: booleandescription: test

Setting InlineReferences to true, will yield a document looking like the following

channels:
mychannel:
publish:
message:
payload:
type: objectrequired:
- testBproperties:
testC:
type: objectproperties:
testD:
type: stringformat: uuidtestB:
type: booleandescription: testcomponents: { }

Notice that all of the references are in-lined, and removed from the components section, as they are not needed anymore.

Overriding default settings

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.

varoutputString=newStringWriter(CultureInfo.InvariantCulture);varwriter=newAsyncApiYamlWriter(outputString,newAsyncApiWriterSettings{ReferenceInline=ReferenceInlineSetting.InlineReferences});asyncApiDocument.SerializeV2(writer);

Reading

Overriding default settings

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.

varreader=newAsyncApiStringReader(newAsyncApiReaderSettings{ReferenceResolution=ReferenceResolutionSetting.DoNotResolveReferences});

Clone this wiki locally