-
Notifications
You must be signed in to change notification settings - Fork 0
feat(openapi-sender): migrate sender to a dedicated package MAPCO-9760 #213
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
Open
netanelC
wants to merge
6
commits into
create-handler
Choose a base branch
from
create-sender
base: create-handler
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6df49d0
feat(openapi-helpers): migrate sender to a dedicated package
netanelC fccb830
Merge branch 'create-handler' of https://github.com/MapColonies/infra…
netanelC 1923c42
style(openapi-helpers): fix lints
netanelC 689c023
Merge branch 'create-handler' of https://github.com/MapColonies/infra…
netanelC 8b3e412
chore(openapi-typed-request-sender): release please
netanelC 4ad87cd
Merge branch 'create-handler' of https://github.com/MapColonies/infra…
netanelC 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
This file contains hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| # openapi-typed-request-sender | ||
|
|
||
| Supertest-based testing utilities that provide full type safety and autocomplete based on OpenAPI specifications. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install --save-dev @map-colonies/openapi-typed-request-sender supertest | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```typescript | ||
| import { createRequestSender, expectResponseStatusFactory } from '@map-colonies/openapi-typed-request-sender'; | ||
| import type { paths, operations } from './types.d.ts'; | ||
|
|
||
| const requestSender = await createRequestSender<paths, operations>('openapi.yaml', expressApp); | ||
|
|
||
| // Call API by operation name! | ||
| const response = await requestSender.getUser({ pathParams: { id: '123' } }); | ||
|
|
||
| // Type-safe status assertion | ||
| const expectResponseStatus = expectResponseStatusFactory(expect); | ||
| expectResponseStatus(response, 200); | ||
|
|
||
| // response.body is now correctly typed for status 200 | ||
| console.log(response.body.name); | ||
| ``` |
4 changes: 2 additions & 2 deletions
4
...openapi-helpers/api-extractor.sender.json → ...i-typed-request-sender/api-extractor.json
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| { | ||
| "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
| "extends": "../../api-extractor.json", | ||
| "mainEntryPointFilePath": "dist/requestSender/requestSender.d.ts", | ||
| "mainEntryPointFilePath": "dist/index.d.ts", | ||
| "apiReport": { | ||
| "enabled": true, | ||
| "reportFileName": "sender.<unscopedPackageName>" | ||
| "reportFileName": "openapi-typed-request-sender.api.md" | ||
| } | ||
| } |
This file contains hidden or 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,4 @@ | ||
| import baseConfig from '@map-colonies/eslint-config/ts-base'; | ||
| import { defineConfig } from 'eslint/config'; | ||
|
|
||
| export default defineConfig(baseConfig, { ignores: ['vitest.config.ts'] }); |
This file contains hidden or 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,59 @@ | ||
| { | ||
| "name": "@map-colonies/openapi-typed-request-sender", | ||
| "version": "0.1.0", | ||
| "description": "Supertest-based testing utilities for OpenAPI-defined APIs", | ||
| "type": "commonjs", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./dist/index.d.ts", | ||
| "default": "./dist/index.js" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "test": "vitest run", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint --fix .", | ||
| "prebuild": "pnpm run clean", | ||
| "build": "tsc --project tsconfig.build.json", | ||
| "clean": "rimraf dist", | ||
| "prepack": "turbo run build", | ||
| "check-dist": "publint && attw --profile node16 --pack .", | ||
| "api:check": "api-extractor run --verbose --config ./api-extractor.json", | ||
| "api": "api-extractor run --local --verbose --config ./api-extractor.json" | ||
| }, | ||
| "repository": "github:MapColonies/infra-packages", | ||
| "files": [ | ||
| "dist/**/*" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "engines": { | ||
| "node": ">=24" | ||
| }, | ||
| "dependencies": { | ||
| "oas-normalize": "^15.0.0", | ||
| "ts-essentials": "^10.1.1" | ||
| }, | ||
| "peerDependencies": { | ||
| "@types/express": "^4.17.21", | ||
| "openapi-typescript": "^7.4.1", | ||
| "supertest": "^7.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@map-colonies/eslint-config": "workspace:^", | ||
| "@map-colonies/tsconfig": "workspace:^", | ||
| "@types/node": "catalog:", | ||
| "@types/supertest": "catalog:", | ||
| "body-parser": "2.2.2", | ||
| "@types/body-parser": "1.19.6", | ||
| "express": "5.2.1", | ||
| "eslint": "catalog:", | ||
| "rimraf": "catalog:", | ||
| "typescript": "catalog:", | ||
| "vitest-config": "workspace:^", | ||
| "vitest": "catalog:", | ||
| "@microsoft/api-extractor": "catalog:", | ||
| "openapi-types": "12.1.3" | ||
| } | ||
| } |
This file contains hidden or 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,31 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
| import type { WritableKeys } from 'ts-essentials'; | ||
|
|
||
| type HasContent<T> = [T] extends [{ content: any }] ? T['content']['application/json'] : never; | ||
|
|
||
| export type AddIfNotNever<T, U> = [U] extends [never] ? T : T & U; | ||
| export type PickWritable<T extends NonNullable<unknown>> = Pick<T, WritableKeys<T>>; | ||
|
|
||
| export type Methods = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head' | 'options' | 'trace'; | ||
|
|
||
| export type OperationsTemplate = Record<string, any>; | ||
|
|
||
| export type PathsTemplate = Record< | ||
| string, | ||
| { | ||
| parameters: { | ||
| query?: any; | ||
| header?: any; | ||
| path?: any; | ||
| cookie?: any; | ||
| }; | ||
| } & { | ||
| [key in Methods]?: OperationsTemplate; | ||
| } | ||
| >; | ||
|
|
||
| export type ResponseObjectToFlat<T> = [T] extends [{ responses: any }] | ||
| ? { | ||
| [res in keyof T['responses']]: { status: res; body: HasContent<T['responses'][res]> }; | ||
| }[keyof T['responses']] | ||
| : never; |
File renamed without changes.
This file contains hidden or 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,3 @@ | ||
| export * from './requestSender.js'; | ||
| export * from './types.js'; | ||
| export * from './expect.js'; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
update the example