PokeAPI / pokeapi

The Pokémon API
https://pokeapi.co
BSD 3-Clause "New" or "Revised" License
4.15k stars 935 forks source link

Query q OAS descriptor #1078

Closed Naramsim closed 4 months ago

Naramsim commented 5 months ago

@Indyandie could you review this PR? Thanks!

Indyandie commented 4 months ago

Howdy @Naramsim! :open_mouth: I wrote a similar thing yesterday.

It seems that nothing is being generated from this change when I run make openapi-generate.

However @ryu-0729's PR #1050, has a solution. see api.py ln 75

#...

retrieve_path_parameter = OpenApiParameter(
    name="id",
    description="This parameter can be a string or an integer.",
    location=OpenApiParameter.PATH,
    type=OpenApiTypes.STR,
    required=True,
)

q_query_string_parameter = OpenApiParameter(
    name="q",
    description="> Only available locally and not at [pokeapi.co](https://pokeapi.co/docs/v2)\nCase-insensitive query applied on the `name` property. ",
    location=OpenApiParameter.QUERY,
    type=OpenApiTypes.STR,
)

#...

@extend_schema(
    description="Pokémon are the creatures that inhabit the world of the Pokémon games. They can be caught using Pokéballs and trained by battling with other Pokémon. Each Pokémon belongs to a specific species but may take on a variant which makes it differ from other Pokémon of the same species, such as base stats, available abilities and typings. See [Bulbapedia](http://bulbapedia.bulbagarden.net/wiki/Pok%C3%A9mon_(species)) for greater detail.",
    summary="Get pokemon",
    tags=["pokemon"],
)
@extend_schema_view(
    list=extend_schema(summary="List pokemon", parameters=[q_query_string_parameter]),
)
class PokemonResource(PokeapiCommonViewset):
    queryset = Pokemon.objects.all()
    serializer_class = PokemonDetailSerializer
    list_serializer_class = PokemonSummarySerializer

    @extend_schema(parameters=[retrieve_path_parameter])
    def retrieve(self, request, pk=None):
        return super().retrieve(request, pk)

#...
Indyandie commented 4 months ago

sorry about the tint I have night shift on

2024-05-09T01:06:43CDT-img

Naramsim commented 4 months ago

If you have the same feature but working, you can submit your PR and I'll close this one

Indyandie commented 4 months ago

Yeah, I'll try to post a PR today or tomorrow.

@Naramsim does the 'q' param apply to all list endpoints?

Naramsim commented 4 months ago

@Naramsim does the 'q' param apply to all list endpoints?

Yes it seems so! It would be nice to test it on unnamed resources, those that only support querying by ID.