Skip to content

Commit

Permalink
Display regex array type descriptions correctly (#1959)
Browse files Browse the repository at this point in the history
* chore: display regex array types correctly

* chore: add changeset

---------

Co-authored-by: Gabriele Antonini <106664971+gabriele-ct@users.noreply.github.com>
  • Loading branch information
timonrey and gabriele-ct authored Mar 26, 2024
1 parent 6fad386 commit 0c5a24c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
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

0 comments on commit 0c5a24c

Please sign in to comment.