Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize build #5

Merged
merged 4 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*.vscode
*.fleet

# OSX
.DS_Store

# node.js
node_modules/
npm-debug.log
yarn-error.log

# build
dist/

# Optional npm cache directory
.npm

Expand Down Expand Up @@ -40,3 +40,6 @@ jspm_packages/

# Unit Test Coverage
coverage/

# OSX
.DS_Store
101 changes: 85 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

[ci-url]: https://github.com/PADAS/react-native-jsonforms-formatter/actions/workflows/npm-build.yml/badge.svg

A [React Native](https://reactnative.dev/) [JSON Schema](https://json-schema.org/) formatter to build mobile forms based on [JSON Forms](https://jsonforms.io/)
A Node.js library for validating JSONSchema and generating UISchema for a custom ReactNative JSONForms element.

React Native JSON Forms Formatter is an alternative solution for rendering JTD schemas in JSON Forms. It validates JSON Schemas and generates UI schemas compatible with the [JSON Forms library](https://github.com/eclipsesource/jsonforms), even for schemas that are not supported by other JSON Schema libraries.
## Installation

## Install
You can install the library using npm or yarn:

#### Using `yarn`

Expand All @@ -22,27 +22,96 @@ npm install --save react-native-jsonforms-formatter
```

## Usage
The library provides two main functions: `validateJSONSchema` and `generateUISchema`.

```javascript
import { validateJSONSchema, generateUISchema } 'react-native-jsonforms-formatter';
### Validating JSONSchema

You can use the `validateJSONSchema` function to validate a JSONSchema string:

```typescript
import { validateJSONSchema } from 'react-native-jsonforms-formatter';

const stringSchema = `
{
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"age": {
"type": "integer",
"title": "Age"
}
}
}
`;

const jsonSchema = validateJSONSchema(stringSchema);
```

The `validateJSONSchema` function returns a valid JSONSchema object if the input string is a valid JSONSchema. If the input is not valid, it will throw an error.

### Generating UISchema
You can use the `generateUISchema` function to generate a UISchema object from a valid JSONSchema:

```typescript
import { generateUISchema } from 'react-native-jsonforms-formatter';

const uiSchema = generateUISchema(jsonSchema);
```

Your json schema needs to be validated and formatted in order to make it parsable and valid for JSON Forms library. The library will generate a valid UI schema for input into JSON Forms to be used in a `JsonForms` component.
The `generateUISchema` function returns a `UISchema` object that can be used with the ReactNative JSONForms library.

## Putting it all together
Here's an example of how you can use the library in a ReactNative application:

```typescript
import React from 'react';
import { JsonForms } from '@jsonforms/react-native';
import { validateJSONSchema, generateUISchema } from 'react-native-jsonforms-formatter';
import { RNRenderers, RNCells } from '@jsonforms/react-native-renderers';

const stringSchema = `
{
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name"
},
"age": {
"type": "integer",
"title": "Age"
}
}
}
`;

```javascript
const jsonSchema = validateJSONSchema(stringSchema);
const uiSchema = generateJSONUISchema(jsonSchema);

<JsonForms
schema={jsonSchema}
uischema={uiSchema}
data={data}
renderers={RNRenderers}
cells={RNCells}
/>
const uiSchema = generateUISchema(jsonSchema);

const App = () => {
const [data, setData] = React.useState({ name: 'John Doe', age: 30 });

return (
<JsonForms
schema={jsonSchema}
uischema={uiSchema}
data={data}
renderers={RNRenderers}
cells={RNCells}
onChange={(event) => setData(event.data)}
/>
);
};

export default App;
```

## Contributors
Contributions are welcome! If you find a bug or have a feature request, please open an issue.

<a href="https://github.com/PADAS/react-native-jsonforms-formatter/graphs/contributors">
<img src="https://contributors-img.web.app/image?repo=PADAS/react-native-jsonforms-formatter" />
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ElementDisplay } from "../../utils/utils";
import { ElementDisplay } from "../../src/utils/utils";

export const JSON_SCHEMA_SPECIAL_CHARS_FAKE_DATA = '{\n' +
' "definition": [\n' +
Expand Down
Loading