-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[JavaScript (with promises)] Bug following $ref in object properties #4973
Comments
@advance512 instead of defining |
I wanted to be able to modify the ID type easily, to set it as either a UUID or an Integer in one place for different use-cases. I side stepped the issue for now, but it is definitely not working as expected: the OpenAPI spec says this is valid syntax. |
Yup, I think it's a bug with the Swagger Parser. Please report the issue to github.com/swagger-api/swagger-parser. For the time being, please define |
Eh, I'm committing a test in swagger-parser, but I think it's behaving correctly. Copying the definition right out of here and putting it in this test: The response is exactly what I'd expect: {
"swagger" : "2.0",
"info" : {
"description" : "It works.",
"version" : "1.0.0",
"title" : "My API"
},
"basePath" : "/",
"schemes" : [ "https" ],
"produces" : [ "application/json" ],
"definitions" : {
"ID" : {
"type" : "integer",
"format" : "int64",
"description" : "An entity identifer"
},
"User" : {
"type" : "object",
"required" : [ "emailAddress" ],
"properties" : {
"id" : {
"$ref" : "#/definitions/ID"
},
"emailAddress" : {
"type" : "string",
"format" : "email",
"minLength" : 6,
"maxLength" : 254
}
}
}
}
} What am I missing? |
Thanks a lot for the super quick response, @fehguy. The output is indeed a valid Swagger schema (formatted as JSON). It includes the $ref external definition that was defined in the source YAML, properly. Since I'm not familiar with how You are saying, it seems to me, that the issue is not in |
This is still broken, even in the latest v3.0.0. This definition
becomes this code:
I mean, just look at this function:
An example run would have data be 1, and obj undefined. Yet it still returns obj... it makes no sense. This was built with useES6=false, which I need to do as I am not transpiling the code. |
I still see this issue, even with v2.4.0 and v3.0.0. Here's an example Swagger file,
Generating a JavaScript file, for example with 3.0.0:
It generates this
Have a good look at the
The It has been nearly a year. Am I truly the only one that sees this bug? |
cc @CodeNinjai @frol @cliffano to see if they can help answer your questions. |
Thanks, @wing328 , I'd love to begin a conversation and potentially help solve this issue.. |
@advance512 I will have a look into it, so we can discuss why this is happening, ok? |
Thanks, @CodeNinjai. I am available for any assistance required |
Any update, @CodeNinjai ? |
I think that PR #7991 might solve this issue. |
@CodeNinjai |
@CodeNinjai |
When will I be able to download a binary (JAR file) that includes this fix? (Based on latest master) |
@CodeNinjai |
Any update on this? This has been open for nearly 1.5 years. Thanks. |
This seems fixed in swagger-codegen-cli-2.4.0-20181113.142213-347.jar |
Seems that a new issue has been introduced in swagger-codegen-cli-2.4.0-20181113.142213-347.jar or before. Code of this format:
generates JavaScript client code like this:
You will notice this line specifically is obviously broken:
it should be:
Or at least:
This seems like a regression. |
hey @advance512 |
closing issue, but please let me know if issue is still present and i'll work on asap. |
Hi @HugoMario, We actually moved to cpenAPI-generator, as the swagger-codegen seemed unmaintained. If I get some time the coming weeks, I'll try to see what swagger-codegen outputs. |
Description
Generated type file
ID
contains the following:data
is an integer input.obj
is null. Hence, the result isexports()
instead of simplydata
.Swagger-codegen version
Build package: io.swagger.codegen.languages.JavascriptClientCodegen
v2.2.2
Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen-cli.jar generate -i ../source.yaml -l javascript --additional-properties usePromises=true -o ./javascript/
Steps to reproduce
Use the above definitions in any operation. You'll get a result object with an exports() objects instead of an ID integer.
Related issues
Suggest a Fix
It tempts me to say:
but I actually think the issue is that swagger-codegen doesn't follow the $ref properly. Not certain
The text was updated successfully, but these errors were encountered: