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.

[FEATURE] parameter documentation

See original GitHub issue

The problem

I cannot add descriptions of parameters in OpenAPI documentation. (the specification by OpenAPI)

E.g.,

@app.get('/')
def get(param1: str, param2: int):
    ... do something

Here, there is no way to put descriptions of what param1 and param2 do.

Possible solutions

I can’t think of a clean solution. FastAPI is tightly using Python type check system for the documentation, which is a good thing, so we cannot easily add information to each parameter. Here are some possible solutions.

  1. Parse docstring and embed the corresponding contents to parameter description. For example
@app.get('/')
def get(param1: str, param2: int):
    """
    - **param1**: param1 is doing the job1.
    - **param2**: param2 is doing the job2.
    """
    ... do something

The descriptions could be added to the specification of the parameters.

  1. Use macro in comments. For example,
@app.get('/')
def get(param1: str,  # %FASTAPI%param1 is doing the job1.
        param2: int,  # %FASTAPI%param2 is doing the job2.
       ):
    ... do something
  1. Based on @phy25’s comments, obviously Field could be supported at path, query and form parameters.

Please do let me know if I missed an existing feature for this. I am trying to switch from Flask to FastAPI for my basic web framework in Python, and most of the things look great so far. Thanks for the great project!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
maresbcommented, Aug 22, 2020

Summary of the above discussion.

The solution to

AttributeError: 'FieldInfo' object has no attribute 'in_'

when you have a query parameter like

param1: float = Field(None, description='This is doing something.'),

is to do

from fastapi import Query

and then change the above line to

param1: float = Query(None, description='This is doing something.'),

Here is the relevant documentation.

4reactions
jbkohcommented, Feb 20, 2020

Hi @phy25 When I use

param1: float = Field(None, description='This is doing something.'),

It produces an error as

AttributeError: 'FieldInfo' object has no attribute 'in_'

at

fastapi/dependencies/utils.py", line 401, in add_param_to_fields
    if field_info.in_ == params.ParamTypes.path:

Would it be a bug?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Parameter Metadata Types and Custom Objects
Feature parameters are represented as Metadata API types in your packaging org, as records of custom objects in your License Management Org, and...
Read more >
Advanced Feature Parameters (DriveWorks Documentation)
To capture Advanced Feature Parameters a feature must already be captured (see Dimensions and Features):. Open the model which has the feature already...
Read more >
How to document a method with parameter(s)? - Stack Overflow
To paraphrase an example from the Sphinx documentation as a Python snippet: ... formatted HTML docs for your parameters with their 'signatures' feature....
Read more >
Model Rules Advanced Feature Parameter Rules - Overview
DriveWorks has the ability to drive advanced feature parameters of a large number of features. This topic outlines how to apply rules to...
Read more >
Use JSDoc: @param
The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of...
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