swagger-api / swagger-api/swagger-codegen

[typescript-angular] property named '*' causes trouble

Open
#8,126 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

For some reason swashbuckle is creating a swagger doc with '*' property names (seems to have trouble with "Dictionary"). I was generating a typescript-angular client from that swagger-doc using editor.swagger.io and noticed that properties with the name '*' were not getting output.
It generated:

export interface BrokenThingProperties {
    ?: any;
}

This resulted in " error TS1131: Property or signature expected."

Swagger-codegen version

I assume editor.swagger.io is using a fairly recent version.

Swagger declaration file content or url
swagger: '2.0'
info:
  version: trunk
  title: API
basePath: /
paths:
  /path:
    post:
      tags:
        - graph
      summary: Invokes a command and returns the response.
      operationId: ApiV1GraphPost
      consumes:
        - application/json
        - text/json
        - application/json-patch+json
      produces: []
      parameters:
        - name: query
          in: body
          required: false
          schema:
            $ref: '#/definitions/brokenThing'
      responses:
        '200':
          description: Success
definitions:
  brokenThing:
    description: this thing results in broken typescript
    required:
      - query
    type: object
    properties:
      property1:
        type: object
        properties:
          '*':
            type: number
            example: '3'
      '*':
        example: 'a'
        type: string
Command line used for generation

http://editor.swagger.io

Steps to reproduce

Pasted the above YAML in editor.swagger.io and then generated typescript-angular client.

Related issues/PRs
Suggest a fix/enhancement

I'm not sure what i'm really expecting, javascript property names can be super weird. It could put out "*" as the name.

export interface BrokenThingProperties {
    "*"?: any;
}

At least it would compile... if that is even desirable in this case. Maybe '*' shouldn't be allowed as a property name? I'm pretty sure this won't play nice in many of the other languages either.

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 and the supplied Swagger definition, especially the object properties named '*'. Generate the client using the reproduction document and verify that the resulting BrokenThingProperties interface uses valid TypeScript property syntax and compiles without TS1131.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.