-
-
Notifications
You must be signed in to change notification settings - Fork 533
Fix missing parameters in operation object #1090
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,25 +24,32 @@ export default function transformPathItemObject( | |
if (!operationObject) continue; | ||
const c = getSchemaObjectComment(operationObject, indentLv); | ||
if (c) output.push(indent(c, indentLv)); | ||
|
||
// fold top-level PathItem parameters into method-level, with the latter overriding the former | ||
const keyedParameters: Record<string, ParameterObject | ReferenceObject> = {}; | ||
if (!("$ref" in operationObject)) { | ||
// important: OperationObject parameters come last, and will override any conflicts with PathItem parameters | ||
for (const parameter of [...(pathItem.parameters ?? []), ...(operationObject.parameters ?? [])]) { | ||
// note: the actual key doesn’t matter here, as long as it can match between PathItem and OperationObject | ||
keyedParameters["$ref" in parameter ? parameter.$ref : parameter.name] = parameter; | ||
} | ||
} | ||
|
||
if ("$ref" in operationObject) { | ||
output.push(indent(`${method}: ${operationObject.$ref}`, indentLv)); | ||
} | ||
// if operationId exists, move into an `operations` export and pass the reference in here | ||
else if (operationObject.operationId) { | ||
const operationType = transformOperationObject(operationObject, { path, ctx: { ...ctx, indentLv: 1 } }); | ||
const operationType = transformOperationObject( | ||
{ ...operationObject, parameters: Object.values(keyedParameters) }, | ||
{ path, ctx: { ...ctx, indentLv: 1 } } | ||
); | ||
ctx.operations[operationObject.operationId] = { | ||
operationType, | ||
comment: getSchemaObjectComment(operationObject, 1), | ||
}; | ||
output.push(indent(`${method}: operations[${escStr(operationObject.operationId)}];`, indentLv)); | ||
} else { | ||
// fold top-level PathItem parameters into method-level, with the latter overriding the former | ||
const keyedParameters: Record<string, ParameterObject | ReferenceObject> = {}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just moves this up one level; that’s it! |
||
// important: OperationObject parameters come last, and will override any conflicts with PathItem parameters | ||
for (const parameter of [...(pathItem.parameters ?? []), ...(operationObject.parameters ?? [])]) { | ||
// note: the actual key doesn’t matter here, as long as it can match between PathItem and OperationObject | ||
keyedParameters["$ref" in parameter ? parameter.$ref : parameter.name] = parameter; | ||
} | ||
const operationType = transformOperationObject( | ||
{ ...operationObject, parameters: Object.values(keyedParameters) }, | ||
{ path, ctx: { ...ctx, indentLv } } | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,7 +276,7 @@ export interface RequestBodyObject extends Extensable { | |
*/ | ||
export interface MediaTypeObject extends Extensable { | ||
/** The schema defining the content of the request, response, or parameter. */ | ||
schema?: SchemaObject; | ||
schema?: SchemaObject | ReferenceObject; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Irrelevant type bug that came up while writing the test |
||
/** Example of the media type. The example object SHOULD be in the correct format as specified by the media type. The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema which contains an example, the example value SHALL override the example provided by the schema. */ | ||
example?: any; | ||
/** Examples of the media type. Each example object SHOULD match the media type and specified schema if present. The examples field is mutually exclusive of the example field. Furthermore, if referencing a schema which contains an example, the examples value SHALL override the example provided by the schema. */ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tweaked wording of this to harp on how helpful TDD is when contributing.
I am not that smart. I need TDD to be able to do anything in this library :P