Skip to content

feat: support adding custom fields on the servers[*] entry#3715

Merged
kamilmysliwiec merged 3 commits intonestjs:masterfrom
micalevisk:feat/add-server-custom-fields
Feb 4, 2026
Merged

feat: support adding custom fields on the servers[*] entry#3715
kamilmysliwiec merged 3 commits intonestjs:masterfrom
micalevisk:feat/add-server-custom-fields

Conversation

@micalevisk
Copy link
Copy Markdown
Member

@micalevisk micalevisk commented Feb 1, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

While using the Cloud Endpoints service from Google Cloud, I notice that the document query builder on @nestjs/swagger did not support the following feature of CE: https://docs.cloud.google.com/endpoints/docs/openapi/oasv3-extensions?#x-google-endpoint

servers:
  - url: https://API_NAME.apigateway.PROJECT_ID.cloud.goog/v1
    x-google-endpoint: {}

because we can't add custom fields to the servers[*] entry -- the x-google-endpoint, for example.

There is a way to circumvent that limitation but it looks hacky.

What is the new behavior?

The .addServer now supports a new parameter dedicated for custom attributes for each entry in the servers field of OpenAPI v3. Note that I'm not a fan of having 4 parameters but this was the only way to avoid breaking changes - we could improve that in the next major version.

.addServer("https://API_NAME.apigateway.PROJECT_ID.cloud.goog/v1", "Cloud Endpoints service URL", undefined, {
  'x-google-endpoint': {
    allowCors: true,
   },
   'foo-bar': {},
})

will output the following:

servers:
  - url: https://API_NAME.apigateway.PROJECT_ID.cloud.goog/v1
    description: Cloud Endpoints service URL
    x-google-endpoint:
      allowCors: true
    foo-bar: {}

Does this PR introduce a breaking change?

  • Yes
  • No

@kamilmysliwiec kamilmysliwiec merged commit 4869d1b into nestjs:master Feb 4, 2026
1 check passed
@kamilmysliwiec
Copy link
Copy Markdown
Member

LGTM

@micalevisk micalevisk deleted the feat/add-server-custom-fields branch February 4, 2026 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants