[BUG] [rust] An empty enum variant becomes invalid code since v6.1.0
Created by: siketyan
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Enum variants can have an "empty" variant, and in code generation it is transformed into some named variant like "SomeEnum::Empty" or something. Until v6.0.1, I confirmed the variant becomes valid code including the transformation for empty variants. Now since v6.1.0, the empty variant started to become invalid code without any transformation for that. See "generation details" section for details of code generation results.
openapi-generator version
It works < 6.1.0, and not working >= 6.1.0. I reproduced the issue on v6.1.0, and the latest using Docker image.
OpenAPI declaration file content or url
openapi: 3.0.0
servers:
- url: 'http://example.com/'
info:
version: 1.0.0
title: Example
paths:
/pet:
post:
summary: Add a new pet to the store
operationId: addPet
responses:
'200':
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
requestBody:
$ref: '#/components/requestBodies/Pet'
components:
requestBodies:
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
schemas:
Pet:
title: a Pet
description: A pet for sale in the pet store
type: object
required:
- name
properties:
name:
type: string
example: doggie
status:
type: string
description: pet status in the store
enum:
- "" # This is an "empty" enum variant
- available
- pending
- sold
Generation Details
docker run --rm -v $(pwd)/petstore.yaml:/petstore.yaml:ro -v $(pwd)/gen:/gen openapitools/openapi-generator-cli:v6.0.1 generate -g rust -i /petstore.yaml -o /gen
generates:
/// pet status in the store
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
#[serde(rename = "")]
Empty,
#[serde(rename = "available")]
Available,
#[serde(rename = "pending")]
Pending,
#[serde(rename = "sold")]
Sold,
}
But,
docker run --rm -v $(pwd)/petstore.yaml:/petstore.yaml:ro -v $(pwd)/gen:/gen openapitools/openapi-generator-cli:v6.1.0 generate -g rust -i /petstore.yaml -o /gen
generates:
/// pet status in the store
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Status {
#[serde(rename = "")]
,
#[serde(rename = "available")]
Available,
#[serde(rename = "pending")]
Pending,
#[serde(rename = "sold")]
Sold,
}
that is invalid Rust code of course.
Steps to reproduce
See "generation details" section.
Related issues/PRs
#13231 may cause this issue (I don't know details of the changes, so this is just my expectation).