Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Consider returning reference type from AddComponent API #2162

Copy link
Copy link
@captainsafia

Description

@captainsafia
Issue body actions

The AddComponent API currently returns a boolean that indicates if the addition of the component to the document registry succeeded.

It would be nice if the API returned a reference to the item that was just constructed. In an M.A.OpenAPI transformer, I currently need to write:

options.AddOperationTransformer((operation, context, cancellationToken) =>
{
    var schemaService = context.ApplicationServices.GetRequiredKeyedService<IOpenApiSchemaService>(context.DocumentName);
    if (context.Description.RelativePath == "error")
    {
        var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));
        context.Document.AddComponent("Error", errorSchema);
        operation.Responses["500"] = new OpenApiResponse
        {
            Description = "Error",
            Content =
            {
                ["application/problem+json"] = new OpenApiMediaType
                {
                    Schema = new OpenApiSchemaReference("Error", context.Document),
                },
            },
        };
    }
    return Task.CompletedTask;
});

but would like to write:

options.AddOperationTransformer((operation, context, cancellationToken) =>
{
    var schemaService = context.ApplicationServices.GetRequiredKeyedService<IOpenApiSchemaService>(context.DocumentName);
    if (context.Description.RelativePath == "error")
    {
        var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));
        var insertedSchema = context.Document.AddComponent("Error", errorSchema);
        operation.Responses["500"] = new OpenApiResponse
        {
            Description = "Error",
            Content =
            {
                ["application/problem+json"] = new OpenApiMediaType
                {
                    Schema = insertedSchema,
                },
            },
        };
    }
    return Task.CompletedTask;
});

cc: @baywet I couldn't see if an API that did this existed already and figured I'd add the proposal.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.