Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api client types and documentation #2138

Open
aulneau opened this issue Oct 23, 2024 · 2 comments
Open

api client types and documentation #2138

aulneau opened this issue Oct 23, 2024 · 2 comments
Assignees

Comments

@aulneau
Copy link
Contributor

aulneau commented Oct 23, 2024

Hey all :)

The new openapi-fetch based client is pretty hard and confusing to use, could you add some basic documentation? 🙏

Additionally, I'm having a really hard time getting types to work correctly, I have to wrangle them pretty explicitly:

Image
Image

Let me know if I'm missing anything or doing this incorrectly btw!

Thanks!!

@aryzing
Copy link

aryzing commented Nov 5, 2024

I'm with you @aulneau. I even created another API client just to provide myself with a friendlier API.

Perhaps it would be worthwhile to look into trpc or Elysia for the Stacks API. Elysia can also use TypeBox, supports typing of both params and body, and has OpenAPI plugins.

By inferring client types directly from the API definition, these tools are able to provide great DX. No need to wrangle a typed client together from the OpenAPI spec of the original typed API definition.

@zone117x
Copy link
Member

zone117x commented Nov 7, 2024

Hi @aulneau, the error schema isn't defined for many of the routes which is why you're seeing the error: never type issue. The route definition here needs a status 4xx response schema defined:

response: {
200: Type.Object(
{
names: Type.Array(
Type.String({
examples: ['muneeb.id'],
})
),
},
{
title: 'BnsNamesOwnByAddressResponse',
description: 'Retrieves a list of names owned by the address provided.',
}
),
},

For now you can check the request status like:

Image

Here's an example of a route with correct error status schemas defined:

response: {
200: Type.Object({
found: Type.Literal(true),
result: SearchResultSchema,
}),
404: Type.Object({
found: Type.Literal(false),
result: Type.Object({
entity_type: Type.Enum(SearchResultType),
}),
error: Type.String(),
}),
},

Image

@zone117x zone117x moved this from 🆕 New to 👀 In Review in API Board Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In Review
Development

No branches or pull requests

4 participants