feat: convert json to interfaces (#3566)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com> Co-authored-by: Liyas Thomas <liyascthomas@gmail.com> Co-authored-by: nivedin <nivedinp@gmail.com>
This commit is contained in:
committed by
GitHub
parent
1cc845e17d
commit
bb4b640e58
@@ -0,0 +1,26 @@
|
||||
const interfaceLanguages = [
|
||||
"cJSON",
|
||||
"C++",
|
||||
"C#",
|
||||
"Crystal",
|
||||
"Dart",
|
||||
"Elm",
|
||||
"Flow",
|
||||
"Go",
|
||||
"Haskell",
|
||||
"Java",
|
||||
"JavaScript",
|
||||
"Kotlin",
|
||||
"Objective-C",
|
||||
"PHP",
|
||||
"Pike",
|
||||
"Python",
|
||||
"Ruby",
|
||||
"Rust",
|
||||
"Scala3",
|
||||
"Smithy",
|
||||
"Swift",
|
||||
"TypeScript",
|
||||
]
|
||||
|
||||
export default interfaceLanguages
|
||||
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
quicktype,
|
||||
InputData,
|
||||
jsonInputForTargetLanguage,
|
||||
} from "quicktype-core"
|
||||
|
||||
async function jsonToLanguage(targetLanguage: string, jsonString: string) {
|
||||
const jsonInput = jsonInputForTargetLanguage(targetLanguage)
|
||||
|
||||
await jsonInput.addSource({
|
||||
name: "JSONSchema",
|
||||
samples: [jsonString],
|
||||
})
|
||||
|
||||
const inputData = new InputData()
|
||||
inputData.addInput(jsonInput)
|
||||
|
||||
return await quicktype({
|
||||
inputData,
|
||||
lang: targetLanguage,
|
||||
rendererOptions: {
|
||||
"just-types": true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export default jsonToLanguage
|
||||
Reference in New Issue
Block a user