Skip to content
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

Display regex array type descriptions correctly #1959

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-countries-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-docs/gatsby-theme-api-docs': patch
---

Display regex types that are declared as an array type correctly.
1 change: 1 addition & 0 deletions api-specs/test/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ uses:
references: types/references.raml
regex-properties-type-string: types/regex-properties-type-string.raml
regex-properties-type-object: types/regex-properties-type-object.raml
regex-properties-type-array: types/regex-properties-type-array.raml
scalars: types/scalars.raml
soft-links: types/soft-links.raml
unions: types/unions.raml
Expand Down
15 changes: 15 additions & 0 deletions api-specs/test/types/regex-properties-type-array.raml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#%RAML 1.0 Library
usage: Regex properties test types.

uses:
objects: objects.raml

types:
RegexPropertiesTypeArray:
description: This is a type that can have arbitrary properties as long as they match a certain expression
type: object
properties:
/^[a-z]{2}(-[A-Z]{2})?$/:
description: Regular expression property with an array type. To be displayed as "Array of ObjectTestType". The Slashes should appear in blue.
type: array
items: objects.ObjectTestType
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const NameType = (props) => {
<PropertyType>
{typeToRender.displayPrefix && typeToRender.displayPrefix}

{isRegex(props.property.name)
{isRegex(props.property.name) && !typeToRender.displayPrefix
? `Any ${typeof typeToRender.type} property matching this regular expression`
: typeof typeToRender.type === 'string'
? typeToRender.type
Expand Down
3 changes: 3 additions & 0 deletions websites/api-docs-smoke-test/src/content/types/general.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: General
description: Types that are not similar.
---

import { ApiType } from "/shortcodes"

# AnyTestType
Expand Down Expand Up @@ -34,6 +35,8 @@ import { ApiType } from "/shortcodes"

<ApiType apiKey="test" type="RegexPropertiesTypeObject" />

<ApiType apiKey="test" type="RegexPropertiesTypeArray" />

# AnnotationsTestType

<ApiType apiKey="test" type="AnnotationsTestType" />
Expand Down
Loading