datamodel-code-generator icon indicating copy to clipboard operation
datamodel-code-generator copied to clipboard

Split long descriptions on multiple lines

Open gaborbernat opened this issue 4 years ago • 4 comments
trafficstars

Description strings are currently injected as a single line, which is troublesome for long strings. We should ideally split them across multiple lines in such cases:

class Cfg(BaseModel):
    b: Optional[str] = Field(
        None,
        description="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut arcu velit, fringilla nec enim dictum, luctus  bibendum dui. Maecenas eget ex ac velit auctor mollis. Integer enim ex, pharetra sed sapien id, tincidunt fermentum eros.",
    )
class Cfg(BaseModel):
    b: Optional[str] = Field(
        None,
        description=(
            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut arcu velit, fringilla nec enim dictum, luctus "
            "bibendum dui. Maecenas eget ex ac velit auctor mollis. Integer enim ex, pharetra sed sapien id, tincidunt"
            " fermentum eros."
        ),
    )

For this the user should perhaps pass some target line length 👍

gaborbernat avatar Jul 02 '21 08:07 gaborbernat

@gaborbernat Thank you for your great suggestion. OK, I will add the CLI Option.

koxudaxi avatar Jul 04 '21 14:07 koxudaxi

@gaborbernat I have forgotten to write this comment. I added this feature as --wrap-string-literal to version 0.11.11

koxudaxi avatar Aug 27 '21 16:08 koxudaxi

How come the generated strings are now quoted with ' instead of "?

gaborbernat avatar Aug 31 '21 10:08 gaborbernat

@gaborbernat I'm sorry for my late reply 🙇

How come the generated strings are now quoted with ' instead of "?

I think the problem is related skip-string-normalization option in toml. Could you show me your pyproject.toml?

koxudaxi avatar Sep 22 '21 13:09 koxudaxi