question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use schema description to populate field docstring

See original GitHub issue

Similar to #274 I would like to add docstrings for each field based on the jsonschema description. Purpose is for my IDE (VSCode) to pick up the description and show in mouse-over

{
  "type": "object",
  "properties": {
    "mykey": {
      "type": "string",
      "description": "Field description"
    }
  }
}

Would lead to:

class Model(BaseModel):
    mykey: Optional[str] = Field(None, description='Field description')
    """
    Field description
    """

Maybe I am missing something else that could solve this, so I welcome alternative solutions.

I can try to submit a PR for this, if you agree that it would be useful.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Dominic-Walthercommented, Nov 12, 2022

Went ahead and implemented it on my fork. Feedback is more than welcome, I’m not too familiar with this project.

Note that the description appears in either the Field() statement or the docstring, unlike in the proposal above.

1reaction
ClausHolbechAristacommented, Oct 6, 2022

I am using the command line option --custom-template-dir <path>. I found it a bit strange that I had to also copy the Config.jinja2 file to that path, since it is included in the base template, but it is no big deal. I think it is something about search path not being passed along to jinja.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Schemas - Django REST framework
The schema generation in REST framework uses docstrings to automatically populate descriptions in the schema document. These descriptions will be based on: The ......
Read more >
Specify types with docstrings | PyCharm Documentation
Information about the arguments and return values obtained during the debugging session will be used to pre-populate type annotations in a docstring.
Read more >
GraphQL schema basics
This schema defines a hierarchy of types with fields that are populated from your back-end data stores. The schema also specifies exactly which...
Read more >
datamodel-code-generator - GitHub Pages
This code generator creates pydantic model from an openapi file and others.
Read more >
apispec - Read the Docs
Our application will have a marshmallow Schema for gists. from marshmallow import Schema, fields class GistParameter(Schema):.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found