swift-openapi-generator icon indicating copy to clipboard operation
swift-openapi-generator copied to clipboard

Support default values for schema properties

Open salminalex opened this issue 2 years ago • 3 comments

The generator skips the default values for Components.Schemas. It would be nice to have a default value for the property itself and in the initializer. I made an example:

Spec example: Screenshot 2023-06-13 at 20 22 25

Current: Screenshot 2023-06-13 at 20 20 58

Desired: Screenshot 2023-06-13 at 20 21 52

salminalex avatar Jun 13 '23 17:06 salminalex

Thanks for filing it – you're right, default values are not generated at the moment, but it's a feature we'd like to do, and would gladly accept a pull request for 🙂 Let me slightly rename and label this issue, to properly track it.

A good starting point for anyone contributing this feature would be to add the default value to https://github.com/apple/swift-openapi-generator/blob/main/Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations/translateObjectStruct.swift#L62, and work from there.

czechboy0 avatar Jun 13 '23 17:06 czechboy0