Skip to content

Commit

Permalink
Merge pull request #220 from open-rpc/fix/default-to-petstore
Browse files Browse the repository at this point in the history
fix: default to petstore
  • Loading branch information
shanejonas authored Jun 11, 2019
2 parents 2c17a97 + c314838 commit cb826ef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
17 changes: 8 additions & 9 deletions src/MonacoJSONEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import _ from "lodash";
import { JSONSchema4 } from "json-schema";
import schema from "@open-rpc/meta-schema";
import { IUISchema } from "./UISchema";
import examplesList from "./examplesList";

interface IProps {
defaultValue?: string;
Expand Down Expand Up @@ -46,16 +47,14 @@ export default class MonacoJSONEditor extends React.Component<IProps> {
this.metaSchema = schema as JSONSchema4;
const defaultV = _.isEmpty(this.props.defaultValue) ? null
: JSON.stringify(this.props.defaultValue, undefined, " ");
const emptySchema = JSON.stringify({
openrpc: "1.0.0-rc1",
info: {
title: "",
version: "",
},
methods: [],
}, undefined, "\t");
const ex = examplesList.find((e) => e.name! === "petstore");
const defaultSchema = await fetch(ex!.url).then((res) => res.text());
const localStorageSchema = window.localStorage.getItem("schema");
const defaultValue = defaultV || localStorageSchema || emptySchema;
let defaultValue = (defaultV || localStorageSchema || defaultSchema).trim();

if (defaultValue === "{}" || defaultValue === "") {
defaultValue = defaultSchema;
}

model = monaco.editor.createModel(defaultValue, "json", modelUri);
monaco.languages.json.jsonDefaults.setDiagnosticsOptions({
Expand Down
28 changes: 2 additions & 26 deletions src/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Grid,
} from "@material-ui/core";
import { IUISchema } from "../UISchema";
import suggestions from "../examplesList";

const styles = (theme: Theme) => ({
title: {
Expand All @@ -31,33 +32,8 @@ interface IProps extends WithStyles<typeof styles> {
onSplitViewChange?: any;
}


function getSuggestion(query: string | null) {
const suggestions = [
{
name: "api-with-examples",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/api-with-examples-openrpc.json", //tslint:disable-line
},
{
name: "link-example",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/link-example-openrpc.json", //tslint:disable-line
},
{
name: "params-by-name-petstore",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/params-by-name-petstore-openrpc.json", //tslint:disable-line
},
{
name: "petstore-expanded",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/petstore-expanded-openrpc.json", //tslint:disable-line
},
{
name: "petstore",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/petstore-openrpc.json", //tslint:disable-line
},
{
name: "simple-math",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/simple-math-openrpc.json", //tslint:disable-line
},
];
if (!query) {
return suggestions;
}
Expand Down
26 changes: 26 additions & 0 deletions src/examplesList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default [
{
name: "api-with-examples",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/api-with-examples-openrpc.json", //tslint:disable-line
},
{
name: "link-example",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/link-example-openrpc.json", //tslint:disable-line
},
{
name: "params-by-name-petstore",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/params-by-name-petstore-openrpc.json", //tslint:disable-line
},
{
name: "petstore-expanded",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/petstore-expanded-openrpc.json", //tslint:disable-line
},
{
name: "petstore",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/petstore-openrpc.json", //tslint:disable-line
},
{
name: "simple-math",
url: "https://raw.githubusercontent.com/open-rpc/examples/master/service-descriptions/simple-math-openrpc.json", //tslint:disable-line
},
];

0 comments on commit cb826ef

Please sign in to comment.