-
-
Notifications
You must be signed in to change notification settings - Fork 487
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 param $ref
s
#997
Fix param $ref
s
#997
Conversation
a8f1bd3
to
ce1d05d
Compare
Hi @drwpow, Thanks |
Are there any updates? I know @wolfy1339 already asked, but this undermines a lot of use cases for this project, its a major bug. Thanks again. |
@HunterKohler Will pick this back up again this week. I’m still looking for help with maintainers (#961) and only have limited capacity to work on it. But I think this can be finished and shipped soon. |
Hi @drwpow, since this bug affects us as well, I looked at the code and the PR to try and figure out the problem. I will try to explain my findings: The GoalGiven for example this API specification: openapi: 3.1.0
info:
version: 1.2.3
title: Example Service
paths:
/data/{foo}:
get:
parameters:
- $ref: '#/components/parameters/foo'
- $ref: '#/components/parameters/bar'
responses:
default:
description: A response
content:
text/plain:
schema:
type: string
components:
parameters:
foo:
name: foo
schema:
type: string
in: path
required: true
bar:
name: bar
schema:
type: string
in: query
required: true The expected output should be, as far as I understand, the following (shortened and ignoring formatting): export interface paths {
"/data/{foo}": {
get: {
parameters: {
path: {
foo: components["parameters"]["foo"];
}
query: {
bar: components["parameters"]["bar"];
}
}
};
};
}
export interface components {
parameters: {
foo: string;
bar: string;
};
} What is actually generated (again shortened for clarity): export interface paths {
"/data/{foo}": {
get: {
};
};
}
export interface components {
parameters: {
foo: string;
bar: string;
};
} The The Current ImplementationDebugging into operation-object.ts#67 for this example shows The Difficulty of the ProblemBefore I can explain why the PR doesn't yet fix the problem, I first have to explain why this particular case of resolving The Proposed Solution in this PRThis PR proposes to replace the line referenced before with: const partsParamIn = parts.find((p) => p === "query" || p === "header" || p === "path" || p === "cookie");
if (paramI === -1 || (partsParamIn && partsParamIn !== paramIn)) continue; This is an attempt to match the parameter currently examined ( So as the PR currently stands, the export interface paths {
"/data/{foo}": {
get: {
parameters: {
query: Pick<NonNullable<components["parameters"]>, "foo" | "bar">;
header: Pick<NonNullable<components["parameters"]>, "foo" | "bar">;
path: Pick<components["parameters"], "foo" | "bar">;
cookie: Pick<NonNullable<components["parameters"]>, "foo" | "bar">;
};
};
};
}
export interface components {
parameters: {
foo: string;
bar: string;
};
} This now picks all ref'd parameters for all locations. A somewhat unrelated problem can also be identified from this: The ternary operator in operation-object.ts#L92 needs to be swapped, since Digging DeeperParameter Object NamesI assume it is an intended feature of It seems important to mention (I wasn't aware of this before experimenting), that the parameter reference is not resolved by openapi: 3.1.0
info:
version: 1.2.3
title: Example Service
paths:
/data/{foo}:
get:
parameters:
- $ref: '#/components/parameters/foo-object-name'
- $ref: '#/components/parameters/bar'
responses:
default:
description: A response
content:
text/plain:
schema:
type: string
components:
parameters:
foo-object-name:
name: foo
schema:
type: string
in: path
required: true
bar:
name: bar
schema:
type: string
in: query
required: true This generates (shortened): export interface paths {
"/data/{foo}": {
get: {
parameters: {
query: Pick<NonNullable<components["parameters"]>, "foo-object-name" | "bar">;
header: Pick<NonNullable<components["parameters"]>, "foo-object-name" | "bar">;
path: Pick<components["parameters"], "foo-object-name" | "bar">;
cookie: Pick<NonNullable<components["parameters"]>, "foo-object-name" | "bar">;
};
};
};
}
export interface components {
parameters: {
"foo-object-name": string;
bar: string;
};
} Since a user of the API would have to fill a parameter with the name Parameter References Including the LocationWhen the (wrong) assumption of the proposed code change in this PR is fulfilled by doing this: paths:
/data/{foo}:
get:
parameters:
- $ref: '#/components/parameters/path/foo'
- $ref: '#/components/parameters/query/bar' This is wrong since the The following code is generated from the modified spec: export interface paths {
"/data/{foo}": {
get: {
parameters: {
query: Pick<NonNullable<components["parameters"]["query"]>, "bar">;
path: Pick<components["parameters"]["path"], "foo">;
};
};
};
}
export interface components {
parameters: {
foo: string;
bar: string;
};
} The selector The Actually Expected OutputFrom all this I deduct that the actually expected output should rather look something like this: export interface paths {
"/data/{foo}": {
get: {
parameters: {
query: Pick<components["parameters"]["query"], "bar">;
path: Pick<components["parameters"]["path"], "foo">;
};
responses: {
default: {
content: {
"text/plain": string;
};
};
};
};
};
}
export interface components {
parameters: {
path: {
foo: string;
}
query: {
bar: string;
}
};
} Summary
I really hope my insights help you. |
Changes
Fixes #984
How to Review
How can a reviewer review your changes? What should be kept in mind for this review?
Checklist
examples/
directory updated (if applicable)