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

fix: get response example return type #792

Merged
merged 1 commit into from
Aug 23, 2023

Conversation

mskri
Copy link
Contributor

@mskri mskri commented Aug 23, 2023

🧰 Changes

Hey 👋 I was using the library and noticed that the getResponseExamples() declares to use incorrect type. The returned data is not in the shape the type definition claims.

The function casts the returned type incorrectly in L68. The used type is shaped like

type ResponseExamples = {
  mediaTypes: Record<string, RMOAS.MediaTypeObject>;
  status: string;
}[];

but the code actually transforms it into type shaped like

interface MediaTypeExample {
  description?: string;
  summary?: string;
  title?: string;
  value: unknown;
}

The actually used type is defined in L28 which is then returned from the getResponseExamples() in L56.

The type is also missing onlyHeaders?: boolean which is added conditionally in L57.

Taking a look at the tests
for getResponseExamples() reveals that the mediaTypes type is expected to be Record<string, MediaTypeExample[]> instead of Record<string, RMOAS.MediaTypeObject>. The used tests data doesn't conform to RMOAS.MediaTypeObject's shape.

🧬 QA & Testing

Since the change is about the types there wasn't any changes to the existing tests. The tests ran green before the change and after change.

@erunion erunion added the bug Something isn't working label Aug 23, 2023
Copy link
Member

@erunion erunion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh great catch! thank you so much.

@erunion erunion merged commit 2a170d3 into readmeio:main Aug 23, 2023
@erunion
Copy link
Member

erunion commented Aug 23, 2023

Published to 20.10.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants