-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Feature/8844 api version in route info #10484
Merged
kamilmysliwiec
merged 11 commits into
nestjs:master
from
thiagomini:feature/8844-api-version-in-route-info
Nov 7, 2022
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d3aae1d
feat(core): add version attribute to routes mapper
thiagomini 1376034
feat(core): add version attribute to routes mapper
thiagomini 439652a
test(core): ensure middleware builder gets version
thiagomini bd5c060
feat(core): add version to middleware module
thiagomini 415858f
test(integration): wrap test case for uri version
thiagomini 4a03932
fix(core): fix middleware for versioned routes
thiagomini cf1b946
fix(core): fix middleware for versioned routes
thiagomini 25f03c4
test(integration): add middleware test
thiagomini 092e721
test(ingration): refactor middleware tests
thiagomini e36acea
feat(core): add middleware versioning support
thiagomini 4176ee5
fix(core): add missing parameter for module
thiagomini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
integration/hello-world/e2e/middleware-with-versioning.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
Controller, | ||
Get, | ||
INestApplication, | ||
MiddlewareConsumer, | ||
Module, | ||
Version, | ||
RequestMethod, | ||
VersioningType, | ||
VERSION_NEUTRAL, | ||
} from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import * as request from 'supertest'; | ||
import { AppModule } from '../src/app.module'; | ||
|
||
const RETURN_VALUE = 'test'; | ||
const VERSIONED_VALUE = 'test_versioned'; | ||
|
||
@Controller() | ||
class TestController { | ||
@Version('1') | ||
@Get('versioned') | ||
versionedTest() { | ||
return RETURN_VALUE; | ||
} | ||
} | ||
|
||
@Module({ | ||
imports: [AppModule], | ||
controllers: [TestController], | ||
}) | ||
class TestModule { | ||
configure(consumer: MiddlewareConsumer) { | ||
consumer | ||
.apply((req, res, next) => res.send(VERSIONED_VALUE)) | ||
.forRoutes({ | ||
path: '/versioned', | ||
version: '1', | ||
method: RequestMethod.ALL, | ||
}); | ||
} | ||
} | ||
|
||
describe('Middleware', () => { | ||
let app: INestApplication; | ||
|
||
beforeEach(async () => { | ||
app = ( | ||
await Test.createTestingModule({ | ||
imports: [TestModule], | ||
}).compile() | ||
).createNestApplication(); | ||
|
||
app.enableVersioning({ | ||
type: VersioningType.URI, | ||
defaultVersion: VERSION_NEUTRAL, | ||
}); | ||
await app.init(); | ||
}); | ||
|
||
it(`forRoutes({ path: 'tests/versioned', version: '1', method: RequestMethod.ALL })`, () => { | ||
return request(app.getHttpServer()) | ||
.get('/v1/versioned') | ||
.expect(200, VERSIONED_VALUE); | ||
}); | ||
|
||
afterEach(async () => { | ||
await app.close(); | ||
}); | ||
}); |
2 changes: 2 additions & 0 deletions
2
packages/common/interfaces/middleware/middleware-configuration.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I extracted many logic branches here to private methods to improve the public method's readability.