grantila / typeconv

Convert between JSON Schema, TypeScript, GraphQL, Open API and SureType
MIT License
424 stars 8 forks source link

TypeScript to OpenApi #25

Open captainrdubb opened 2 years ago

captainrdubb commented 2 years ago

I would like to serve multiple versions of an api from a single web service. I also don't want to write OpenApi schemas. I want to write TypeScript, then I want to convert that to OpenApi. I am able to convert from TS to OpenApi (thanks!), however, I need to support multiple schema versions. If my project dirs look something like this...

.
`-- src/
    |-- business/
    |   `-- dtos/
    |       |-- v1/
    |       |   `-- index.ts
    |       `-- v2/
    |           `-- index.ts
    `-- customer/
        `-- dtos/
            |-- v1/
            |   `-- index.ts
            `-- v2/
                `-- index.ts

then i want the schema to look something like

{
    ...
    components:{
        schemas: {
            v1: {
                ...
            },
            v2:{
                ...
            }
        }
    }
}
captainrdubb commented 2 years ago

extending the example above, one of the index.ts files may have an interface like...

export interface Customer {
    name: string;
    creditCardNumber: string
    socialSecurityNumber: string
    streetAddress: string
    passportId: string
    dateOfBirth: string
    isHouseKeyUnderMat: boolean
}

export interface AttackAnimal {
    isExoticPet: boolean
    isillegal: boolean
    isTerritorial: boolean
}