1.2.0 • Published 4 years ago
@lancercomet/suntori.generator v1.2.0
SunTori codegen
A codegen to create SunTori codes from JSON.
import { generate } from '@lancercomet/suntori.generator'
const result = await generate({
  jsonObject: {
    name: 'John Smith',
    age: 200,
    address: [
      {
        name: 'Home',
        locaiton: 'The earth'
      }
    ]
  },
  rootClassName: 'User'
})Result:
@Serializable()
class UserAddress {
  @JsonProperty('name')
  name: string = ''
  @JsonProperty('location')
  location: string = ''
}
@Serializable()
class User {
  @JsonProperty('name')
  name: string = ''
  @JsonProperty('age')
  age: number = 0
  @JsonProperty({
    name: 'address',
    type: UserAddress
  })
  address: UserAddress[] = []
}Options
- jsonObject: neverThe JSON payload. Should be a JavaScript Object.
- rootClassName: string = 'Root'The name for generated class. And it will be used as prefix for all subclasses.
- useCamelCase: boolean = trueUse- camelCaseduring code generation.
- addReadonly: boolean = trueAdd- readonlymodifier to all members of a class.
About null
All null JSON fields would be converted to the unknown, as well as empty arrays.
await generate({
  jsonObject: {
    a: null,
    b: []
  }
})
// To
@Serializable()
class Root {
  @JsonProperty('a')
  a: unknown = null
  @JsonProperty('b')
  b: unknown[] = []
}License
Apache-2.0