Revert "Add support for json schema to API docs"

Signed-off-by: Oliver Sand <oliver.sand@sda-se.com>
This commit is contained in:
Oliver Sand
2021-05-03 17:23:14 +02:00
parent 5c3a5306c1
commit f852f7381c
13 changed files with 6 additions and 1238 deletions
-5
View File
@@ -1,5 +0,0 @@
---
'@backstage/plugin-api-docs': patch
---
Add support for displaying JSON schemas.
@@ -5,7 +5,6 @@ metadata:
description: A collection of all Backstage example APIs
spec:
targets:
- ./apis/config-schema-api.yaml
- ./apis/hello-world-api.yaml
- ./apis/petstore-api.yaml
- ./apis/spotify-api.yaml
@@ -1,11 +0,0 @@
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: config-schema
description: A Backstage config schemas.
spec:
type: jsonschema
lifecycle: production
owner: team-a
definition:
$text: https://github.com/backstage/backstage/blob/master/plugins/config-schema/dev/example-schema.json
-1
View File
@@ -15,7 +15,6 @@ Right now, the following API formats are supported:
- [OpenAPI](https://swagger.io/specification/) 2 & 3
- [AsyncAPI](https://www.asyncapi.com/docs/specifications/latest/)
- [GraphQL](https://graphql.org/learn/schema/)
- [JSON Schema](https://json-schema.org/)
Other formats are displayed as plain text, but this can easily be extended.
-15
View File
@@ -27,7 +27,6 @@ import {
} from '../src';
import asyncapiApiEntity from './asyncapi-example-api.yaml';
import graphqlApiEntity from './graphql-example-api.yaml';
import jsonschemaApiEntity from './jsonschema-example-api.yaml';
import openapiApiEntity from './openapi-example-api.yaml';
import otherApiEntity from './other-example-api.yaml';
@@ -42,7 +41,6 @@ createDevApp()
items: [
openapiApiEntity,
asyncapiApiEntity,
jsonschemaApiEntity,
graphqlApiEntity,
otherApiEntity,
],
@@ -89,19 +87,6 @@ createDevApp()
</Page>
),
})
.addPage({
title: 'JSON Schema',
element: (
<Page themeId="home">
<Header title="JSON Schema" />
<Content>
<EntityProvider entity={(jsonschemaApiEntity as any) as Entity}>
<EntityApiDefinitionCard />
</EntityProvider>
</Content>
</Page>
),
})
.addPage({
title: 'GraphQL',
element: (
@@ -1,32 +0,0 @@
apiVersion: backstage.io/v1alpha1
kind: API
metadata:
name: persons
description: Person dataset
spec:
type: jsonschema
lifecycle: experimental
owner: team-c
# From https://json-schema.org/learn/miscellaneous-examples.html
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
}
}
}
-3
View File
@@ -38,9 +38,6 @@
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@stoplight/json-schema-viewer": "^4.0.0-beta.16",
"@stoplight/mosaic": "^1.0.0-beta.46",
"@stoplight/reporter": "^1.10.0",
"@types/react": "^16.9",
"graphiql": "^1.0.0-alpha.10",
"graphql": "^15.3.0",
@@ -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} />
),
},
];
}
@@ -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();
});
});
@@ -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';
-1
View File
@@ -20,4 +20,3 @@ export * from './AsyncApiDefinitionWidget';
export * from './ComponentsCards';
export * from './OpenApiDefinitionWidget';
export * from './PlainApiDefinitionWidget';
export * from './JsonSchemaDefinitionWidget';
+6 -1032
View File
File diff suppressed because it is too large Load Diff