Bug Report Checklist
Description
For endpoints with request bodies of type form (e.g. application/x-www-form-urlencoded) and enum properties, the generated Rust client invokes format!("{:?}", param_foo) where param_foo is the model generated in models.rs for the enum property. {:?} is the debug formatter, which uses the derived impl Debug on the enum model, which resolves to the name of the enum variant (as per the rust docs) - however, we should instead be serializing this with the impl Display on the enum model, which produces the defined allowable values from the API definition. This incorrect serialization does not obey the OpenAPI spec and will cause any server policing the value of the enum to reject requests created by this client.
openapi-generator version
Present in all 7.x releases
OpenAPI declaration file content or url
openapi: "3.0.3"
info:
title: Enum Form Parameter Example
version: "1.0.0"
paths:
/authentication-endpoint:
post:
operationId: authenticate
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
target_resource:
type: string
enum:
- resource_one
- resource_two
description: "Resource to authenticate for - must be one of `resource_one` or `resource_two`"
responses:
'200':
description: Authorization successful
content:
application/json:
schema:
type: object
properties:
token:
type: string
Generation Details
No specific generation is required.
Steps to reproduce
- Generate Rust bindings for the above spec with
rust-server
- Open generated
src/client/mod.rs bindings, find authenticate method
- Observe the serialization of the enum form:
- Call this method and note that
target_resource is supplied as ResourceOne or ResourceTwo, not their correct serializations
Expected: it should be set to the serialized version, resource_one or resource_two.
Suggest a fix
The RustServerCodegen.java file should check if the parameter is an enum and set x-format-string to {} instead of {:?} - this is safe because all models impl Display and all enums have allowedValues in their impl Display.
Bug Report Checklist
Description
For endpoints with request bodies of type form (e.g.
application/x-www-form-urlencoded) andenumproperties, the generated Rust client invokesformat!("{:?}", param_foo)whereparam_foois the model generated inmodels.rsfor theenumproperty.{:?}is the debug formatter, which uses the derivedimpl Debugon the enum model, which resolves to the name of the enum variant (as per the rust docs) - however, we should instead be serializing this with theimpl Displayon the enum model, which produces the defined allowable values from the API definition. This incorrect serialization does not obey the OpenAPI spec and will cause any server policing the value of the enum to reject requests created by this client.openapi-generator version
Present in all 7.x releases
OpenAPI declaration file content or url
Generation Details
No specific generation is required.
Steps to reproduce
rust-serversrc/client/mod.rsbindings, findauthenticatemethodtarget_resourceis supplied asResourceOneorResourceTwo, not their correct serializationsExpected: it should be set to the serialized version,
resource_oneorresource_two.Suggest a fix
The RustServerCodegen.java file should check if the parameter is an enum and set
x-format-stringto{}instead of{:?}- this is safe because all modelsimpl Displayand all enums haveallowedValuesin theirimpl Display.