Skip to content

Commit

Permalink
feat: show additional properties are (not) allowed (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmvilas authored Aug 10, 2020
1 parent ab24ff8 commit 9d3e6d8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions library/src/containers/Schemas/Schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export const SchemaComponent: React.FunctionComponent<Props> = ({
>
{renderSchemaProps(name, schema)}
</Table>
<div className={bemClasses.element('additional-properties-notice')}>
Additional properties are{' '}
{schema.additionalProperties === false && 'NOT'} allowed.
</div>
</div>
{/* we need to disable this component if schema has "not" field anywhere in it */}
{hasNotField ? null : (
Expand Down
13 changes: 6 additions & 7 deletions library/src/helpers/beautifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Channels,
Parameters,
Operation,
AdditionalProperties,
} from '../types';

import { renderMd } from './renderMarkdown';
Expand Down Expand Up @@ -104,18 +105,16 @@ class Beautifier {

if (schema.additionalProperties) {
const additionalProperties = schema.additionalProperties;
const newAdditionalProperties: Record<
string,
Schema
> = additionalProperties;
const newAdditionalProperties: AdditionalProperties = additionalProperties;

for (const [key, prop] of Object.entries(additionalProperties)) {
if (prop.description) {
prop.description = renderMd(prop.description as string);
}
if (prop.additionalProperties) {
const propAdditionalProperties = prop.additionalProperties;
const newPropAdditionalProperties: Record<string, Schema> = {};
if (typeof prop.additionalProperties !== 'boolean') {
const propAdditionalProperties: AdditionalProperties =
prop.additionalProperties;
const newPropAdditionalProperties: AdditionalProperties = {};

for (const [propKey, propValue] of Object.entries(
propAdditionalProperties,
Expand Down
11 changes: 11 additions & 0 deletions library/src/styles/fiori.css
Original file line number Diff line number Diff line change
Expand Up @@ -1265,3 +1265,14 @@
padding: 0 0.5rem;
color: #fff;
}

.asyncapi__additional-properties-notice {
text-align: center;
font-style: italic;
font-weight: bold;
color: #333333;
font-size: 0.75rem;
line-height: 2;
margin-right: 0.5rem;
margin-top: 0.5rem;
}
4 changes: 3 additions & 1 deletion library/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export interface XML {
wrapped?: boolean;
}

export type AdditionalProperties = boolean | Record<string, Schema>;

export interface Schema {
nullable?: boolean;
format?: string;
Expand Down Expand Up @@ -346,7 +348,7 @@ export interface Schema {
not?: Schema;
properties?: Record<string, Schema>;

additionalProperties?: Record<string, Schema>;
additionalProperties?: AdditionalProperties;

// old field

Expand Down

0 comments on commit 9d3e6d8

Please sign in to comment.