@@ -588,19 +588,65 @@ public static ReadResult Parse(string input,
588588            return  OpenApiModelFactory . Parse ( input ,  format ,  settings ) ; 
589589        } 
590590        /// <summary> 
591-         /// Adds a schema  to the components object of the current document. 
591+         /// Adds a component  to the components object of the current document and registers it to the underlying workspace . 
592592        /// </summary> 
593-         /// <param name="openApiSchema ">The schema  to add</param> 
593+         /// <param name="componentToRegister ">The component  to add</param> 
594594        /// <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 ) 
595+         /// <typeparam name="T">The type of the component</typeparam> 
596+         /// <returns>Whether the component was added to the components.</returns> 
597+         /// <exception cref="ArgumentNullException">Thrown when the component is null.</exception> 
598+         /// <exception cref="ArgumentException">Thrown when the id is null or empty.</exception> 
599+         public  bool  AddComponent < T > ( string  id ,  T  componentToRegister ) 
597600        { 
598-             Utils . CheckArgumentNull ( openApiSchema ) ; 
601+             Utils . CheckArgumentNull ( componentToRegister ) ; 
599602            Utils . CheckArgumentNullOrEmpty ( id ) ; 
600603            Components  ??=  new ( ) ; 
601-             Components . Schemas  ??=  new  Dictionary < string ,  OpenApiSchema > ( ) ; 
602-             Components . Schemas . Add ( id ,  openApiSchema ) ; 
603-             return  Workspace ? . RegisterSchemaForDocument ( this ,  openApiSchema ,  id )  ??  false ; 
604+             switch  ( componentToRegister ) 
605+             { 
606+                 case  OpenApiSchema  openApiSchema : 
607+                     Components . Schemas  ??=  new  Dictionary < string ,  OpenApiSchema > ( ) ; 
608+                     Components . Schemas . Add ( id ,  openApiSchema ) ; 
609+                     break ; 
610+                 case  OpenApiParameter  openApiParameter : 
611+                     Components . Parameters  ??=  new  Dictionary < string ,  OpenApiParameter > ( ) ; 
612+                     Components . Parameters . Add ( id ,  openApiParameter ) ; 
613+                     break ; 
614+                 case  OpenApiResponse  openApiResponse : 
615+                     Components . Responses  ??=  new  Dictionary < string ,  OpenApiResponse > ( ) ; 
616+                     Components . Responses . Add ( id ,  openApiResponse ) ; 
617+                     break ; 
618+                 case  OpenApiRequestBody  openApiRequestBody : 
619+                     Components . RequestBodies  ??=  new  Dictionary < string ,  OpenApiRequestBody > ( ) ; 
620+                     Components . RequestBodies . Add ( id ,  openApiRequestBody ) ; 
621+                     break ; 
622+                 case  OpenApiLink  openApiLink : 
623+                     Components . Links  ??=  new  Dictionary < string ,  OpenApiLink > ( ) ; 
624+                     Components . Links . Add ( id ,  openApiLink ) ; 
625+                     break ; 
626+                 case  OpenApiCallback  openApiCallback : 
627+                     Components . Callbacks  ??=  new  Dictionary < string ,  OpenApiCallback > ( ) ; 
628+                     Components . Callbacks . Add ( id ,  openApiCallback ) ; 
629+                     break ; 
630+                 case  OpenApiPathItem  openApiPathItem : 
631+                     Components . PathItems  ??=  new  Dictionary < string ,  OpenApiPathItem > ( ) ; 
632+                     Components . PathItems . Add ( id ,  openApiPathItem ) ; 
633+                     break ; 
634+                 case  OpenApiExample  openApiExample : 
635+                     Components . Examples  ??=  new  Dictionary < string ,  OpenApiExample > ( ) ; 
636+                     Components . Examples . Add ( id ,  openApiExample ) ; 
637+                     break ; 
638+                 case  OpenApiHeader  openApiHeader : 
639+                     Components . Headers  ??=  new  Dictionary < string ,  OpenApiHeader > ( ) ; 
640+                     Components . Headers . Add ( id ,  openApiHeader ) ; 
641+                     break ; 
642+                 case  OpenApiSecurityScheme  openApiSecurityScheme : 
643+                     Components . SecuritySchemes  ??=  new  Dictionary < string ,  OpenApiSecurityScheme > ( ) ; 
644+                     Components . SecuritySchemes . Add ( id ,  openApiSecurityScheme ) ; 
645+                     break ; 
646+                 default : 
647+                     throw  new  ArgumentException ( $ "Component type { componentToRegister ! . GetType ( ) . Name }  is not supported.") ; 
648+             } 
649+             return  Workspace ? . RegisterComponentForDocument ( this ,  componentToRegister ,  id )  ??  false ; 
604650        } 
605651    } 
606652
0 commit comments