Skip to content

Include parameter name in JSON Schema error path on unmarshalling #246

Closed

Description

@playpauseandstop

Hi,

I've run into the problem, when I'm not able to show which invalid parameter raised an InvalidSchemaValue.

As InvalidSchemaValue contains a list of schema_errors (List[JsonSchemaValidationError]) I expect to have relative_path / absoulte_path filled for its items. But in reality all items have empty path / relative_path attributes (and absolute_path property).

I've managed to fix this by manually add parameter name as JSON Schem error path as,

        try:
            return unmarshaller(value)
        except InvalidSchemaValue as err:
            # Modify invalid schema validation errors to include parameter name
            if isinstance(param_or_media_type, Parameter):
                param_name = param_or_media_type.name

                for schema_error in err.schema_errors:
                    schema_error.path = schema_error.relative_path = deque(
                        [param_name]
                    )

            raise err

instead of plain,

        return unmarshaller(value)

But would like to have path filled by openapi_core instead.


More details in playpauseandstop/rororo#53

Activity

  1. playpauseandstop commented on Apr 23, 2020

    @playpauseandstop
    Author

    Similar issue with CastError

    It doesn't contain name attrib and it is impossible to find out which parameter name resulted casting error

  2. added
    area/castingIndicates an issue on casting area.
    area/unmarshallingIndicates an issue on unmarshalling area.
    on Jul 20, 2020
  3. jgod commented on Dec 24, 2020

    @jgod
    Contributor

    Yeah this is a must

  4. jgod commented on Dec 24, 2020

    @jgod
    Contributor

    By the way, do you know how to determine the location (path, body, header, etc.) where the erroring parameter is located? It's not in the error object, either.

  5. osynge commented on Nov 1, 2021

    @osynge

    I feel this is resolved please see my answer to #241

  6. jyggen commented on Sep 26, 2022

    @jyggen
    Contributor

    I don't think this is resolved. I need to differentiate between schema errors in the request body and in the request parameters (e.g. query string) and there seems to be no info about this on the exception intself nor the schema errors it contains.

  7. wickedest commented on Jan 11, 2023

    @wickedest
    Contributor

    I don't know the code base too well, but I was poking around. Couldn't the parameter name just be mapped to the exception here?

                try:
                    value = self._get_parameter(param, request)
                except MissingParameter:
                    continue
                except (
                    MissingRequiredParameter,
                    DeserializeError,
                    CastError,
                    ValidateError,
                    UnmarshalError,
                ) as exc:
                    errors.append(exc)
                    continue
                else:
                    location = getattr(parameters, param_location)
                    location[param_name] = value
  8. p1c2u commented on Jan 12, 2023

    @p1c2u
    Collaborator

    Errors are definitely something to improve. However this will be a breaking change and I was waiting for this until I refactor validators. I will add errors refactor to the 0.17 roadmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/castingIndicates an issue on casting area.area/unmarshallingIndicates an issue on unmarshalling area.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions