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

Add Default derive #132

Closed
wants to merge 1 commit into from
Closed

Conversation

jayvdb
Copy link
Contributor

@jayvdb jayvdb commented Nov 9, 2022

This adds Default to the base derive list, excluding enums where it requires a nightly feature.
This allows the generated types to be used by other frameworks that expect models to have Default.

@ahl
Copy link
Collaborator

ahl commented Nov 9, 2022

I don't think this is going to work in a variety of cases, for example if a struct contains a generated enum. I'm working on #131 which might be applicable for your use case. Will that work for the situation you have in mind?

@jayvdb
Copy link
Contributor Author

jayvdb commented Nov 9, 2022

#131 looks like it will be helpful. I'll try out your PR to see what, if anything, is missing to solve my use case. Because Default cant be applied to all types on stable, I think it needs to be added to the base set with appropriate logic to avoid the cases it wont work yet. Structs containing enums is one I didn't encounter for my use case, odd because I have a fairly large set of complex models - but it does sound like it would be a problem.

@ahl
Copy link
Collaborator

ahl commented Nov 15, 2022

I'm going to close this, but if it turns out that #131 is insufficient, then I'd be happy to consider how to address your requirements.

@ahl ahl closed this Nov 15, 2022
@jayvdb
Copy link
Contributor Author

jayvdb commented Jan 3, 2023

@ahl, IMO #131 is insufficient. I want to add Default to all generated structs (see note below). Default is listed as one of the traits which should be implemented. c.f. Rust for Rustaceans, Chapter 3 "The next set of nearly universal traits you should implement is Clone and Default." If I was to use #131, I would need to explicitly list every single model in the input OpenAPI spec to add Default to it.

Note: we can't add Default to enums unless we can choose one to be the default value. I am happy to work on adding Default to enums also, next, as that is also very useful.

@jayvdb
Copy link
Contributor Author

jayvdb commented Jan 30, 2023

I am now a bit wiser, and believe #184 is roughly the missing piece of the puzzle.

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