From a4b9bd2c77ebcf87c2250b5f3153604924d55e93 Mon Sep 17 00:00:00 2001 From: Kyle Johnston Date: Fri, 10 May 2024 12:53:34 +0100 Subject: [PATCH 1/3] feat: changed auth default, removed auth from being sent with request --- demo/src/components/ElementsAPI.tsx | 2 ++ .../CustomComponents/CodeComponent.spec.ts | 2 +- .../src/components/TryIt/Auth/AuthTokenInput.tsx | 2 +- .../elements-core/src/components/TryIt/TryIt.tsx | 4 +++- .../src/components/TryIt/build-request.ts | 12 ++++++------ 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/demo/src/components/ElementsAPI.tsx b/demo/src/components/ElementsAPI.tsx index 3ed801b65..00066a264 100644 --- a/demo/src/components/ElementsAPI.tsx +++ b/demo/src/components/ElementsAPI.tsx @@ -14,6 +14,8 @@ export const ElementsAPI: React.FC = () => { ? `https://stoplight.io/cors-proxy/${apiDescriptionUrl}` : apiDescriptionUrl; + console.log(specUrlWithProxy); + return ( diff --git a/packages/elements-core/src/components/MarkdownViewer/CustomComponents/CodeComponent.spec.ts b/packages/elements-core/src/components/MarkdownViewer/CustomComponents/CodeComponent.spec.ts index 85e0381a8..77d973578 100644 --- a/packages/elements-core/src/components/MarkdownViewer/CustomComponents/CodeComponent.spec.ts +++ b/packages/elements-core/src/components/MarkdownViewer/CustomComponents/CodeComponent.spec.ts @@ -81,7 +81,7 @@ describe('parseHttpRequest', () => { { name: 'limit', style: HttpParamStyles.Form, schema: { default: '10' }, required: true }, { name: 'skip', style: HttpParamStyles.Form, schema: {}, required: false }, ], - headers: [{ name: 'apikey', style: HttpParamStyles.Simple, schema: { default: '123' }, required: true }], + headers: [{ name: 'apikey', style: HttpParamStyles.Simple, schema: { default: 'YOUR TOKEN' }, required: true }], path: [{ name: 'id', style: HttpParamStyles.Simple, required: true }], body: { contents: [{ mediaType: 'application/json', schema: { default: '{}' } }] }, }, diff --git a/packages/elements-core/src/components/TryIt/Auth/AuthTokenInput.tsx b/packages/elements-core/src/components/TryIt/Auth/AuthTokenInput.tsx index 9219e888e..61f527278 100644 --- a/packages/elements-core/src/components/TryIt/Auth/AuthTokenInput.tsx +++ b/packages/elements-core/src/components/TryIt/Auth/AuthTokenInput.tsx @@ -25,7 +25,7 @@ export const AuthTokenInput: React.FC = ({ type, name, valu aria-label={name} appearance="minimal" flex={1} - placeholder={type === 'oauth2' ? 'Bearer 123' : '123'} + placeholder={type === 'oauth2' ? 'Bearer YOUR TOKEN' : 'YOUR TOKEN'} value={value} type="text" required diff --git a/packages/elements-core/src/components/TryIt/TryIt.tsx b/packages/elements-core/src/components/TryIt/TryIt.tsx index 420ea7084..1e0f0a1a9 100644 --- a/packages/elements-core/src/components/TryIt/TryIt.tsx +++ b/packages/elements-core/src/components/TryIt/TryIt.tsx @@ -198,11 +198,13 @@ export const TryIt: React.FC = ({ mediaTypeContent, bodyInput: formDataState.isFormDataBody ? getValues() : textRequestBody, mockData, - auth: operationAuthValue, chosenServer, credentials: tryItCredentialsPolicy, corsProxy, }); + + console.log(request); + let response: Response | undefined; try { response = await fetch(...request); diff --git a/packages/elements-core/src/components/TryIt/build-request.ts b/packages/elements-core/src/components/TryIt/build-request.ts index 89ec7cb3f..d8c7103f0 100644 --- a/packages/elements-core/src/components/TryIt/build-request.ts +++ b/packages/elements-core/src/components/TryIt/build-request.ts @@ -191,14 +191,14 @@ const runAuthRequestEhancements = ( if (auth.scheme.in === 'query') { newQueryParams.push({ name: auth.scheme.name, - value: auth.authValue || '123', + value: auth.authValue || 'YOUR TOKEN', }); } if (auth.scheme.in === 'header') { newHeaders.push({ name: auth.scheme.name, - value: auth.authValue || '123', + value: auth.authValue || 'YOUR TOKEN', }); } } @@ -206,28 +206,28 @@ const runAuthRequestEhancements = ( if (isOAuth2SecurityScheme(auth.scheme)) { newHeaders.push({ name: 'Authorization', - value: auth.authValue || 'Bearer 123', + value: auth.authValue || 'Bearer YOUR TOKEN', }); } if (isBearerSecurityScheme(auth.scheme)) { newHeaders.push({ name: 'Authorization', - value: `Bearer ${auth.authValue || '123'}`, + value: `Bearer ${auth.authValue || 'YOUR TOKEN'}`, }); } if (isDigestSecurityScheme(auth.scheme)) { newHeaders.push({ name: 'Authorization', - value: auth.authValue?.replace(/\s\s+/g, ' ').trim() || '123', + value: auth.authValue?.replace(/\s\s+/g, ' ').trim() || 'YOUR TOKEN', }); } if (isBasicSecurityScheme(auth.scheme)) { newHeaders.push({ name: 'Authorization', - value: `Basic ${auth.authValue || '123'}`, + value: `Basic ${auth.authValue || 'YOUR TOKEN'}`, }); } }); From e9777bcef8e21e065a74f5c6d00935653ab4195a Mon Sep 17 00:00:00 2001 From: Kyle Johnston Date: Fri, 10 May 2024 13:00:02 +0100 Subject: [PATCH 2/3] feat: removed console log --- demo/src/components/ElementsAPI.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/demo/src/components/ElementsAPI.tsx b/demo/src/components/ElementsAPI.tsx index 00066a264..3ed801b65 100644 --- a/demo/src/components/ElementsAPI.tsx +++ b/demo/src/components/ElementsAPI.tsx @@ -14,8 +14,6 @@ export const ElementsAPI: React.FC = () => { ? `https://stoplight.io/cors-proxy/${apiDescriptionUrl}` : apiDescriptionUrl; - console.log(specUrlWithProxy); - return ( From 1bc5e923e6730ba71380bb7f015281a456bfcd03 Mon Sep 17 00:00:00 2001 From: Kyle Johnston Date: Fri, 10 May 2024 13:02:41 +0100 Subject: [PATCH 3/3] feat: remove console log --- packages/elements-core/src/components/TryIt/TryIt.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/elements-core/src/components/TryIt/TryIt.tsx b/packages/elements-core/src/components/TryIt/TryIt.tsx index 1e0f0a1a9..1123f8509 100644 --- a/packages/elements-core/src/components/TryIt/TryIt.tsx +++ b/packages/elements-core/src/components/TryIt/TryIt.tsx @@ -203,8 +203,6 @@ export const TryIt: React.FC = ({ corsProxy, }); - console.log(request); - let response: Response | undefined; try { response = await fetch(...request);