oxidecomputer / oxidecomputer/progenitor
Nullable enum causes progenitor to generator both enum and newtype with same name
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 136
- Avg merge
- 8h 36m
- Merged PRs (30d)
- 14
Description
Let's say we have the following example spec:
{
"openapi": "3.0.3",
"info": {
"title": "Example",
"version": "0.0.1",
"description": "Example",
"contact": {
"name": "Example",
"url": "https://example.com"
}
},
"components": {
"schemas": {
"ExampleEnum": {
"type": "string",
"nullable": true,
"title": "ExampleEnum",
"description": "An example enum",
"enum": [
"test",
null
]
}
}
},
"paths": {}
}
When running progenitor using the binary, the following is generated:
pub mod types {
use serde::{Deserialize, Serialize};
#[doc = "An example enum"]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ExampleEnum(pub Option<ExampleEnum>);
impl std::ops::Deref for ExampleEnum {
type Target = Option<ExampleEnum>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[doc = "An example enum"]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)]
pub enum ExampleEnum {
#[serde(rename = "test")]
Test,
}
impl ToString for ExampleEnum {
fn to_string(&self) -> String {
match *self {
ExampleEnum::Test => "test".to_string(),
}
}
}
}
Notice that the newtype has the same name as the enum, conflicting with its implementation. I encountered this when working with the plaid open api spec, but I'm not sure if it's generally considered a valid case or not.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the progenitor binary and the provided OpenAPI JSON spec, then inspect how the nullable ExampleEnum schema becomes the generated types module. Reproduce the duplicate Rust definitions and verify that the generated output no longer declares conflicting types with the same name and compiles successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100