Skip to content

Every property marked as optional + 'any' types #158

Open
@kaesetoast

Description

@kaesetoast

API Platform version(s) affected: 3.0

Description
I generated typescript interfaces from a API Platform with this package. This worked really well, but there are two issues that make the result pretty much unusable for me:

  • Every property is marked as optional, even '@id'. Having to manual check for every property kinda defeats the purpose of having the interfaces in the first place.
  • Some properties are marked as any, even though there is a proper type in the API docs. E.g. ContactPerson.image is listed as string in Swagger, but appears as any in TypeScript. I also noticed dates being any – but this was in a API Platform 2.6 project and might not be an issue in newer versions.

Here is an example taken out of my Swagger docs:

{
  "hydra:member": [
    {
      "@context": "string",
      "@id": "string",
      "@type": "string",
      "id": "string",
      "name": "string",
      "phoneNumber": "string",
      "email": "string",
      "jobAdvertisements": [
        "string"
      ],
      "image": "string"
    }
  ],
  "hydra:totalItems": 0,
  "hydra:view": {
    "@id": "string",
    "type": "string",
    "hydra:first": "string",
    "hydra:last": "string",
    "hydra:previous": "string",
    "hydra:next": "string"
  },
  "hydra:search": {
    "@type": "string",
    "hydra:template": "string",
    "hydra:variableRepresentation": "string",
    "hydra:mapping": [
      {
        "@type": "string",
        "variable": "string",
        "property": "string",
        "required": true
      }
    ]
  }
}

And this is the generated interface:

export interface ContactPerson {
  "@id"?: string;
  name?: string;
  phoneNumber?: string;
  email?: string;
  jobAdvertisements?: string[];
  image?: any;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions