Skip to content

Improve response_fields and sort query parameter regexes #808

@ml-evs

Description

@ml-evs

Currently our regexes for response_fields and sort allow e.g. response_fields="chemical_formula_anonymous" through, where the field is treated as the quoted string '"chemical_formula_anonymous"'.

This is not ideal and can be fixed in the model regexes directly (which we should then push upstream for v1.0.1 of the spec).

response_fields: str = Query(
"",
description="A comma-delimited set of fields to be provided in the output.\nIf provided, these fields MUST be returned along with the REQUIRED fields.\nOther OPTIONAL fields MUST NOT be returned when this parameter is present.\nExample: `http://example.com/v1/structures?response_fields=last_modified,nsites`",
regex=r"([a-z_][a-z_0-9]*(,[a-z_][a-z_0-9]*)*)?",
),
sort: str = Query(
"",
description='If supporting sortable queries, an implementation MUST use the `sort` query parameter with format as specified by [JSON API 1.0](https://jsonapi.org/format/1.0/#fetching-sorting).\n\nAn implementation MAY support multiple sort fields for a single query.\nIf it does, it again MUST conform to the JSON API 1.0 specification.\n\nIf an implementation supports sorting for an entry listing endpoint, then the `/info/<entries>` endpoint MUST include, for each field name `<fieldname>` in its `data.properties.<fieldname>` response value that can be used for sorting, the key `sortable` with value `true`.\nIf a field name under an entry listing endpoint supporting sorting cannot be used for sorting, the server MUST either leave out the `sortable` key or set it equal to `false` for the specific field name.\nThe set of field names, with `sortable` equal to `true` are allowed to be used in the "sort fields" list according to its definition in the JSON API 1.0 specification.\nThe field `sortable` is in addition to each property description and other OPTIONAL fields.\nAn example is shown in the section Entry Listing Info Endpoints.',
regex=r"([a-z_][a-z_0-9]*(,[a-z_][a-z_0-9]*)*)?",
),

Metadata

Metadata

Assignees

No one assigned

    Labels

    ergonomicsFeatures that improve the usability of the packagegood first issueGood for newcomersmodelsFor issues related to the pydantic models directlypriority/lowIssue or PR with a consensus of low priorityschemaConcerns the schema modelssuggestions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions