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

typescript-fetch: unexpected behavior when creating "any" type #692

Open
shinkenji opened this issue May 28, 2020 · 0 comments
Open

typescript-fetch: unexpected behavior when creating "any" type #692

shinkenji opened this issue May 28, 2020 · 0 comments

Comments

@shinkenji
Copy link

I want to generate a model with a property that has the "any" type.
According to the OAS 3 spec, "Any Type" can be achieved by omitting the type property. See the section "Any Type" of https://swagger.io/docs/specification/data-models/data-types/
But typescript-fetch produces some unexpected results.

This behavior can be reproduced by modifying the Pet Store example on https://editor.swagger.io and generating the typescript-fetch client. The Pet Store example was converted to OAS 3 first.

For example:

    Pet:
      type: object
      properties:
        value:
          description: any value

When generating the typescript-fetch client the result is the following:

export interface Pet {
    /**
     * any value
     * @type {ModelObject}
     * @memberof Pet
     */
    value?: ModelObject;
}

The type ModelObject does not exist and the client can't be used that way.

After some tests I found out, that by adding additionalProperties, the result changes.

Adding additionalProperties: true results in:

export interface Pet {
    /**
     * any value
     * @type {{ [key: string]: any; }}
     * @memberof Pet
     */
    value?: { [key: string]: any; };
}

Adding additionalProperties: false results in:

export interface Pet {
    /**
     * any value
     * @type {any}
     * @memberof Pet
     */
    value?: any;
}

Please correct me if I am wrong, but I thought when additionalProperties is omitted, it is treated as if it was present with the value true.

Some additional info: Having a property with any type, the TSOA framework generates the following OAS:

"value": {
  "additionalProperties": true
}

Suggestion: If the type is omitted, typescript-fetch should create a property of type any. additionalProperties shouldn't influence the output if no type is provided.

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

No branches or pull requests

1 participant