Q42 / openapi-typescript-validator

Generate typescript with ajv validation based on openapi schemas
26 stars 14 forks source link

Feature: option for additional properties #21

Closed SiebrenKazemier closed 1 year ago

SiebrenKazemier commented 1 year ago

Problem

There is no option for additional properties on the outer component. Currently, the only option is to use the anonymousData() type. However this always results in:

`export interface BazComponent { type: "baz"; name: string; additionalProps: {

}

}`

Solution

Add "additionalProperties" to the objectBaseOptions to create objects like:

`export interface BazComponent { type: "baz"; name: string;

}`

hermanbanken commented 1 year ago

Isn't there the option to extend a data type using anonymousData?

types.TitleComponent = anonymousData(object({
  type: constant('title'),
  title: string(),
  subtitle: nillable(string),
}));
// or
types.TitleComponent = object({
  type: constant('title'),
  title: string(),
  subtitle: nillable(string),
}, anonymousData());

should give you

export interface TitleComponent {
  type: "title";
  name: string;
  subtitle?: string;
  [k: string]: string;
}

Right?