mirror of
https://github.com/ritz078/transform.git
synced 2026-12-05 14:14:59 +03:00
add json schema to rust serde (#56)
* add json schema to rust serde * fixes * fixes
This commit is contained in:
1 parent
5d11840f16
commit
b690634565
7 files changed
+217
-59
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import json from '../utils/dummy-json-schema'
|
||||
import loadWorker from '../utils/loadWorker'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => {
|
||||
this.promiseWorker = loadWorker(
|
||||
'json-schema-to-rust-serde.js',
|
||||
this
|
||||
).promiseWorker
|
||||
return this.promiseWorker.postMessage(code)
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<Layout pathname={this.props.url.pathname}>
|
||||
<ConversionPanel
|
||||
leftTitle='JSON Schema'
|
||||
rightTitle='Rust Serde'
|
||||
getTransformedValue={this.getTransformedValue}
|
||||
defaultText={json}
|
||||
leftMode='javascript'
|
||||
rightMode='rust'
|
||||
url={this.props.url}
|
||||
prettifyRightPanel={false}
|
||||
/>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -2,34 +2,7 @@ import React, { PureComponent } from 'react'
|
||||
import Layout from '../components/Layout'
|
||||
import ConversionPanel from '../components/ConversionPanel'
|
||||
import { compile } from 'json-schema-to-typescript'
|
||||
|
||||
const json = `{
|
||||
title: 'Example Schema',
|
||||
type: 'object',
|
||||
properties: {
|
||||
firstName: {
|
||||
type: 'string'
|
||||
},
|
||||
lastName: {
|
||||
type: 'string'
|
||||
},
|
||||
age: {
|
||||
description: 'Age in years',
|
||||
type: 'integer',
|
||||
minimum: 0
|
||||
},
|
||||
height: {
|
||||
type: 'number'
|
||||
},
|
||||
favoriteFoods: {
|
||||
type: 'array'
|
||||
},
|
||||
likesDogs: {
|
||||
type: 'boolean'
|
||||
}
|
||||
},
|
||||
required: ['firstName', 'lastName']
|
||||
}`
|
||||
import json from '../utils/dummy-json-schema'
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = code => compile(eval('(' + code + ')'))
|
||||
|
||||
Reference in new issue
Block a user