Title: Consider returning reference type from `AddComponent` API · Issue #2162 · microsoft/OpenAPI.NET · GitHub
Open Graph Title: Consider returning reference type from `AddComponent` API · Issue #2162 · microsoft/OpenAPI.NET
X Title: Consider returning reference type from `AddComponent` API · Issue #2162 · microsoft/OpenAPI.NET
Description: 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.OpenAP...
Open Graph Description: 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 tha...
X Description: 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 tha...
Opengraph URL: https://github.com/microsoft/OpenAPI.NET/issues/2162
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Consider returning reference type from `AddComponent` API","articleBody":"The `AddComponent` API currently returns a boolean that indicates if the addition of the component to the document registry succeeded.\n\nIt 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:\n\n```csharp\noptions.AddOperationTransformer((operation, context, cancellationToken) =\u003e\n{\n var schemaService = context.ApplicationServices.GetRequiredKeyedService\u003cIOpenApiSchemaService\u003e(context.DocumentName);\n if (context.Description.RelativePath == \"error\")\n {\n var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));\n context.Document.AddComponent(\"Error\", errorSchema);\n operation.Responses[\"500\"] = new OpenApiResponse\n {\n Description = \"Error\",\n Content =\n {\n [\"application/problem+json\"] = new OpenApiMediaType\n {\n Schema = new OpenApiSchemaReference(\"Error\", context.Document),\n },\n },\n };\n }\n return Task.CompletedTask;\n});\n```\n\nbut would like to write:\n\n```csharp\noptions.AddOperationTransformer((operation, context, cancellationToken) =\u003e\n{\n var schemaService = context.ApplicationServices.GetRequiredKeyedService\u003cIOpenApiSchemaService\u003e(context.DocumentName);\n if (context.Description.RelativePath == \"error\")\n {\n var errorSchema = schemaService.GetOrCreateSchema(typeof(ProblemDetails));\n var insertedSchema = context.Document.AddComponent(\"Error\", errorSchema);\n operation.Responses[\"500\"] = new OpenApiResponse\n {\n Description = \"Error\",\n Content =\n {\n [\"application/problem+json\"] = new OpenApiMediaType\n {\n Schema = insertedSchema,\n },\n },\n };\n }\n return Task.CompletedTask;\n});\n```\n\ncc: @baywet I couldn't see if an API that did this existed already and figured I'd add the proposal.","author":{"url":"https://github.com/captainsafia","@type":"Person","name":"captainsafia"},"datePublished":"2025-02-24T16:53:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/2162/OpenAPI.NET/issues/2162"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5cb1f0f6-fb9d-a054-d268-6406715fee0b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9BB6:1580D:912BD2:BDF641:69814951 |
| html-safe-nonce | c508fb128dd16075db969b49f6ade5b170c88f4e76ed7836d1d1952e9b67d4a7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QkI2OjE1ODBEOjkxMkJEMjpCREY2NDE6Njk4MTQ5NTEiLCJ2aXNpdG9yX2lkIjoiNzE3MDkyMTU1NTczMDQ1MDc2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 92095dda271bcf1d8994542f6e1ce6ef6fa19f3c94742a963a82ae8243454c58 |
| hovercard-subject-tag | issue:2875607190 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/OpenAPI.NET/2162/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d0c699672a3960d87869716bd2a01a2c3821b228f7dcc1a4130c0c88df58821/microsoft/OpenAPI.NET/issues/2162 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d0c699672a3960d87869716bd2a01a2c3821b228f7dcc1a4130c0c88df58821/microsoft/OpenAPI.NET/issues/2162 |
| og:image:alt | 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 tha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | captainsafia |
| hostname | github.com |
| expected-hostname | github.com |
| None | e5c6a4b0d37e7dc8f18034781c9e3e492fdd80eb16410763ec244c3e1caf0805 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/OpenAPI.NET git https://github.com/microsoft/OpenAPI.NET.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 97175798 |
| octolytics-dimension-repository_nwo | microsoft/OpenAPI.NET |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 97175798 |
| octolytics-dimension-repository_network_root_nwo | microsoft/OpenAPI.NET |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 906ec698502db8129a94bb04f4413119a1291133 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width