Skip to content

additionalProperties management problem in Swagger 2 #343

@paztis

Description

@paztis

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 ?

Activity

paztis

paztis commented on Feb 23, 2022

@paztis
Author

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

paztis commented on Mar 29, 2022

@paztis
Author

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

self-assigned this
on Aug 17, 2022
pinned this issue on Aug 17, 2022
unpinned this issue on Oct 29, 2022
js2me

js2me commented on Oct 29, 2022

@js2me
Member

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

added theissue type on Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @paztis@js2me

      Issue actions

        additionalProperties management problem in Swagger 2 · Issue #343 · acacode/swagger-typescript-api