Skip to content

Commit efd2bfb

Browse files
committed
feat; adds a method to register and add the component schemas
Signed-off-by: Vincent Biret <[email protected]>
1 parent 72db982 commit efd2bfb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,21 @@ public static ReadResult Parse(string input,
587587
{
588588
return OpenApiModelFactory.Parse(input, format, settings);
589589
}
590+
/// <summary>
591+
/// Adds a schema to the components object of the current document.
592+
/// </summary>
593+
/// <param name="openApiSchema">The schema to add</param>
594+
/// <param name="id">The id for the component</param>
595+
/// <returns>Whether the schema was added to the components.</returns>
596+
public bool AddComponentSchema(string id, OpenApiSchema openApiSchema)
597+
{
598+
Utils.CheckArgumentNull(openApiSchema);
599+
Utils.CheckArgumentNullOrEmpty(id);
600+
Components ??= new();
601+
Components.Schemas ??= new Dictionary<string, OpenApiSchema>();
602+
Components.Schemas.Add(id, openApiSchema);
603+
return Workspace?.RegisterSchemaForDocument(this, openApiSchema, id) ?? false;
604+
}
590605
}
591606

592607
internal class FindSchemaReferences : OpenApiVisitorBase

0 commit comments

Comments
 (0)