Skip to content

Commit 10e548a

Browse files
committed
feat: adds components registration method for schemas
Signed-off-by: Vincent Biret <[email protected]>
1 parent 0a7b4f6 commit 10e548a

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/Microsoft.OpenApi/Services/OpenApiWorkspace.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void RegisterComponents(OpenApiDocument document)
6464
{
6565
if (document?.Components == null) return;
6666

67-
string baseUri = document.BaseUri + OpenApiConstants.ComponentsSegment;
67+
string baseUri = getBaseUri(document);
6868
string location;
6969

7070
// Register Schema
@@ -139,6 +139,33 @@ public void RegisterComponents(OpenApiDocument document)
139139
}
140140
}
141141

142+
private string getBaseUri(OpenApiDocument openApiDocument)
143+
{
144+
return openApiDocument.BaseUri + OpenApiConstants.ComponentsSegment;
145+
}
146+
147+
/// <summary>
148+
/// Registers a schema for a document in the workspace
149+
/// </summary>
150+
/// <param name="openApiDocument">The document to register the schema for.</param>
151+
/// <param name="openApiSchema">The schema to register.</param>
152+
/// <param name="id">The id of the schema.</param>
153+
/// <returns>true if the schema is successfully registered; otherwise false.</returns>
154+
/// <exception cref="ArgumentNullException">openApiDocument is null</exception>
155+
/// <exception cref="ArgumentNullException">openApiSchema is null</exception>
156+
/// <exception cref="ArgumentNullException">id is null or empty</exception>
157+
public bool RegisterSchemaForDocument(OpenApiDocument openApiDocument, OpenApiSchema openApiSchema, string id)
158+
{
159+
Utils.CheckArgumentNull(openApiDocument);
160+
Utils.CheckArgumentNull(openApiSchema);
161+
Utils.CheckArgumentNullOrEmpty(id);
162+
163+
var baseUri = getBaseUri(openApiDocument);
164+
165+
var location = baseUri + ReferenceType.Schema.GetDisplayName() + ComponentSegmentSeparator + id;
166+
167+
return RegisterComponent(location, openApiSchema);
168+
}
142169

143170
/// <summary>
144171
/// Registers a component in the component registry.

0 commit comments

Comments
 (0)