diff --git a/.env.local-sample b/.env.local-sample index 16b29dc..ca93945 100644 --- a/.env.local-sample +++ b/.env.local-sample @@ -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 diff --git a/src/lib/apiSchemaUtils.ts b/src/lib/apiSchemaUtils.ts index aed93ce..611a1e5 100644 --- a/src/lib/apiSchemaUtils.ts +++ b/src/lib/apiSchemaUtils.ts @@ -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") { @@ -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; }