Skip to content

Ordering feature - expose ordering_fields as OpenAPI Types #284

@csoare7

Description

@csoare7

Hi there, is there a way to expose the ordering fields as openapi types instead of a string as of currently?
Would help with the integration with a typescript frontend.

What we ended up doing, if it helps anyone:

from typing import Literal, get_args

from ninja import Schema
from ninja_extra.ordering import Ordering, ordering

class MyOrdering(Schema):
    id: Literal["id"]

@ordering(Ordering, ordering_fields=[
    get_args(annotation)[0]
    for annotation in MyOrdering.__annotations__.values()
])
def list_objects(...):
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions