Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support additionalProperties: true #1154

Open
ajenkins-cargometrics opened this issue Jul 18, 2022 · 3 comments · May be fixed by #1808
Open

Support additionalProperties: true #1154

ajenkins-cargometrics opened this issue Jul 18, 2022 · 3 comments · May be fixed by #1808

Comments

@ajenkins-cargometrics
Copy link

In OpenAPI 3, a schema like:

    AnyValues:
      description: An object whose property values can be of any type
      type: object
      additionalProperties: true

Should be equivalent to a typescript type like:

type AnyValues = {
    [key: string]: any
};

However what openapi-typescript-codegen actually generates is a type like this:

type AnyValues = {
};

That is, an object with no properties.

Additionally, OpenAPI allows combining additionalProperties: true with explicit property definitions. So an OpenAPI schema like this:

SomeType:
    type: object
    required: [name]
    properties:
        name:
            type: string
    additionalProperties: true

Should result in a typescript type like:

type SomeType = {
    name: string,
    [key: string]: any
};

but in fact it results in:

type SomeType = {
    name: string
};

Desired result: additionalProperties: true in an object schema should result in a [key: string]: any property in the corresponding typescript type.

@garcipat
Copy link

This is seems to be related to this one: #1066

@ajenkinski
Copy link

This is seems to be related to this one: #1066

That issue is different. In that case, the problem is that the spec doesn't specify a type for the schemas. That is, it has types defined like

  schemas:
    Account:
      properties:
        balance:
          type: string
          description: balance in unit WEI, presented with hex string
          example: '0x47ff1f90327aa0f8e'
        energy:
          type: string
          description: energy in uint WEI, presented with hex string
          example: '0xcf624158d591398'
        hasCode:
          type: boolean
          description: whether the account has code
          example: false

Simply adding type: object to the type fixes the problem. I'm not sure if the type field is supposed to be optional, but in any case it's a different problem.

@mrlubos
Copy link
Collaborator

mrlubos commented Feb 4, 2024

Hey @ajenkins-cargometrics, if this is still relevant, we got this feature in our fork that is kept in sync with this repository, would love you to give it a try

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants