swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

additionalProperties management problem in Swagger 2

Open paztis opened this issue 3 years ago • 2 comments

In swagger 2, additionalProperties are very limited. They didn't support the true and {} values. To replace this they define it like this

  MyObject:
    type: object
    properties:
      id:
        type: string
    additionalProperties:
        type: object

It works only because in java like words String, Boolean and Numbers are Objects

in swagger 2, it must be transpiled in

export interface MyObject {
    id?: string;
    [key: string]: {}; // or [key: string]: any
} 

but for now it is transpiled in

export interface MyObject {
    id?: string;
}

result is the same If I try to transpile below code

  MyObject:
    type: object
    properties:
      id:
        type: string
    additionalProperties: {}

The only case the correctly works is

  MyObject:
    type: object
    properties:
      id:
        type: string
    additionalProperties: true

Swagger file is correctly converted with Swager.io typescript generators

Is it possible to fix it ?

paztis avatar Feb 23 '22 12:02 paztis

Problem came from schema.js file


  if (additionalProperties === true) {
    propertiesContent.push({
      $$raw: { additionalProperties },
      description: "",
      isRequired: false,
      field: `[key: ${TS_KEYWORDS.STRING}]: ${TS_KEYWORDS.ANY}`,
    });
  }

  return propertiesContent;

It seams you only support the additionalProperties: true case, not the others

paztis avatar Feb 23 '22 13:02 paztis

Is this module still supported ? I didn't see any activity since few months

paztis avatar Mar 29 '22 21:03 paztis

Hello @paztis , this problem will be fixed in next release

js2me avatar Oct 29 '22 07:10 js2me