Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all 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
19 changes: 17 additions & 2 deletions src/lib/apiSchemaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ export function getShortSchemaNameFromRef(ref: string) {
return bits[bits.length - 1];
}

function isResponseObject(node: OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject | OpenAPIV3.ResponseObject): node is OpenAPIV3.ResponseObject {
return 'content' in node
}

export function getReferencedSchema(ref: string) {
const [, , section, name] = ref.split("/");

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,10 +131,21 @@ export function getReferencedSchema(ref: string) {
found = apiSpec.components?.schemas?.[name];
}

if (found && isResponseObject(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");
}

if (found && isResponseObject(found)) {
throw new Error("Expected a Schema object, found a ResponseObject");
}

return found;
}

Expand Down