Revert "Add support for json schema to API docs"
Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
import React from 'react';
|
||||
import { AsyncApiDefinitionWidget } from '../AsyncApiDefinitionWidget';
|
||||
import { GraphQlDefinitionWidget } from '../GraphQlDefinitionWidget';
|
||||
import { JsonSchemaDefinitionWidget } from '../JsonSchemaDefinitionWidget';
|
||||
import { OpenApiDefinitionWidget } from '../OpenApiDefinitionWidget';
|
||||
|
||||
export type ApiDefinitionWidget = {
|
||||
@@ -52,13 +51,5 @@ export function defaultDefinitionWidgets(): ApiDefinitionWidget[] {
|
||||
<GraphQlDefinitionWidget definition={definition} />
|
||||
),
|
||||
},
|
||||
{
|
||||
type: 'jsonschema',
|
||||
title: 'JSON Schema',
|
||||
rawLanguage: 'json',
|
||||
component: definition => (
|
||||
<JsonSchemaDefinitionWidget definition={definition} />
|
||||
),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { renderInTestApp } from '@backstage/test-utils';
|
||||
import React from 'react';
|
||||
import { JsonSchemaDefinitionWidget } from './JsonSchemaDefinitionWidget';
|
||||
|
||||
describe('<JsonSchemaDefinitionWidget />', () => {
|
||||
it('renders json schema', async () => {
|
||||
// From https://json-schema.org/learn/miscellaneous-examples.html
|
||||
const definition = `
|
||||
{
|
||||
"$id": "https://example.com/person.schema.json",
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"title": "Person",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"firstName": {
|
||||
"type": "string",
|
||||
"description": "The person's first name."
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string",
|
||||
"description": "The person's last name."
|
||||
},
|
||||
"age": {
|
||||
"description": "Age in years which must be equal to or greater than zero.",
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
const { getByText } = await renderInTestApp(
|
||||
<JsonSchemaDefinitionWidget definition={definition} />,
|
||||
);
|
||||
|
||||
expect(getByText(/lastName/i)).toBeInTheDocument();
|
||||
expect(getByText(/The person's last name./i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders error if definition is missing', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<JsonSchemaDefinitionWidget definition="{}" />,
|
||||
);
|
||||
expect(getByText(/No schema defined/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useTheme } from '@material-ui/core';
|
||||
import { JsonSchemaViewer } from '@stoplight/json-schema-viewer';
|
||||
import { injectStyles, useThemeStore } from '@stoplight/mosaic';
|
||||
import React, { useMemo } from 'react';
|
||||
import { useEffectOnce } from 'react-use';
|
||||
|
||||
injectStyles();
|
||||
|
||||
type Props = {
|
||||
definition: any;
|
||||
};
|
||||
|
||||
export const JsonSchemaDefinitionWidget = ({ definition }: Props) => {
|
||||
const schema = useMemo(() => JSON.parse(definition), [definition]);
|
||||
const theme = useTheme();
|
||||
const themeStore = useThemeStore();
|
||||
|
||||
useEffectOnce(() => {
|
||||
themeStore.setColor('background', theme.palette.background.paper);
|
||||
themeStore.setColor('text', theme.palette.text.primary);
|
||||
themeStore.setColor('primary', theme.palette.primary.main);
|
||||
themeStore.setColor('success', theme.palette.success.main);
|
||||
themeStore.setColor('warning', theme.palette.warning.main);
|
||||
themeStore.setColor('danger', theme.palette.error.main);
|
||||
themeStore.setMode(theme.palette.type);
|
||||
});
|
||||
return (
|
||||
<JsonSchemaViewer
|
||||
schema={schema}
|
||||
emptyText="No schema defined"
|
||||
defaultExpandedDepth={5}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright 2020 Spotify AB
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { JsonSchemaDefinitionWidget } from './JsonSchemaDefinitionWidget';
|
||||
@@ -20,4 +20,3 @@ export * from './AsyncApiDefinitionWidget';
|
||||
export * from './ComponentsCards';
|
||||
export * from './OpenApiDefinitionWidget';
|
||||
export * from './PlainApiDefinitionWidget';
|
||||
export * from './JsonSchemaDefinitionWidget';
|
||||
|
||||
Reference in New Issue
Block a user