hotfix: docs build (#198)

* fix: build

* fix: build

* fix: build

* fix: build
This commit is contained in:
Sebastian Rindom
2021-03-10 16:15:06 +01:00
committed by GitHub
parent 82d2c352b2
commit 1e5a1398d8
20 changed files with 12875 additions and 328 deletions

File diff suppressed because one or more lines are too long

View File

@@ -695,49 +695,6 @@ paths:
properties:
discount:
$ref: '#/components/schemas/discount'
/notifications:
get:
operationId: GetNotifications
summary: List Notifications
description: Retrieves a list of Notifications.
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notifications:
type: array
items:
$ref: '#/components/schemas/notification'
'/notifications/{id}/resend':
post:
operationId: PostNotificationsNotificationResend
summary: Resend Notification
description: >-
Resends a previously sent notifications, with the same data but
optionally to a different address
parameters:
- in: path
name: id
required: true
description: The id of the Notification
schema:
type: string
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notification:
$ref: '#/components/schemas/notification'
/gift-cards:
post:
operationId: PostGiftCards
@@ -910,6 +867,49 @@ paths:
properties:
gift_card:
$ref: '#/components/schemas/gift_card'
/notifications:
get:
operationId: GetNotifications
summary: List Notifications
description: Retrieves a list of Notifications.
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notifications:
type: array
items:
$ref: '#/components/schemas/notification'
'/notifications/{id}/resend':
post:
operationId: PostNotificationsNotificationResend
summary: Resend Notification
description: >-
Resends a previously sent notifications, with the same data but
optionally to a different address
parameters:
- in: path
name: id
required: true
description: The id of the Notification
schema:
type: string
tags:
- Notification
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
notification:
$ref: '#/components/schemas/notification'
'/orders/{id}/shipping-methods':
post:
operationId: PostOrdersOrderShippingMethods
@@ -3358,116 +3358,6 @@ paths:
properties:
shipping_option:
$ref: '#/components/schemas/shipping_option'
'/store/currencies/{code}':
post:
operationId: PostStoreCurrenciesCode
summary: Add a Currency Code
description: Adds a Currency Code to the available currencies.
parameters:
- in: path
name: code
required: true
description: The 3 character ISO currency code.
schema:
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
delete:
operationId: DeleteStoreCurrenciesCode
summary: Remvoe a Currency Code
description: Removes a Currency Code from the available currencies.
parameters:
- in: path
name: code
required: true
description: The 3 character ISO currency code.
schema:
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
/store:
get:
operationId: GetStore
summary: Retrieve Store details.
description: Retrieves the Store details
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
post:
operationId: PostStore
summary: Update Store details.
description: Updates the Store details
requestBody:
content:
application/json:
schema:
properties:
name:
description: The name of the Store
type: string
swap_link_template:
description: >-
A template for Swap links - use `{{cart_id}}` to insert the
Swap Cart id
type: string
default_currency_code:
description: The default currency code for the Store.
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
/store/payment-providers:
get:
operationId: GetStorePaymentProviders
summary: Retrieve configured Payment Providers
description: Retrieves the configured Payment Providers
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
payment_providers:
type: array
items:
$ref: '#/components/schemas/store'
/shipping-profiles:
post:
operationId: PostShippingProfiles
@@ -3590,6 +3480,116 @@ paths:
properties:
shipping_profiles:
$ref: '#/components/schemas/shipping_profile'
'/store/currencies/{code}':
post:
operationId: PostStoreCurrenciesCode
summary: Add a Currency Code
description: Adds a Currency Code to the available currencies.
parameters:
- in: path
name: code
required: true
description: The 3 character ISO currency code.
schema:
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
delete:
operationId: DeleteStoreCurrenciesCode
summary: Remvoe a Currency Code
description: Removes a Currency Code from the available currencies.
parameters:
- in: path
name: code
required: true
description: The 3 character ISO currency code.
schema:
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
/store:
get:
operationId: GetStore
summary: Retrieve Store details.
description: Retrieves the Store details
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
post:
operationId: PostStore
summary: Update Store details.
description: Updates the Store details
requestBody:
content:
application/json:
schema:
properties:
name:
description: The name of the Store
type: string
swap_link_template:
description: >-
A template for Swap links - use `{{cart_id}}` to insert the
Swap Cart id
type: string
default_currency_code:
description: The default currency code for the Store.
type: string
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
store:
$ref: '#/components/schemas/store'
/store/payment-providers:
get:
operationId: GetStorePaymentProviders
summary: Retrieve configured Payment Providers
description: Retrieves the configured Payment Providers
tags:
- Store
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
payment_providers:
type: array
items:
$ref: '#/components/schemas/store'
/swaps:
get:
operationId: GetSwaps

File diff suppressed because one or more lines are too long

View File

@@ -1025,6 +1025,56 @@ paths:
properties:
customer:
$ref: '#/components/schemas/customer'
'/products/{id}':
get:
operationId: GetProductsProduct
summary: Retrieves a Product
description: Retrieves a Product.
parameters:
- in: path
name: id
required: true
description: The id of the Product.
schema:
type: string
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
product:
$ref: '#/components/schemas/product'
/products:
get:
operationId: GetProducts
summary: List Products
description: Retrieves a list of Products.
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
count:
description: The total number of Products.
type: integer
offset:
description: The offset for pagination.
type: integer
limit:
description: 'The maxmimum number of Products to return,'
type: integer
products:
type: array
items:
$ref: '#/components/schemas/product'
'/regions/{id}':
get:
operationId: GetRegionsRegion
@@ -1129,56 +1179,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/shipping_option'
'/products/{id}':
get:
operationId: GetProductsProduct
summary: Retrieves a Product
description: Retrieves a Product.
parameters:
- in: path
name: id
required: true
description: The id of the Product.
schema:
type: string
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
product:
$ref: '#/components/schemas/product'
/products:
get:
operationId: GetProducts
summary: List Products
description: Retrieves a list of Products.
tags:
- Product
responses:
'200':
description: OK
content:
application/json:
schema:
properties:
count:
description: The total number of Products.
type: integer
offset:
description: The offset for pagination.
type: integer
limit:
description: 'The maxmimum number of Products to return,'
type: integer
products:
type: array
items:
$ref: '#/components/schemas/product'
'/swaps/{cart_id}':
get:
operationId: GetSwapsSwapCartId

View File

@@ -17,7 +17,7 @@ swaggerInline(
console.error(err);
return;
}
fs.writeFileSync("./docs/api/store-spec3.json", JSON.stringify(genObj));
fs.writeFileSync("./docs/api/store-spec3.json", gen);
}, true);
});
@@ -44,7 +44,7 @@ swaggerInline(
console.error(err);
return;
}
fs.writeFileSync("./docs/api/admin-spec3.json", JSON.stringify(genObj));
fs.writeFileSync("./docs/api/admin-spec3.json", gen);
}, true);
});

View File

@@ -13,7 +13,7 @@ module.exports = {
offset: -300,
},
},
`gatsby-transformer-yaml`,
`gatsby-transformer-json`,
`gatsby-plugin-emotion`,
{
resolve: `gatsby-source-filesystem`,

View File

@@ -23,6 +23,7 @@
"gatsby-plugin-emotion": "^5.0.0",
"gatsby-plugin-react-helmet": "^3.3.12",
"gatsby-source-filesystem": "^2.3.31",
"gatsby-transformer-json": "^3.0.0",
"gatsby-transformer-yaml": "^2.4.13",
"react": "^16.12.0",
"react-collapsible": "^2.8.1",

View File

@@ -1,5 +1,5 @@
import React from "react"
import { Flex, Box, Text } from "rebass"
import { Flex, Text } from "rebass"
import styled from "@emotion/styled"
import Markdown from "react-markdown"
@@ -68,10 +68,14 @@ const DocsReader = ({ tags, spec }) => {
path={endpoint.path}
/>
<Markdown>{endpoint.description}</Markdown>
<Parameters endpoint={endpoint} />
<Parameters spec={spec} endpoint={endpoint} />
</Flex>
<Flex py={5} width="45%" flex="1">
<JsonBox name={tagName} endpoint={endpoint} />
<JsonBox
name={tagName}
endpoint={endpoint}
spec={spec}
/>
</Flex>
</Flex>
))}

View File

@@ -49,7 +49,7 @@ const EndpointOverview = ({ title, description, routes, spec }) => {
>
<Text my={2}>Attributes</Text>
{attrs.map(p => (
<ParamSection param={p} />
<ParamSection param={p} spec={spec} />
))}
</Box>
)}

View File

@@ -1,15 +1,14 @@
import React, { useState, useEffect } from "react"
import { graphql } from "gatsby"
import { Flex, Box, Text, Image } from "rebass"
import React from "react"
import { Flex, Box, Text } from "rebass"
import styled from "@emotion/styled"
import { AnchorLink } from "gatsby-plugin-anchor-links"
import Markdown from "react-markdown"
import Highlight from "react-highlight.js"
import "highlight.js/styles/a11y-light.css"
import fixtures from "../../../docs/api/fixtures.json"
import { deref } from "../utils/deref"
export const ResponseContainer = styled(Flex)`
border: 1px solid #e3e8ee;
border-radius: 5px;
@@ -28,10 +27,9 @@ export const ResponseContainer = styled(Flex)`
}
`
const JsonBox = ({ text, resourceId, endpoint }) => {
const [json, setJson] = useState({})
const JsonBox = ({ text, resourceId, endpoint, spec }) => {
let json = {}
useEffect(() => {
const toSet = {}
if (endpoint) {
const props =
@@ -40,24 +38,29 @@ const JsonBox = ({ text, resourceId, endpoint }) => {
if (props) {
for (const [name, details] of Object.entries(props)) {
let cleanDets = details
if (details.$ref) {
const [, ...path] = details.$ref.split("/")
cleanDets = deref(path, spec)
}
if (
details["x-resourceId"] &&
details["x-resourceId"] in fixtures.resources
cleanDets["x-resourceId"] &&
cleanDets["x-resourceId"] in fixtures.resources
) {
toSet[name] = fixtures.resources[details["x-resourceId"]]
toSet[name] = fixtures.resources[cleanDets["x-resourceId"]]
} else {
toSet[name] = details
toSet[name] = cleanDets
}
}
}
}
if (resourceId) {
setJson(fixtures.resources[resourceId])
json = fixtures.resources[resourceId]
} else {
setJson(toSet)
json = toSet
}
}, [])
return (
<ResponseContainer flexDirection="column" as="pre">

View File

@@ -4,6 +4,8 @@ import { Flex, Box, Text } from "rebass"
import Markdown from "react-markdown"
import Collapsible from "react-collapsible"
import { deref } from "../utils/deref"
const ExpandContainer = styled.div`
.child-attrs {
cursor: pointer;
@@ -28,15 +30,27 @@ const ExpandContainer = styled.div`
}
`
const Expand = ({ schema }) => {
const Expand = ({ schema, spec }) => {
if (schema.$ref) {
const [, ...path] = schema.$ref.split("/")
schema = deref(path, spec)
}
const properties = schema.properties
let aggregated = []
for (const [name, details] of Object.entries(properties)) {
let cleanDets = details
if (name === "$ref") {
const [, ...path] = details.split("/")
cleanDets = deref(path, spec)
}
if (!aggregated.find(a => a.name === name)) {
aggregated.push({
name,
...details,
...cleanDets,
})
}
}
@@ -104,7 +118,7 @@ const Expand = ({ schema }) => {
)
}
const ParamSection = ({ routeParam, param }) => {
const ParamSection = ({ routeParam, param, spec }) => {
let type = param.type
if (!type && param.schema) {
type = param.schema.type
@@ -133,10 +147,12 @@ const ParamSection = ({ routeParam, param }) => {
<Text fontSize={0}>
<Markdown>{param.description}</Markdown>
</Text>
{param.anyOf && param.anyOf.map(schema => <Expand schema={schema} />)}
{param.oneOf && param.oneOf.map(schema => <Expand schema={schema} />)}
{param.anyOf &&
param.anyOf.map(schema => <Expand schema={schema} spec={spec} />)}
{param.oneOf &&
param.oneOf.map(schema => <Expand schema={schema} spec={spec} />)}
{param.type === "array" && param.items?.properties && (
<Expand schema={param.items} />
<Expand schema={param.items} spec={spec} />
)}
</Box>
)

View File

@@ -1,19 +1,27 @@
import React from "react"
import { Flex, Box, Text } from "rebass"
import { Box, Text } from "rebass"
import ParamSection from "./param-section"
const Parameters = ({ endpoint }) => {
import { deref } from "../utils/deref"
const Parameters = ({ endpoint, spec }) => {
const aggregated = endpoint.parameters || []
const reqBody = endpoint.requestBody || {}
const props = reqBody.content?.["application/json"]?.schema?.properties
if (props) {
for (const [name, details] of Object.entries(props)) {
let cleanDets = details
if (name === "$ref") {
const [, ...path] = details.split("/")
cleanDets = deref(path, spec)
}
if (!aggregated.find(a => a.name === name)) {
aggregated.push({
name,
...details,
...cleanDets,
})
}
}
@@ -32,7 +40,7 @@ const Parameters = ({ endpoint }) => {
>
<Text my={2}>Parameters</Text>
{aggregated.map(p => (
<ParamSection param={p} />
<ParamSection param={p} spec={spec} />
))}
</Box>
)

View File

@@ -2,7 +2,7 @@ import React from "react"
import { Flex, Box, Text } from "rebass"
const RouteSection = ({ basePath, path, method }) => {
path = path.replaceAll(/{(.*?)}/g, ":$1")
path = path.replace(/{(.*?)}/g, ":$1")
return (
<Box py={2}>

View File

@@ -1,6 +1,6 @@
import React, { useState, useEffect } from "react"
import React from "react"
import styled from "@emotion/styled"
import { Flex, Box, Text, Image } from "rebass"
import { Flex, Box, Text } from "rebass"
const StyledRoutesOverview = styled(Flex)`
border: 1px solid #e3e8ee;
@@ -51,7 +51,7 @@ const RoutesOverview = ({ content }) => {
{route.method}
</Text>
<Text color="#4f566b">
{route.path?.replaceAll(/{(.*?)}/g, ":$1")}
{route.path?.replace(/{(.*?)}/g, ":$1")}
</Text>
</Flex>
))}

View File

@@ -1,5 +1,5 @@
import React, { useState, useEffect } from "react"
import { Link, navigate } from "gatsby"
import { navigate } from "gatsby"
import { Flex, Box, Text } from "rebass"
import { AnchorLink } from "gatsby-plugin-anchor-links"
import styled from "@emotion/styled"
@@ -63,11 +63,6 @@ const SideBarContainer = styled(Flex)`
flex-direction: column;
`
const StyledLink = styled(Link)`
color: #212121;
font-decoration: none;
`
const SideBar = ({ tags }) => {
const [api, setApi] = useState("store")
@@ -89,7 +84,6 @@ const SideBar = ({ tags }) => {
px={4}
py={3}
mb={3}
justifyContent="center"
flexDirection="column"
>
<Flex width={"100%"} alignContent="center">

View File

@@ -1,21 +1,14 @@
import React, { useState, useEffect } from "react"
const useSpec = raw => {
const [tags, setTags] = useState({})
const [spec, setSpec] = useState({})
useEffect(() => {
setSpec(raw)
let tags = {}
for (const [path, methods] of Object.entries(raw.paths)) {
for (const [method, specification] of Object.entries(methods)) {
for (const t of specification.tags) {
setTags(ts => {
if (t in ts) {
return {
...ts,
if (t in tags) {
tags = {
...tags,
[t]: [
...ts[t],
...tags[t],
{
method: method.toUpperCase(),
path,
@@ -24,8 +17,8 @@ const useSpec = raw => {
],
}
} else {
return {
...ts,
tags = {
...tags,
[t]: [
{
method: method.toUpperCase(),
@@ -35,13 +28,11 @@ const useSpec = raw => {
],
}
}
})
}
}
}
}, [])
return { tags, spec }
return { tags, spec: raw }
}
export default useSpec

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from "react"
import React from "react"
import { Flex } from "rebass"
import { Helmet } from "react-helmet"

View File

@@ -1,38 +1,17 @@
import React, { useState, useEffect } from "react"
import React from "react"
import { Flex } from "rebass"
import { Helmet } from "react-helmet"
import adminSpec from "../../../docs/api/admin-spec3.json"
import spec from "../../../docs/api/admin-spec3.json"
import rawSpec from "../../../docs/api/admin-spec3.json"
import Layout from "../components/layout"
import SideBar from "../components/sidebar"
import DocsReader from "../components/docs-reader"
export default function Home() {
const tags = {}
import useSpec from "../hooks/use-spec"
for (const [path, methods] of Object.entries(spec.paths)) {
for (const [method, specification] of Object.entries(methods)) {
for (const t of specification.tags) {
if (t in tags) {
tags[t].push({
method: method.toUpperCase(),
path,
...specification,
})
} else {
tags[t] = [
{
method: method.toUpperCase(),
path,
...specification,
},
]
}
}
}
}
export default function Home() {
const { tags, spec } = useSpec(rawSpec)
return (
<Layout>
@@ -41,7 +20,7 @@ export default function Home() {
</Helmet>
<Flex>
<SideBar tags={tags} />
<DocsReader tags={tags} />
<DocsReader tags={tags} spec={spec} />
</Flex>
</Layout>
)

9
www/src/utils/deref.js Normal file
View File

@@ -0,0 +1,9 @@
export const deref = (path, spec) => {
let cleanDets = spec
for (const part of path) {
if (part === "#") continue
cleanDets = cleanDets[part]
}
return cleanDets
}

View File

@@ -1002,6 +1002,13 @@
dependencies:
regenerator-runtime "^0.13.4"
"@babel/runtime@^7.12.5":
version "7.13.10"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d"
integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==
dependencies:
regenerator-runtime "^0.13.4"
"@babel/standalone@^7.11.6":
version "7.11.6"
resolved "https://registry.yarnpkg.com/@babel/standalone/-/standalone-7.11.6.tgz#2ea3c9463c8b1d04ee2dacc5ac4b81674cec2967"
@@ -5961,6 +5968,14 @@ gatsby-telemetry@^1.3.36:
node-fetch "^2.6.0"
uuid "3.4.0"
gatsby-transformer-json@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/gatsby-transformer-json/-/gatsby-transformer-json-3.0.0.tgz#e8ab61ac5aa9aa7699c00d869c63b91ce37d606e"
integrity sha512-MyQZdoGbr1OEtFkAF1BAEvfhZKZVeD00yCX/9E/CSd/73jrBqxXqSWN2gIVx9HlPRbPUjmChMW6Nwx0z6GF+MA==
dependencies:
"@babel/runtime" "^7.12.5"
bluebird "^3.7.2"
gatsby-transformer-yaml@^2.4.13:
version "2.4.13"
resolved "https://registry.yarnpkg.com/gatsby-transformer-yaml/-/gatsby-transformer-yaml-2.4.13.tgz#791e8bed84b91161af5ac2b1368855fd68830158"