-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
[rust-server] features broken from swagger-codegen #307
Comments
Right. I'm planning to pick this up this week. |
My plan is to add notes to this issue as I go. I'm likely to be working on this over a few days, and don't want to forget things. The schema problem is interesting. From my testing, it appears that the problem is any base schema in a response with at least one header defined. both the body and first header get the type of the first header. The type is correct in the generated Hmm. It looks as if the problem is that inside EDIT: repro template: swagger: '2.0'
info:
description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io:80
basePath: /v2
tags:
- name: pet
description: Everything about your Pets
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
schemes:
- http
paths:
/user/login:
get:
tags:
- user
summary: Logs user into the system
operationId: loginUser
produces:
- application/json
responses:
'200':
description: successful operation
schema:
type: number
headers:
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
# X-Expires-After:
# type: string
# format: date-time
# description: date in UTC when token expires
'201':
description: wtf
schema:
type: string
'400':
description: Invalid username/password supplied EDIT2: I've gone back in time to before #290, and saw this error. This suggests to me that this is caused by the move from swagger/v2 to openapi/v3 (rather than anything I did in #290) |
On the byte form params - I don't think this ever worked. What happens is that if So:
In this issue, I'm just trying to match the behaviour of the old swagger-codegen rather than fixing any pre-existing bugs. Hence, I plan to check whether the change to EDIT: OK - I think what's happened is that the old mechanism for file parsing has been fundamentally broken by the switch to OpenAPI v3:
What this means is that the old |
I compared Swagger Codegen and OpenAPI Generator and both show the following mustache tags:
Do mean you're looking for the data type of the response body? Can you point me to the exact lines in the mustache template having the issue and ideally what you expect? |
Speaking of |
Thanks for taking a look. On the first point - see https://github.com/bjgill/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/rust-server/lib.mustache#L45 for the template. Then, On the second - I think we realised this at the same time. In swagger-codegen's |
The fourth point ( In any case, #538 will fix this as well. |
Looking at the second, I wonder is this is another weird mustache-related bug. Repro template: swagger: '2.0'
info:
description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
schemes:
- http
paths:
/pet:
get:
tags:
- fake
description: To test enum parameters
consumes:
- "application/x-www-form-urlencoded"
parameters:
- name: enum_form_string_array
type: array
items:
type: string
default: '$'
enum:
- '>'
- '$'
in: formData
description: Form parameter enum test (string array)
- name: enum_form_string
type: string
default: '-efg'
enum:
- _abc
- '-efg'
- (xyz)
in: formData
description: Form parameter enum test (string)
responses:
'400':
description: Invalid request Interestingly, if I comment out either of EDIT: I've not confirmed, but I suspect that EDIT2: the compilation error is a red herring. I've confirmed that EDIT3: I've raised #545 to cover the problem with |
@wing328 - I'm suspicious that something has changed in the mustache template logic. I'll use the following spec to demonstrate: swagger: '2.0'
info:
description: "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
version: 1.0.0
title: OpenAPI Petstore
license:
name: Apache-2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
host: petstore.swagger.io:80
basePath: /v2
tags:
- name: pet
description: Everything about your Pets
- name: store
description: Access to Petstore orders
- name: user
description: Operations about user
schemes:
- http
paths:
/user/login:
get:
tags:
- user
summary: Logs user into the system
operationId: loginUser
produces:
- application/json
responses:
'200':
description: successful operation
schema:
type: number
headers:
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
# X-Expires-After:
# type: string
# format: date-time
# description: date in UTC when token expires
'201':
description: wtf
schema:
type: string
headers:
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user
'400':
description: Invalid username/password supplied
headers:
X-Rate-Limit:
type: integer
format: int32
description: calls per hour allowed by the user Swagger-codegen
yields #[derive(Debug, PartialEq)]
pub enum LoginUserResponse {
/// successful operation
SuccessfulOperation { body: f64, x_rate_limit: i32 } ,
/// wtf
Wtf { body: String, x_rate_limit: i32 } ,
/// Invalid username/password supplied
InvalidUsername { x_rate_limit: i32 } ,
} Openapi-generator
yields #[derive(Debug, PartialEq)]
pub enum LoginUserResponse {
/// successful operation
SuccessfulOperation { body: i32, x_rate_limit: i32 } ,
/// wtf
Wtf { body: i32, x_rate_limit: i32 } ,
/// Invalid username/password supplied
InvalidUsername , x_rate_limit: i32 } ,
} HypothesisFrom the output from openapi-generator, it looks as if the difference is to do with what happens inside How to fixThe ideal fix would be to restore the previous (swagger-codegen) behaviour. Failing that, we could probably work-around by some mixture of template changes and Rust macros. |
On my previous comment. I've now read through some of the mustache spec. It looks like the new behaviour is probably correct. I think I may have found a way to fix by using |
OK, with #547 merged, we are now feature back-compatible. |
Description
In #290, we got rust-server mostly working in openapi-generator. However, there are still a few missing features. See the commented out sections of https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/2_0/rust-server/petstore-with-fake-endpoints-models-for-testing.yaml, but in summary:
schema: {type: <something>}
and >0 headers (got a fix - [rust-server] Handle headers correctly #549)isString
set #545 for the fix for the compilation error)file
type? #538)file
type? #538)I suspect the former might be related to the terrible hack I did in
postProcessModels
, whilst the latter 3 seem likely to be related toprocessParam
.EDIT: I have no plans to work on this for the next fortnight, so contributions gratefully welcomed.The text was updated successfully, but these errors were encountered: