Skip to content
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

[BUG] Code generation is broken for oneOf types (Rust Server) #17210

Open
5 of 6 tasks
mirosval opened this issue Nov 28, 2023 · 1 comment
Open
5 of 6 tasks

[BUG] Code generation is broken for oneOf types (Rust Server) #17210

mirosval opened this issue Nov 28, 2023 · 1 comment

Comments

@mirosval
Copy link

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

I had some code that used to work on 5.4.0 and now it doesn't. I traced the issue down to some change in the implementation of the usage of oneOf, where previously swagger::OneOf<A,B> was generated, now a new model is generated, but that new model is empty.

https://gist.github.com/mirosval/433308deb22727e3b1102fb58f3a6652

openapi-generator version

Works on 5.4.0 and does not since 6.0.

OpenAPI declaration file content or url

I'll provide a full gist, but shortly these are the interesting bits:

openapi: 3.0.3

...

components:
  schemas:
    Test:
      type: object
      properties:
        something:
          oneOf:
            - type: string
            - type: integer

Before:

    pub something: Option<swagger::OneOf2<String,i32>>,

After:

    pub something: Option<models::TestSomething>,

...

#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, validator::Validate)]
#[cfg_attr(feature = "conversion", derive(frunk::LabelledGeneric))]
pub struct TestSomething {
}
Generation Details
generate-710:
	docker run --rm \
		-v $(PWD):/local openapitools/openapi-generator-cli:v7.1.0 generate \
		-i /local/test.yaml \
		--generator-name rust-server \
		--output /local/openapi \
		--global-property models,modelDocs=false,supportingFiles
	mv openapi/src/models.rs test-710.rs
	rm -rf openapi
Steps to reproduce

See the Gist and then make generate-540 generate-710 generate-latest

Related issues/PRs

This looks like it might be related:

#13538

Suggest a fix

It seems that generating intermediate models for nested properties is a good idea, just that there should probably be some heuristic to detect when the nested type is a oneOf and use a different path.

@c-thiel
Copy link

c-thiel commented Apr 7, 2024

While #13970 and #17915 have fixed it for the client side, rust-server is still broken for me. #9497 also only faces client-side code from what I can see.

@mirosval should we change this issue title to include rust-server specifically?

@mirosval mirosval changed the title [BUG] Code generation is broken for oneOf types [BUG] Code generation is broken for oneOf types (Rust Server) Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants