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

Single fielded oneof #118

Conversation

dfithian
Copy link
Contributor

@dfithian dfithian commented Nov 9, 2024

@joel-bach

Not sure if this is the best way. At work using Rust's aide package we'll have a lot of enums like this:

enum MyType {
    Left(LeftType)
    Right(RightType)
}

Which generate this:

MyType:
  oneOf:
    - type: object
      required:
        - left
      properties:
        left:
          $ref: '#/components/schemas/LeftType'
    - type: object
      required:
        - right
      properties:
        right:
          $ref: '#/components/schemas/RightType'

Using this generator it tends to generate enumerations with a lot of OneofN suffixes, but with this feature it'll generate them with Left and Right suffixes instead.

…variants after those fields instead of with numbers. Fix up some utilities for consistency, and add a Field type instead of recomputing property names.
@joel-bach
Copy link
Member

Hey @dfithian

Generally, it is hard to give these types good names generically, so I do not see a way around some special casing (which we already have in place with the fixed value schemas). Your case looks reasonable to me, so I think this is an improvement as the indexed OneOf types are nearly useless. I even wonder if we should enable the option by default as it should only improve existing cases (having the flag though is good so peeps can revert to the previous version if needed).

At least I'd be interested to see how the changes behave in the golden tests. Since you'll have to update the golden result anyway, would you mind also adding the flag here?

goldenTestCode = generateCode { fileName = "z_complex_self_made_example.yml"; extraFlags = [ "--output-all-schemas" ]; };

Could you also add a single field object schema outside a oneOf case to make it visible that the new code does not affect that?

Thank you!

@dfithian
Copy link
Contributor Author

I am happy to make it the default behavior. Would you like me to increment the version to 0.2.0.0 or would you prefer to handle any version rev?

@joel-bach
Copy link
Member

I am happy to make it the default behavior. Would you like me to increment the version to 0.2.0.0 or would you prefer to handle any version rev?

Yeah, let's increase the version 👍

@dfithian
Copy link
Contributor Author

Alright, tests are passing!

@joel-bach
Copy link
Member

Nice work, thank you @dfithian !

@joel-bach joel-bach merged commit 0eb15be into Haskell-OpenAPI-Code-Generator:master Nov 13, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants