Merge branch 'master' into useRelatedEntities-batches

This commit is contained in:
Will Sewell
2021-05-03 15:15:24 +01:00
37 changed files with 1432 additions and 115 deletions
+1
View File
@@ -15,6 +15,7 @@ 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,6 +27,7 @@ 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';
@@ -41,6 +42,7 @@ createDevApp()
items: [
openapiApiEntity,
asyncapiApiEntity,
jsonschemaApiEntity,
graphqlApiEntity,
otherApiEntity,
],
@@ -87,6 +89,19 @@ 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: (
@@ -0,0 +1,32 @@
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,6 +38,9 @@
"@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,6 +16,7 @@
import React from 'react';
import { AsyncApiDefinitionWidget } from '../AsyncApiDefinitionWidget';
import { GraphQlDefinitionWidget } from '../GraphQlDefinitionWidget';
import { JsonSchemaDefinitionWidget } from '../JsonSchemaDefinitionWidget';
import { OpenApiDefinitionWidget } from '../OpenApiDefinitionWidget';
export type ApiDefinitionWidget = {
@@ -51,5 +52,13 @@ export function defaultDefinitionWidgets(): ApiDefinitionWidget[] {
<GraphQlDefinitionWidget definition={definition} />
),
},
{
type: 'jsonschema',
title: 'JSON Schema',
rawLanguage: 'json',
component: definition => (
<JsonSchemaDefinitionWidget definition={definition} />
),
},
];
}
@@ -0,0 +1,61 @@
/*
* 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();
});
});
@@ -0,0 +1,50 @@
/*
* 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}
/>
);
};
@@ -0,0 +1,17 @@
/*
* 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,3 +20,4 @@ export * from './AsyncApiDefinitionWidget';
export * from './ComponentsCards';
export * from './OpenApiDefinitionWidget';
export * from './PlainApiDefinitionWidget';
export * from './JsonSchemaDefinitionWidget';
@@ -156,7 +156,7 @@ describe('github', () => {
describe('getOrganizationRepositories', () => {
it('read repositories', async () => {
const input: QueryResponse = {
organization: {
repositoryOwner: {
repositories: {
nodes: [
{
@@ -20,7 +20,8 @@ import { graphql } from '@octokit/graphql';
// Graphql types
export type QueryResponse = {
organization: Organization;
organization?: Organization;
repositoryOwner?: Organization | User;
};
export type Organization = {
@@ -41,6 +42,7 @@ export type User = {
avatarUrl?: string;
email?: string;
name?: string;
repositories?: Connection<Repository>;
};
export type Team = {
@@ -228,28 +230,27 @@ export async function getOrganizationRepositories(
org: string,
): Promise<{ repositories: Repository[] }> {
const query = `
query repositories($org: String!, $cursor: String) {
organization(login: $org) {
name
repositories(first: 100, after: $cursor) {
nodes {
name
url
isArchived
}
pageInfo {
hasNextPage
endCursor
query repositories($org: String!, $cursor: String) {
repositoryOwner(login: $org) {
login
repositories(first: 100, after: $cursor) {
nodes {
name
url
isArchived
}
pageInfo {
hasNextPage
endCursor
}
}
}
}
}
`;
}`;
const repositories = await queryWithPaging(
client,
query,
r => r.organization?.repositories,
r => r.repositoryOwner?.repositories,
x => x,
{ org },
);
+1 -1
View File
@@ -40,7 +40,7 @@
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@octokit/rest": "^18.0.12",
"@octokit/rest": "^18.5.3",
"@types/react": "^16.9",
"git-url-parse": "^11.4.4",
"js-base64": "^3.6.0",
+1 -1
View File
@@ -40,7 +40,7 @@
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@octokit/rest": "^18.0.12",
"@octokit/rest": "^18.5.3",
"moment": "^2.27.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
@@ -202,13 +202,13 @@ export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => {
<TableCell>
<Typography noWrap>Message</Typography>
</TableCell>
<TableCell>{details.value?.head_commit.message}</TableCell>
<TableCell>{details.value?.head_commit?.message}</TableCell>
</TableRow>
<TableRow>
<TableCell>
<Typography noWrap>Commit ID</Typography>
</TableCell>
<TableCell>{details.value?.head_commit.id}</TableCell>
<TableCell>{details.value?.head_commit?.id}</TableCell>
</TableRow>
<TableRow>
<TableCell>
@@ -231,7 +231,7 @@ export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => {
<TableCell>
<Typography noWrap>Author</Typography>
</TableCell>
<TableCell>{`${details.value?.head_commit.author?.name} (${details.value?.head_commit.author?.email})`}</TableCell>
<TableCell>{`${details.value?.head_commit?.author?.name} (${details.value?.head_commit?.author?.email})`}</TableCell>
</TableRow>
<TableRow>
<TableCell>
+1 -1
View File
@@ -39,7 +39,7 @@
"@material-ui/lab": "4.0.0-alpha.45",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-hook-form": "^6.6.0",
"react-hook-form": "^6.15.4",
"react-router": "6.0.0-beta.0",
"react-router-dom": "6.0.0-beta.0",
"react-use": "^15.3.3"
+1 -1
View File
@@ -37,7 +37,7 @@
"@backstage/integration": "^0.5.1",
"@gitbeaker/core": "^28.0.2",
"@gitbeaker/node": "^28.0.2",
"@octokit/rest": "^18.0.12",
"@octokit/rest": "^18.5.3",
"@types/dockerode": "^3.2.1",
"@types/express": "^4.17.6",
"@types/git-url-parse": "^9.0.0",