-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat: allow duplicate http names by method #7949
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import path from './path'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { sanitizeName } from './regex'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const getHttpRequestFilenameBase = (requestName, method = 'GET') => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const sanitizedRequestName = sanitizeName(requestName || '') || 'request'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| const normalizedMethod = String(method || 'GET').trim().toUpperCase() || 'GET'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| return sanitizeName(`${normalizedMethod} ${sanitizedRequestName}`); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const getRequestFilenameBase = ({ requestName, requestMethod, requestType }) => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| if (requestType === 'http-request') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return getHttpRequestFilenameBase(requestName, requestMethod); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return sanitizeName(requestName || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export const normalizeRequestFilename = (filename, format = 'bru') => { | ||||||||||||||||||||||||||||||||||||||||||||||||
| const targetExtension = format === 'yml' ? 'yml' : 'bru'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| const extension = path.extname(filename || '').toLowerCase(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| const baseName = ['.bru', '.yml', '.yaml'].includes(extension) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ? path.basename(filename, extension) | ||||||||||||||||||||||||||||||||||||||||||||||||
| : filename; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle extension stripping with original-case suffix, not the lowercased variant.
Proposed fix export const normalizeRequestFilename = (filename, format = 'bru') => {
const targetExtension = format === 'yml' ? 'yml' : 'bru';
- const extension = path.extname(filename || '').toLowerCase();
- const baseName = ['.bru', '.yml', '.yaml'].includes(extension)
- ? path.basename(filename, extension)
- : filename;
+ const originalExtension = path.extname(filename || '');
+ const extension = originalExtension.toLowerCase();
+ const baseName = ['.bru', '.yml', '.yaml'].includes(extension)
+ ? path.basename(filename, originalExtension)
+ : filename;
return `${sanitizeName(baseName || 'request')}.${targetExtension}`;
};📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return `${sanitizeName(baseName || 'request')}.${targetExtension}`; | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { getHttpRequestFilenameBase, normalizeRequestFilename } from './requestFilename'; | ||
|
|
||
| describe('request filename helpers', () => { | ||
| it('generates method-aware HTTP request filenames from display names', () => { | ||
| expect(getHttpRequestFilenameBase('/projects', 'GET')).toBe('GET projects'); | ||
| expect(getHttpRequestFilenameBase('/projects', 'POST')).toBe('POST projects'); | ||
| expect(getHttpRequestFilenameBase('/projects/{id}', 'PUT')).toBe('PUT projects-{id}'); | ||
| }); | ||
|
|
||
| it('normalizes request filename extensions for collection format', () => { | ||
| expect(normalizeRequestFilename('GET projects.bru', 'yml')).toBe('GET projects.yml'); | ||
| expect(normalizeRequestFilename('POST projects', 'bru')).toBe('POST projects.bru'); | ||
| }); | ||
| }); |
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.
Resync auto filename when cURL type is toggled from the dropdown.
curlRequestTypeChangeupdates onlycurlRequestTypeDetected; when filename is still auto-managed, it can stay stale after switching HTTP ↔ GraphQL.Proposed fix
const curlRequestTypeChange = (type) => { setCurlRequestTypeDetected(type); + if (!isFilenameManuallyEdited) { + formik.setFieldValue('filename', getRequestFilenameBase({ + requestName: formik.values.requestName, + requestMethod: formik.values.requestMethod, + requestType: type + })); + } };Also applies to: 603-615
🤖 Prompt for AI Agents