-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Conversation
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 |
There was a problem hiding this 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(); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ;-)
There was a problem hiding this comment.
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 suggestion
Done |
PR checklist
./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\
.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