OpenAPITools / OpenAPITools/openapi-generator

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

Open
#6,810 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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 https://github.com/OpenAPITools/openapi-generator/issues/1080. Was addressed in https://github.com/OpenAPITools/openapi-generator/pull/1152 but seems to have been 'undone' in https://github.com/OpenAPITools/openapi-generator/commit/ced6e0502ec53031efa0a043924f7fe7e4b2691e#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

https://github.com/OpenAPITools/openapi-generator/issues/1080 https://github.com/OpenAPITools/openapi-generator/pull/1152 https://github.com/OpenAPITools/openapi-generator/commit/ced6e0502ec53031efa0a043924f7fe7e4b2691e#diff-328108658e03bbcf6cc8b931ffa7a63e (https://github.com/api-platform/core/issues/8000)

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typescript-angular generator using the provided OpenAPI schema and command, then trace how property names such as "hydra:member" become TypeScript interface properties. Compare the current sanitization behavior with the linked issue and pull request. Done means generated interfaces preserve valid colon-containing property names and the reproduced output is corrected.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.