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:
Rajdip Bhattacharya
2023-12-03 23:14:26 +05:30
committed by GitHub
parent 1cc845e17d
commit bb4b640e58
9 changed files with 283 additions and 64 deletions

View File

@@ -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

View File

@@ -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