-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: display request headers * chore: add changeset
- Loading branch information
Showing
14 changed files
with
243 additions
and
12 deletions.
There are no files selected for viewing
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,6 @@ | ||
--- | ||
'@commercetools-docs/gatsby-transformer-raml': patch | ||
'@commercetools-docs/gatsby-theme-api-docs': patch | ||
--- | ||
|
||
Request headers are now being displayed in the endpoints. |
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
131 changes: 131 additions & 0 deletions
131
packages/gatsby-theme-api-docs/src/components/resource/method/headers.js
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,131 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from '@emotion/styled'; | ||
import { | ||
Markdown, | ||
designSystem as uiKitDesignSystem, | ||
} from '@commercetools-docs/ui-kit'; | ||
import SpacingsStack from '@commercetools-uikit/spacings-stack'; | ||
import SpacingsInline from '@commercetools-uikit/spacings-inline'; | ||
import useTypesToRender from '../../../hooks/use-type-to-render'; | ||
import Required from '../../required'; | ||
import Table from '../../table'; | ||
import Title from './title'; | ||
import { DescriptionText } from '../../description'; | ||
import Info from '../../info'; | ||
import { typography } from '../../../design-system'; | ||
|
||
// inline-blocks inside a block are wrapped first before wrapping inline. | ||
// this implements a wrapping behavior where property name and type are separated | ||
// into lines before the name is wrapped in itself if it consists of multiple words. | ||
const HeaderName = styled.div` | ||
display: inline-block; | ||
margin-right: ${uiKitDesignSystem.dimensions.spacings.s}; | ||
white-space: nowrap; | ||
line-height: ${typography.lineHeights.propertyType}; | ||
`; | ||
const HeaderType = styled.div` | ||
display: inline-block; | ||
line-height: ${typography.lineHeights.propertyType}; | ||
color: ${uiKitDesignSystem.colors.light.textFaded}; | ||
`; | ||
|
||
const Pattern = styled.code` | ||
color: ${uiKitDesignSystem.colors.light.textHighlight}; | ||
letter-spacing: 0.03em; | ||
`; | ||
|
||
const Headers = (props) => { | ||
return ( | ||
<SpacingsStack scale="xs"> | ||
{props.title && <Title>{props.title}:</Title>} | ||
<Table> | ||
<tbody> | ||
{props.headers.map((header) => { | ||
return ( | ||
<HeaderRow | ||
key={header.name} | ||
apiKey={props.apiKey} | ||
header={header} | ||
/> | ||
); | ||
})} | ||
</tbody> | ||
</Table> | ||
</SpacingsStack> | ||
); | ||
}; | ||
Headers.propTypes = { | ||
apiKey: PropTypes.string, | ||
title: PropTypes.string, | ||
headers: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
displayName: PropTypes.string.isRequired, | ||
header: PropTypes.string.isRequired, | ||
type: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
required: PropTypes.bool, | ||
pattern: PropTypes.string, | ||
enum: PropTypes.string, | ||
}).isRequired | ||
).isRequired, | ||
}; | ||
Headers.displayName = 'Headers'; | ||
|
||
function HeaderRow(props) { | ||
const typesToRender = useTypesToRender({ | ||
property: props.header, | ||
apiKey: props.apiKey, | ||
isParameter: false, | ||
}); | ||
const typeToRender = typesToRender[0]; // safe as we expect a single item in the array | ||
|
||
return ( | ||
<tr key={props.header.displayName}> | ||
<td> | ||
<HeaderName> | ||
<SpacingsInline scale="xs"> | ||
<Markdown.InlineCode>{props.header.header}</Markdown.InlineCode> | ||
{props.header.required && <Required />} | ||
</SpacingsInline> | ||
</HeaderName> | ||
{'\u200B' /* zero-width space for the search crawler */} | ||
<HeaderType> | ||
{typeToRender.displayPrefix && typeToRender.displayPrefix} | ||
|
||
{typeToRender.type} | ||
</HeaderType> | ||
{'\u200B' /* zero-width space for the search crawler */} | ||
</td> | ||
<td> | ||
<SpacingsStack scale="xs"> | ||
{props.header.description && ( | ||
<DescriptionText markdownString={props.header.description} /> | ||
)} | ||
{props.header.pattern && ( | ||
<div> | ||
<Info> | ||
Pattern: <Pattern>{props.header.pattern}</Pattern> | ||
</Info> | ||
</div> | ||
)} | ||
</SpacingsStack> | ||
</td> | ||
</tr> | ||
); | ||
} | ||
HeaderRow.propTypes = { | ||
apiKey: PropTypes.string, | ||
header: PropTypes.shape({ | ||
displayName: PropTypes.string.isRequired, | ||
header: PropTypes.string.isRequired, | ||
type: PropTypes.string.isRequired, | ||
description: PropTypes.string, | ||
required: PropTypes.bool, | ||
pattern: PropTypes.string, | ||
enum: PropTypes.string, | ||
}).isRequired, | ||
}; | ||
HeaderRow.displayName = 'HeaderRow'; | ||
|
||
export default Headers; |
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
11 changes: 11 additions & 0 deletions
11
packages/gatsby-transformer-raml/src/utils/resource/headers-to-array.mjs
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,11 @@ | ||
function headersToArray(headers) { | ||
if (headers) { | ||
return Object.entries(headers).map(([key, value]) => { | ||
return { header: key, ...value }; | ||
}); | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export default headersToArray; |
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
Oops, something went wrong.