#Feature flags and class properties

3 messages · Page 1 of 1 (latest)

cinder kelp
#

Hi all 👋

I'm researching feature flags support for NestJS. Basically I would like to control endpoints and objects behaviour by environmental variables. Without rebuilding the app. Reload is fine. To what extent it is possible with NestJS?

My main goals is to show/hide object property in the response. Make some field required or not while creating entity via POST. And I would like this changes to be reflected by swagger / openapi.

For hiding/showing routes I already found decorators ApiExcludeEndpoint and ApiExcludeController and they can take disabled as argument. Works well with app reload only.

I found some clues that interceptors could be used for deleting fields from the response. And openapi document can be manipulated on creation phase. But I'm not sure how reliable this approach is.

Do you folks know about better ways to achieve that?

  @ApiProperty()
  name: string;
  @ApiHideProperty()
  surname: string;
  @ApiProperty()
  passportNumber: string; // only visible if process.env.FEATURE_PASSPORT === true 
}
zinc snow
#

For properties, it's @ApiHideProperty()

#

you can conditionally use it with

const ApiPropertyIfPassport = (args) => process.env.FEATURE_PASSPORT
    ? ApiProperty(args)
    : ApiHideProperty(args)