openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open Swahjak opened this issue 4 years ago • 5 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] 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/api-platform/issues/1493)

Suggest a fix

Swahjak avatar Jun 29 '20 14:06 Swahjak