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

Simplify variable descriptions in api definition #673

Open
ender-null opened this issue Jul 20, 2018 · 2 comments
Open

Simplify variable descriptions in api definition #673

ender-null opened this issue Jul 20, 2018 · 2 comments

Comments

@ender-null
Copy link

Is there any way to simplify this output?

"outputs": {
    "format": "JSON (Javascript Serialized Object Notion) pretty printed and indented",
    "content_type": "application/json; charset=utf-8"
},
"inputs": {
    "number": {
        "type": "int(x=0) -> integer\nint(x, base=10) -> integer\n\nConvert a number or string to an integer, or return 0 if no arguments\nare given.  If x is a number, return x.__int__().  For floating point\nnumbers, this truncates towards zero.\n\nIf x is not a number or if base is given, then x must be a string,\nbytes, or bytearray instance representing an integer literal in the\ngiven base.  The literal can be preceded by '+' or '-' and be surrounded\nby whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.\nBase 0 means to interpret the base from the string as an integer literal.\n>>> int('0b100', base=0)\n4"
    },
    "source": {
        "type": "Basic text / string value"
    }
}

Something like this:

"outputs": {
    "format": "JSON",
    "content_type": "application/json; charset=utf-8"
},
"inputs": {
    "number": {
        "type": "int"
    },
    "source": {
        "type": "string"
    }
}
@hvgab
Copy link

hvgab commented Sep 29, 2018

See "Extending and creating new hug types" in Type annotations in hug and maybe take a look in the types source for more examples.
If you just want to modify the docs

If you simply want to perform additional conversion after a base type is finished, or modify its documentation, the most succinct way is the hug.type decorator:

import hug

@hug.type(extend=hug.types.number)
def the_answer(value):
    """My new documentation"""
    if value != 42:
        raise ValueError('Value is not the answer to everything.')

@akaihola
Copy link
Contributor

akaihola commented Jan 8, 2019

I've used this method:

import hug

class BeginTimestamp(hug.types.Text):
    """ISO timestamp to start from"""

begin_timestamp = BeginTimestamp()

@hug.cli()
def foo(begin: begin_timestamp):
    ...

if __name__ == '__main__':
    foo.interface.cli()
$ python test.py -h
usage: test.py [-h] begin

positional arguments:
  begin       ISO timestamp to start from

optional arguments:
  -h, --help  show this help message and exit

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

No branches or pull requests

3 participants