[typescript] fix cast problem#303
Merged
Merged
Conversation
Contributor
Author
|
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 |
macjohnny
approved these changes
Jun 13, 2018
macjohnny
left a comment
Member
There was a problem hiding this comment.
looks good to me. thanks for the PR
wing328
reviewed
Jun 13, 2018
| NumberSchema dp = (NumberSchema) p; | ||
| if (dp.getDefault() != null) { | ||
| return dp.getDefault().toString(); | ||
| } |
Member
There was a problem hiding this comment.
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
Contributor
Author
There was a problem hiding this comment.
@wing328 yes indeed
if it fix
error and it is less code
It is better ;-)
Member
There was a problem hiding this comment.
👌 I'll merge this PR after you update the fix.
wing328 suggestion
Contributor
Author
|
Done |
wing328
approved these changes
Jun 14, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif 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\.master,3.1.x,4.0.x. Default:master.@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