---
lang: en
title: 'API docs: openapi-spec-builder.openapispecbuilder.withcomponents'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/openapi-spec-builder
permalink: /doc/en/lb4/apidocs.openapi-spec-builder.openapispecbuilder.withcomponents.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/openapi-spec-builder](./openapi-spec-builder.md) &gt; [OpenApiSpecBuilder](./openapi-spec-builder.openapispecbuilder.md) &gt; [withComponents](./openapi-spec-builder.openapispecbuilder.withcomponents.md)

## OpenApiSpecBuilder.withComponents() method

Define a new ComponentsObject.

**Signature:**

```typescript
withComponents(spec: ComponentsObject | ComponentsSpecBuilder): this;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td markdown="1">

spec


</td><td markdown="1">

ComponentsObject \| [ComponentsSpecBuilder](./openapi-spec-builder.componentsspecbuilder.md)


</td><td markdown="1">

Specification of the components.


</td></tr>
</tbody></table>

**Returns:**

this


