Exemplo n.º 1
0
def main():
    template: Template = None
    with open('schemas/python-templates/data-class.jinja2') as t:
        template = template or Template(
            t.read(), lstrip_blocks=True, trim_blocks=True)

    for schema in load_schemas():
        for model in schema.models.values():
            model.resources, model.methods = {}, {}
            rename_properties(model)

            for prop in model.properties.values():
                improve_doc_string(prop)

        output = template.render(models=schema.models,
                                 imports=get_imports_to_types(schema))

        with open(f'stepik/api/{schema.py_module_name}.py', 'w') as out:
            out.write(output)
Exemplo n.º 2
0
def put(token, url, data=None) -> List[str]:
    api_url = f'https://{server}/api/{url}'
    res = requests.put(api_url, headers={'Authorization': 'Bearer ' + token}, json=data or {})
    return res.json() \
        if res.headers['Content-Type'] == 'application/json' \
        else {'detail': f'{res.status_code} {res.reason}'}


if __name__ == '__main__':
    from schemas.schema import load_schemas
    from config import id, secret

    token = auth(id, secret)
    stepik = Stepik(id, secret)
    schemas = load_schemas()

    # 1. If resource supports POST & PUT method
    # then we can take all parameters from create() method
    # and put them to update() method

    # 2. What if resource doesn't support POST request to base?
    # but has GET, GET by PK
    # ... todo

    pr_schema = [s for s in load_schemas() if s.resourcePath == '/api/profiles'][0]
    # for schema in schemas:
    pr = stepik.profiles.iterate()


    # for p in les_schema.model.properties.values():
Exemplo n.º 3
0
        POST_BASE=('POST' in base_route) and (post_base_params is not None),
        POST_BASE_PARAMS=post_base_params,
        POST_BASE_OTHER_PARAMS=other_post_base_params,
    )

    return output


if __name__ == '__main__':
    with open(f'schemas/api-refined/metadata/ordering_fields.json') as f:
        ordering_fields = json.load(f)
    with open(f'schemas/api-refined/metadata/required_fields.post.base.json'
              ) as f:
        post_required_fields = json.load(f)
    with open('schemas/python-templates/list-of-models.jinja2') as t:
        template_with_model = Template(t.read(),
                                       lstrip_blocks=True,
                                       trim_blocks=True)
    with open('schemas/python-templates/list-of-objects.jinja2') as t:
        template_with_object = Template(t.read(),
                                        lstrip_blocks=True,
                                        trim_blocks=True)

    build_data_classes()

    for schema in load_schemas():
        output = gen_with_model(
            schema) if schema.model else ''  # gen_with_object(schema)
        with open(f'stepik/api/{schema.py_module_name}.py', 'a') as f:
            f.write(output)
Exemplo n.º 4
0
def models() -> Dict[str, Model]:
    """Return dict of all models"""
    return {
        m.id: m
        for schema in load_schemas() for m in schema.models.values()
    }
    return token


def get(token, url) -> List[str]:
    api_url = f'https://{server}/api/{url}'
    res = requests.options(api_url,
                           headers={'Authorization': 'Bearer ' + token})
    return json.dumps(res.json(), indent=2)


if __name__ == '__main__':
    from schemas.schema import load_schemas
    from config import id, secret

    token = auth(id, secret)
    schemas = load_schemas()

    for schema in schemas:
        if schema.resources_name != 'views':
            continue

        print(schema.resourcePath, get(token, schema.resources_name))
        break

    # routes_pk = {schema.resourcePath: get(token, f'{schema.resources_name}/0') for schema in schemas}

    # dir = 'schemas/api-refined/metadata'
    # pathlib.Path(dir).mkdir(parents=True, exist_ok=True)
    #
    # with open(f'{dir}/base.methods.json', 'w') as f:
    #     json.dump(routes, f, indent=2)