Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operationIdFactory does not respect all versioning types #3268

Open
2 of 4 tasks
triforcely opened this issue Jan 23, 2025 · 0 comments
Open
2 of 4 tasks

operationIdFactory does not respect all versioning types #3268

triforcely opened this issue Jan 23, 2025 · 0 comments

Comments

@triforcely
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I'm trying to implement a custom versioning pattern (some modules use path and some header) with multiple documents served per version. My plan is to include all of the metadata that I need in the operationId and then do the filtering per document in patchDocumentOnRequest function.

I found a bug in the "operationIdFactory", where it only receives version parameter from path versioning.

Take a look at this example:

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return this.appService.getHello();
  }

  @Get()
  @Version('2')
  getHelloV2(): string {
    return this.appService.getHello();
  }
}
  app.enableVersioning({
    type: VersioningType.CUSTOM,
    defaultVersion: '1',
    extractor(request) {
      return '1.0'; // irrelevant for the example
    }
  });

  const documentOptions = new DocumentBuilder()
    .setTitle(`repro | OpenAPI`)
    .setVersion('1.0')
    .build();

  SwaggerModule.createDocument(app, documentOptions, {
    operationIdFactory: (controllerKey, methodKey, version) => {
      const opId = `${controllerKey}_${methodKey}_${version}`;
      console.log(opId); // AppController_getHelloV2_undefined
      return opId;
    }
  });

It seems that it is hardcoded that the only version that is being passed to the 'getOperationId' function is the pathVersion, ignoring method and controller versions:

operationId: this.getOperationId(instance, methodKey, pathVersion),

Minimum reproduction code

https://github.com/triforcely/nest-js-operationifactorybug

Steps to reproduce

No response

Expected behavior

When any api versioning is present, the parameter shouldn't be undefined.

Package version

11.0.3

NestJS version

11.0.5

Node.js version

22.13.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant