-
Notifications
You must be signed in to change notification settings - Fork 0
fix: support of oneOf
#98
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
crates/oapi-codegen/tests/fixtures/oneof_variant_naming.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| openapi: "3.0.3" | ||
| info: | ||
| title: how an inline oneOf member gets its name | ||
| version: "1.0.0" | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| # A scalar member hoists no type, so the position names nothing a reader can | ||
| # use. Each variant takes the name of the type it holds. | ||
| Scalars: | ||
| oneOf: | ||
| - type: string | ||
| - type: integer | ||
| - type: boolean | ||
| # An object member hoists a struct, and the two names must agree. Without an | ||
| # override the position is the only thing that tells the members apart. | ||
| Objects: | ||
| oneOf: | ||
| - type: object | ||
| required: [meow] | ||
| properties: | ||
| meow: | ||
| type: string | ||
| - type: object | ||
| required: [bark] | ||
| properties: | ||
| bark: | ||
| type: string | ||
| # `x-rust-name` on an inline member names the variant and the hoisted type. | ||
| Named: | ||
| oneOf: | ||
| - x-rust-name: Cat | ||
| type: object | ||
| required: [meow] | ||
| properties: | ||
| meow: | ||
| type: string | ||
| - x-rust-name: Dog | ||
| type: object | ||
| required: [bark] | ||
| properties: | ||
| bark: | ||
| type: string | ||
| # A member list that mixes the three cases above. | ||
| Mixed: | ||
| oneOf: | ||
| - type: string | ||
| - type: array | ||
| items: | ||
| type: string | ||
| - x-rust-name: Detail | ||
| type: object | ||
| required: [note] | ||
| properties: | ||
| note: | ||
| type: string |
20 changes: 20 additions & 0 deletions
20
crates/oapi-codegen/tests/fixtures/unsupported_duplicate_union_variant.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| openapi: "3.0.3" | ||
| info: | ||
| title: a oneOf that holds one type twice | ||
| version: "1.0.0" | ||
| paths: {} | ||
| components: | ||
| schemas: | ||
| Cat: | ||
| type: object | ||
| required: [meow] | ||
| properties: | ||
| meow: | ||
| type: string | ||
| # Both members lower to `Cat`. The emitted enum is untagged, so serde reads | ||
| # the variants in order and takes the first that fits. The second variant | ||
| # never matches, and a value built with it comes back as the first. | ||
| Pet: | ||
| oneOf: | ||
| - $ref: "#/components/schemas/Cat" | ||
| - $ref: "#/components/schemas/Cat" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
crates/oapi-codegen/tests/generated/oneof_variant_naming.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Code generated by oapi-codegen-rust. DO NOT EDIT. | ||
| #![allow( | ||
| dead_code, | ||
| clippy::all, | ||
| clippy::pedantic, | ||
| clippy::nursery, | ||
| clippy::restriction, | ||
| reason = "generated code, not first-party source" | ||
| )] | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum Scalars { | ||
| String(String), | ||
| I64(i64), | ||
| Bool(bool), | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum Objects { | ||
| ObjectsVariant0(ObjectsVariant0), | ||
| ObjectsVariant1(ObjectsVariant1), | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum Named { | ||
| Cat(Cat), | ||
| Dog(Dog), | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| #[serde(untagged)] | ||
| pub enum Mixed { | ||
| String(String), | ||
| MixedVariant1(Vec<String>), | ||
| Detail(Detail), | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub struct ObjectsVariant0 { | ||
| pub meow: String, | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub struct ObjectsVariant1 { | ||
| pub bark: String, | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub struct Cat { | ||
| pub meow: String, | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub struct Dog { | ||
| pub bark: String, | ||
| } | ||
|
|
||
| #[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)] | ||
| pub struct Detail { | ||
| pub note: String, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.