Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript] fix cast problem #303

Merged
merged 2 commits into from
Jun 14, 2018
Merged

[typescript] fix cast problem #303

merged 2 commits into from
Jun 14, 2018

Conversation

topce
Copy link
Contributor

@topce topce commented Jun 13, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
    @TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01)

Description of the PR

(details of the change, additional tests that have been done, reference to the issue for tracking, etc)
In same cases there is error when generate typescript-angular
Exception: io.swagger.v3.oas.models.media.Schema cannot be cast to io.swagger.v3.oas.models.media.NumberSchema
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:934)
at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:825)
at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:460)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:786)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:315)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:58)
Caused by: java.lang.ClassCastException: io.swagger.v3.oas.models.media.Schema cannot be cast to io.swagger.v3.oas.models.media.NumberSchema
at org.openapitools.codegen.languages.AbstractTypeScriptClientCodegen.toDefaultValue(AbstractTypeScriptClientCodegen.java:328)
at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1609)
at org.openapitools.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:2530)
at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:2221)
at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:902)
... 5 more

@topce
Copy link
Contributor Author

topce commented Jun 13, 2018

example of swagger.yaml that can cause error (if somebody want to reproduce it)

swagger: '2.0'
info:
  title: Test
  description: Test
  version: "1.0.0"
host: "localhost:8002"
schemes:
  - http
basePath: /v1
produces:
  - application/json
securityDefinitions:
  basicAuth:
    type: basic
    description: HTTP Basic Authentication
security:
  - basicAuth: []
paths:
  /categories/{id}/statistics:
    get:
      operationId: getCategoryStatistics
      security:
        - basicAuth: []
      tags:
        - Category
      description: get the list of calculated IG statistics
      parameters:
        - name: id
          in: path
          type: string
          required: true
        - name: limit
          in: query
          description: |
            the amount of values per page
            values = 25 (default) / 50 / 100 / 0 (all)
            if not any value is passed, the default value (25) is used
          required: false
          type: number
        - name: page
          in: query
          description: the number of the page
          required: false
          type: number
      responses:
        '200':
          description: OK
          schema:
            $ref: '#/definitions/PagedStatisticsContents'
        '405':
          description: Invalid ref
        '500':
          description: Internal Server Error
definitions:
  PagedStatisticsContents:
    type: object
    required:
      [data,total]
    properties:
      data:
        type: array
        items:
          $ref: "#/definitions/StatisticsContent"
      total:
        type: number
        description: |
          return the total amount of nodes, without paging
          so the UI can compute the number of pages
  StatisticsContent:
    type: object
    properties:
      name:
        type: string
      size:
        type: string
      modifiedDate:
        type: string
        format: date
      downloadURL:
        type: string
tags:
 - name: Category
   description: all the operations related to

Copy link
Member

@macjohnny macjohnny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. thanks for the PR

NumberSchema dp = (NumberSchema) p;
if (dp.getDefault() != null) {
return dp.getDefault().toString();
}
Copy link
Member

@wing328 wing328 Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we instead follow the case for Integer below without doing any casting?

             if (p.getDefault() != null) {
                 return p.getDefault().toString();
             }

Line 336 to 338 after the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 yes indeed
if it fix
error and it is less code
It is better ;-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 I'll merge this PR after you update the fix.

@wing328 wing328 added this to the 3.0.2 milestone Jun 13, 2018
@jmini jmini changed the title fix cast problem [typescript] fix cast problem Jun 14, 2018
wing328 suggestion
@topce
Copy link
Contributor Author

topce commented Jun 14, 2018

Done
Thank you guys: @wing328 @jmini and @macjohnny

@wing328 wing328 merged commit f8e61ac into OpenAPITools:master Jun 14, 2018
@topce topce deleted the fix-cast branch April 23, 2019 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants