Skip to content

Commit

Permalink
feat: Read only fields are excluded from Webhook docs (PROVCON-2826)
Browse files Browse the repository at this point in the history
  • Loading branch information
Relionnn committed Sep 27, 2024
1 parent 213f05e commit d0cbb98
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/elements-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-core",
"version": "8.4.3",
"version": "8.4.4",
"sideEffects": [
"web-components.min.js",
"src/web-components/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SectionSubtitle } from '../Sections';
export interface BodyProps {
body: IHttpOperationRequestBody;
onChange?: (requestBodyIndex: number) => void;
isHttpWebhookOperation?: boolean;
}

export const isBodyEmpty = (body?: BodyProps['body']) => {
Expand All @@ -23,7 +24,7 @@ export const isBodyEmpty = (body?: BodyProps['body']) => {
return contents.length === 0 && !description?.trim();
};

export const Body = ({ body, onChange }: BodyProps) => {
export const Body = ({ body, onChange, isHttpWebhookOperation = false }: BodyProps) => {
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
const [chosenContent, setChosenContent] = React.useState(0);
const { nodeHasChanged, renderExtensionAddon } = useOptionsCtx();
Expand Down Expand Up @@ -61,13 +62,12 @@ export const Body = ({ body, onChange }: BodyProps) => {
<NodeAnnotation change={descriptionChanged} />
</Box>
)}

{isJSONSchema(schema) && (
<JsonSchemaViewer
resolveRef={refResolver}
maxRefDepth={maxRefDepth}
schema={getOriginalObject(schema)}
viewMode="write"
viewMode={isHttpWebhookOperation ? 'standalone' : 'write'}
renderRootTreeLines
nodeHasChanged={nodeHasChanged}
renderExtensionAddon={renderExtensionAddon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,13 @@ const HttpOperationComponent = React.memo<HttpOperationProps>(
<NodeAnnotation change={descriptionChanged} />
</Box>
)}

<NodeVendorExtensions data={data} />

<Request
onChange={setTextRequestBodyIndex}
operation={data}
hideSecurityInfo={layoutOptions?.hideSecurityInfo}
isHttpWebhookOperation={isHttpWebhookOperation(data)}
/>

{data.responses && (
<Responses
responses={data.responses}
Expand All @@ -112,9 +110,7 @@ const HttpOperationComponent = React.memo<HttpOperationProps>(
isCompact={isCompact}
/>
)}

{data.callbacks?.length ? <Callbacks callbacks={data.callbacks} isCompact={isCompact} /> : null}

{isCompact && tryItPanel}
</VStack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface IRequestProps {
operation: IHttpEndpointOperation;
hideSecurityInfo?: boolean;
onChange?: (requestBodyIndex: number) => void;
isHttpWebhookOperation?: boolean;
}

export const Request: React.FunctionComponent<IRequestProps> = ({
Expand All @@ -33,6 +34,7 @@ export const Request: React.FunctionComponent<IRequestProps> = ({
},
hideSecurityInfo,
onChange,
isHttpWebhookOperation = false,
}) => {
if (!request || typeof request !== 'object') return null;

Expand Down Expand Up @@ -82,7 +84,7 @@ export const Request: React.FunctionComponent<IRequestProps> = ({
</VStack>
)}

{body && <Body onChange={onChange} body={body} />}
{body && <Body onChange={onChange} body={body} isHttpWebhookOperation={isHttpWebhookOperation} />}
</VStack>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import { useGenerateExampleFromMediaTypeContent } from '../../../utils/exampleGe

export const useTextRequestBodyState = (
mediaTypeContent: IMediaTypeContent | undefined,
skipReadOnly: boolean,
): [string, React.Dispatch<React.SetStateAction<string>>] => {
const initialRequestBody = useGenerateExampleFromMediaTypeContent(mediaTypeContent, undefined, {
skipReadOnly: true,
skipReadOnly,
});

const [textRequestBody, setTextRequestBody] = React.useState<string>(initialRequestBody);
Expand Down
5 changes: 4 additions & 1 deletion packages/elements-core/src/components/TryIt/TryIt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ export const TryIt: React.FC<TryItProps> = ({
const [bodyParameterValues, setBodyParameterValues, isAllowedEmptyValues, setAllowedEmptyValues, formDataState] =
useBodyParameterState(mediaTypeContent);

const [textRequestBody, setTextRequestBody] = useTextRequestBodyState(mediaTypeContent);
const [textRequestBody, setTextRequestBody] = useTextRequestBodyState(
mediaTypeContent,
!isHttpWebhookOperation(httpOperation),
);

const [operationAuthValue, setOperationAuthValue, setCurrentScheme] = usePersistedSecuritySchemeWithValues();

Expand Down
4 changes: 2 additions & 2 deletions packages/elements-dev-portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-dev-portal",
"version": "2.4.4",
"version": "2.4.5",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -66,7 +66,7 @@
"dependencies": {
"@stoplight/markdown-viewer": "^5.7.1",
"@stoplight/mosaic": "^1.53.4",
"@stoplight/elements-core": "^8.4.3",
"@stoplight/elements-core": "^8.4.4",
"@stoplight/path": "^1.3.2",
"@stoplight/types": "^14.0.0",
"classnames": "^2.2.6",
Expand Down
4 changes: 2 additions & 2 deletions packages/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements",
"version": "8.4.3",
"version": "8.4.4",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -63,7 +63,7 @@
]
},
"dependencies": {
"@stoplight/elements-core": "^8.4.3",
"@stoplight/elements-core": "^8.4.4",
"@stoplight/http-spec": "^7.1.0",
"@stoplight/json": "^3.18.1",
"@stoplight/mosaic": "^1.53.4",
Expand Down

0 comments on commit d0cbb98

Please sign in to comment.