Skip to content

[BUG][typescript-angular] allow colons in TS interface property names #6810

@Swahjak

Description

@Swahjak

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Original issue #1080. Was addressed in #1152 but seems to have been 'undone' in ced6e05#diff-328108658e03bbcf6cc8b931ffa7a63e (by only allowing alphanumeric characters).

When generating from openapi documentation that contains colons the typescript generator will remove these colons. The specific case is generating a schema that's build using https://www.hydra-cg.com/spec/latest/core/.

openapi-generator version

4.3.1, not a regression (although it was fixed, it seems to have been 'undone' before reaching a release).

OpenAPI declaration file content or url

Schema:

  /api/v2/products:
    get:
      tags:
        - Product
      operationId: getProductCollection
      summary: Retrieves the collection of Product resources.
      responses:
        '200':
          description: Product collection response
          content:
            application/ld+json:
              schema:
                type: object
                properties:
                  'hydra:member':
                    type: array
                    items:
                      $ref: '#/components/schemas/Product.jsonld-get_product_list'
                  'hydra:totalItems':
                    type: integer
                    minimum: 0
                  'hydra:view':
                    type: object
                    properties:
                      '@id':
                        type: string
                        format: iri-reference
                      '@type':
                        type: string
                      'hydra:first':
                        type: string
                        format: iri-reference
                      'hydra:last':
                        type: string
                        format: iri-reference
                      'hydra:next':
                        type: string
                        format: iri-reference
                  'hydra:search':
                    type: object
                    properties:
                      '@type':
                        type: string
                      'hydra:template':
                        type: string
                      'hydra:variableRepresentation':
                        type: string
                      'hydra:mapping':
                        type: array
                        items:
                          type: object
                          properties:
                            '@type':
                              type: string
                            variable:
                              type: string
                            property:
                              type: string
                            required:
                              type: boolean
                required:
                  - 'hydra:member'

Response example:

{
    "@context": "/api/v2/contexts/Product",
    "@id": "/api/v2/products",
    "@type": "hydra:Collection",
    "hydra:member": [
        {
            "@id": "/api/v2/products/1",
            "@type": "Product",
            "image": null,
            "id": 1,
            "name": "Filtratiekast (technische ruimte) - 120cm",
            "stock": {
                "@id": "/api/v2/stocks/1",
                "@type": "Stock",
                "id": 1,
                "qty": 0,
                "qtyAvailable": 0,
                "qtyExpected": 0,
                "qtyReserved": 0
            },
            "imageUrl": "https://cdn.stocky.toppy-dev.nl//images/product/1/"
        }
    ],
    "hydra:totalItems": 11193,
    "hydra:view": {
        "@id": "/api/v2/products?page=1",
        "@type": "hydra:PartialCollectionView",
        "hydra:first": "/api/v2/products?page=1",
        "hydra:last": "/api/v2/products?page=224",
        "hydra:next": "/api/v2/products?page=2"
    },
    "hydra:search": {
        "@type": "hydra:IriTemplate",
        "hydra:template": "/api/v2/products{?search_name,barcodes.barcode,barcodes.barcode[],id,id[]}",
        "hydra:variableRepresentation": "BasicRepresentation",
        "hydra:mapping": [
            {
                "@type": "IriTemplateMapping",
                "variable": "search_name",
                "property": "name",
                "required": false
            },
            {
                "@type": "IriTemplateMapping",
                "variable": "barcodes.barcode",
                "property": "barcodes.barcode",
                "required": false
            },
            {
                "@type": "IriTemplateMapping",
                "variable": "barcodes.barcode[]",
                "property": "barcodes.barcode",
                "required": false
            },
            {
                "@type": "IriTemplateMapping",
                "variable": "id",
                "property": "id",
                "required": false
            },
            {
                "@type": "IriTemplateMapping",
                "variable": "id[]",
                "property": "id",
                "required": false
            }
        ]
    }
}

Generated typescript:

export interface InlineResponse2001 { 
    hydramember: Array<ProductJsonldGetProductList>;
    hydratotalItems?: number;
    hydraview?: InlineResponse200HydraView;
    hydrasearch?: InlineResponse200HydraSearch;
}
Command line used for generation

java -jar openapi-generator-cli.jar generate -i schema.json -g typescript-angular -o ./api

Steps to reproduce
  1. See schema & command used for generation
Related issues/PRs

#1080 #1152 ced6e05#diff-328108658e03bbcf6cc8b931ffa7a63e (api-platform/api-platform#1493)

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions