Exemple #1
0
def generate(args=None):
    if args is None:
        args = [None]

    endpoint: Endpoint
    for endpoint in ENDPOINT_REGISTRY:
        try:
            SPEC.path(
                path=endpoint.path,
                operations=endpoint.to_operation_dict(),
            )
        except TypeError:
            print(endpoint, file=sys.stderr)
            raise

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(SPEC.to_dict())
    validate_spec(check_dict)

    if args[-1] == '--json':
        output = json.dumps(SPEC.to_dict(), indent=2).rstrip()
    else:
        output = SPEC.to_yaml().rstrip()

    return output
Exemple #2
0
def generate(args=None):
    if args is None:
        args = [None]

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(SPEC.to_dict())
    validate_spec(check_dict)

    if args[-1] == '--json':
        output = json.dumps(SPEC.to_dict(), indent=2).rstrip()
    else:
        output = SPEC.to_yaml().rstrip()

    return output
Exemple #3
0
def generate_data() -> Dict[str, Any]:
    endpoint: Endpoint
    for endpoint in ENDPOINT_REGISTRY:
        SPEC.path(
            path=endpoint.path,
            operations=endpoint.to_operation_dict(),
        )

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(SPEC.to_dict())
    validate_spec(check_dict)
    # NOTE: We want to modify the thing afterwards. The SPEC object would be a global reference
    # which would make modifying the spec very awkward, so we deepcopy again.
    return copy.deepcopy(SPEC.to_dict())
Exemple #4
0
def generate_data(target: EndpointTarget,
                  validate: bool = True) -> Dict[str, Any]:
    endpoint: Endpoint

    methods = ["get", "put", "post", "delete"]

    for endpoint in sorted(ENDPOINT_REGISTRY,
                           key=lambda e:
                           (e.func.__module__, methods.index(e.method))):
        if target in endpoint.blacklist_in:
            continue
        SPEC.path(
            path=endpoint.path,
            operations=endpoint.to_operation_dict(),
        )

    generated_spec = SPEC.to_dict()
    #   return generated_spec
    _add_cookie_auth(generated_spec)
    if not validate:
        return generated_spec

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(generated_spec)
    validate_spec(check_dict)
    # NOTE: We want to modify the thing afterwards. The SPEC object would be a global reference
    # which would make modifying the spec very awkward, so we deepcopy again.
    return generated_spec
Exemple #5
0
def generate_data(target: EndpointTarget, validate: bool = True) -> Dict[str, Any]:
    endpoint: Endpoint

    methods = ["get", "put", "post", "delete"]

    # NOTE
    # This needs to be called on the very first request to create some important configuration
    # files with default values for them to be considered in the OpenAPI schema. If this wouldn't
    # be called, the schema would for example lack certain default tag groups.
    watolib.init_wato_datastructures(with_wato_lock=True)

    for endpoint in sorted(
        ENDPOINT_REGISTRY, key=lambda e: (e.func.__module__, methods.index(e.method))
    ):
        if target in endpoint.blacklist_in:
            continue
        SPEC.path(
            path=endpoint.path,
            operations=endpoint.to_operation_dict(),
        )

    generated_spec = SPEC.to_dict()
    #   return generated_spec
    _add_cookie_auth(generated_spec)
    if not validate:
        return generated_spec

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(generated_spec)
    validate_spec(check_dict)
    # NOTE: We want to modify the thing afterwards. The SPEC object would be a global reference
    # which would make modifying the spec very awkward, so we deepcopy again.
    return generated_spec
Exemple #6
0
def generate(args=None):
    if args is None:
        args = [None]
    # We need to import the endpoints before importing the spec, lest we don't have a guarantee that
    # all endpoints will be registered in the spec as this is done at import-time.
    import cmk.gui.plugins.openapi.endpoints  # pylint: disable=unused-import,unused-variable

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(SPEC.to_dict())
    validate_spec(check_dict)
    if args[-1] == '--json':
        output = json.dumps(SPEC.to_dict(), indent=2).rstrip()
    else:
        output = SPEC.to_yaml().rstrip()

    return output
Exemple #7
0
def generate():
    # We need to import the endpoints before importing the spec, lest we don't have a guarantee that
    # all endpoints will be registered in the spec as this is done at import-time.
    import cmk.gui.plugins.openapi.endpoints  # pylint: disable=unused-import,unused-variable

    # NOTE: deepcopy the dict because validate_spec modifies the SPEC in-place, leaving some
    # internal properties lying around, which leads to an invalid spec-file.
    check_dict = copy.deepcopy(SPEC.to_dict())
    validate_spec(check_dict)
    return SPEC.to_yaml().rstrip()