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

Support response schemas #72

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.local-sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
REACT_APP_BUNGIE_CLIENT_ID=...
REACT_APP_OAUTH_CLIENT_ID=...
REACT_APP_OAUTH_CLIENT_SECRET=...
REACT_APP_API_KEY=...
HTTPS=true
PORT=4000
13 changes: 10 additions & 3 deletions src/lib/apiSchemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export function getReferencedSchema(ref: string) {

let found:
| OpenAPIV3.ReferenceObject
| OpenAPIV3.ArraySchemaObject
| OpenAPIV3.NonArraySchemaObject
| OpenAPIV3.SchemaObject
| OpenAPIV3.ResponseObject
| undefined = apiSpec.components?.schemas?.[getSchemaNameFromRef(ref)];

if (!found && section === "responses") {
Expand All @@ -127,11 +127,18 @@ export function getReferencedSchema(ref: string) {
found = apiSpec.components?.schemas?.[name];
}

if (found && "content" in found) {
const jsonResponse = found.content?.['application/json']
if (jsonResponse && jsonResponse.schema) {
found = jsonResponse.schema
}
}

if (found && "$ref" in found) {
throw new Error("Referenced schema can not be a reference schema itself");
}

return found;
return found as OpenAPIV3.SchemaObject;
Copy link
Owner

Choose a reason for hiding this comment

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

I might find some time to check it out myself, but it would be great if we avoided the type assertion/cast.

I know the openapi types are very.... 'everything is a union of everything', but i would prefer this explicitly threw an exception if something isn't as expected, rather than propagate unexpectedly down.

}

// TODO: type this better, remove all the any casts
Expand Down