Skip to content

Commit

Permalink
Merge branch 'rohin/convert-auth-openapi-parser-v2' into rohin/reques…
Browse files Browse the repository at this point in the history
…t-response-parsing
  • Loading branch information
RohinBhargava committed Dec 3, 2024
2 parents 9f75038 + e1bbfb8 commit 27caa05
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class OperationObjectConverterNode extends BaseOpenApiV3_1ConverterNode<
} else {
this.context.errors.warning({
message: `Expected parameter reference to resolve to an object. Received undefined reference: ${parameter.$ref}`,
path: this.accessPath,
path: [...this.accessPath, `parameters[${index}]`],
});
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ export class ResponseObjectConverterNode extends BaseOpenApiV3_1ConverterNode<

parse(streamingFormat: ResponseStreamingFormat | undefined): void {
this.description = this.input.description;
const input = isReferenceObject(this.input)
? resolveResponseReference(this.input, this.context.document)
: this.input;
const input = resolveResponseReference(this.input, this.context.document);

if (input == null) {
this.context.errors.error({
message: isReferenceObject(this.input)
? `Expected response reference to resolve to an object. Received undefined reference: ${this.input.$ref}`
: "Expected response to be defined. Received null",
? `Undefined reference: ${this.input.$ref}`
: "Expected response, received null",
path: this.accessPath,
});
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ export class OneOfConverterNode extends BaseOpenApiV3_1ConverterNode<
if (schema == null) {
this.context.errors.warning({
message: `Expected schema reference. Received undefined reference: ${value}`,
path: this.accessPath,
path: [...this.accessPath, "discriminator", "mapping", key],
});
return;
}
discriminatedMapping[key] = new SchemaConverterNode({
input: schema,
context: this.context,
accessPath: this.accessPath,
pathId: this.pathId,
accessPath: [...this.accessPath, "discriminator", "mapping", key],
pathId: key,
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class EnumConverterNode extends BaseOpenApiV3_1ConverterNode<
if (this.input.enum != null) {
let continueParsing = true;
this.values = this.input.enum
.map((value) => {
.map((value, index) => {
if (!continueParsing) {
return undefined;
}
Expand All @@ -31,7 +31,7 @@ export class EnumConverterNode extends BaseOpenApiV3_1ConverterNode<
if (typeof value !== "string") {
this.context.errors.error({
message: `Expected enum values to be strings. Received ${value}`,
path: this.accessPath,
path: [...this.accessPath, `enum[${index}]`],
});
continueParsing = false;
return undefined;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { OpenAPIV3_1 } from "openapi-types";
import { isReferenceObject } from "../../3.1/guards/isReferenceObject";
import { resolveReference } from "./resolveReference";

export function resolveResponseReference(
referenceObject: OpenAPIV3_1.ReferenceObject,
referenceObject: OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ResponseObject,
document: OpenAPIV3_1.Document,
): OpenAPIV3_1.ResponseObject | undefined {
return resolveReference<OpenAPIV3_1.ResponseObject | undefined>(referenceObject, document, undefined);
if (isReferenceObject(referenceObject)) {
return resolveReference<OpenAPIV3_1.ResponseObject | undefined>(referenceObject, document, undefined);
}

return referenceObject;
}

0 comments on commit 27caa05

Please sign in to comment.