ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.43k stars 30 forks source link

types can't parse for $ref in allOf and refer to allOf/anyOf/oneOf #126

Open timothyliu opened 1 year ago

timothyliu commented 1 year ago

Thank you! json-schema-to-ts is good job for me, but this case I need your support:

const testSchema = {
    $id: 'test',
    type: 'object',
    patternProperties: {
        '^[\\w_$]+$': {
            title: '自定義樣式',
            type: 'object',
            anyOf: [
                {
                    properties: {
                        street: { type: 'string', },
                        city: { type: 'string', },
                        state: { type: 'string', },
                    },
                },
                {
                    properties: {
                        type: { enum: ['residential', 'business',], },
                    },
                },
            ],
        },
    },
} as const

const addressSchema = {
    type: 'object',
    allOf: [
        {
            properties: {
                address: { type: 'string', },
                city: { type: 'string', },
                state: { type: 'string', },
            },
            required: ['address', 'city', 'state',],
        },
        {
            properties: {
                type: { enum: ['residential', 'business',], },
            },
        },
        {
            $ref: 'test',
        },
    ],
} as const

export type Address = FromSchema<typeof addressSchema, {
    references: [
        typeof testSchema
    ]
}>
// Address ==>  never