jhannes / openapi-generator-typescript-fetch-api

TypeScript client library using Fetch API and API interfaces
13 stars 6 forks source link

Stronger implementation of readonly and writeonly fields #6

Open jhannes opened 3 years ago

jhannes commented 3 years ago

Motivating example with OmitReadOnly and OmitWriteOnly:

export interface PetsApiInterface {

    addPet(params: {
        pathParams: { storeId: string };
        petDto?: OmitReadOnly<PetDto>;
    }): Promise<void>;

    listPets(params: {
        pathParams: { storeId: string };
        queryParams?: { status?: Array<string>, tags?: Array<string>, bornAfter?: Date,  };
    }): Promise<OmitWriteOnly<PetDto>>;
}

OmitReadOnly can be created using https://stackoverflow.com/a/49579497/27658. Alternatively, OmitWriteOnly<PetDto> = Omit<PetDto, "foo" | "bar" | "baz"> can be generated (but the LHS syntax is probably to possible).

If this is done, the test data generator must also be updated to support Full, Input, Output (and perhaps MinimalOutput and MinimalInput) variants as well.