Skip to content

Avoid overwriting predefined method definitions in ClassDefinition - #1330

Open
pardeepsinghverma wants to merge 1 commit into
dedoc:mainfrom
pardeepsinghverma:fix-preserve-predefined-method-definitions
Open

pardeepsinghverma wants to merge 1 commit into
dedoc:mainfrom
pardeepsinghverma:fix-preserve-predefined-method-definitions

Conversation

@pardeepsinghverma

Copy link
Copy Markdown

Fixes #1325

Description

When an endpoint returns a raw LengthAwarePaginator, Infer::analyzeClass re-analyzes the paginator class definition. While AfterLengthAwarePaginatorDefinitionCreatedExtension registers the refined OpenAPI schema on LengthAwarePaginator::methods['toArray'], subsequent lazy loading in ClassDefinition::lazilyLoadMethodDefinition() was unconditionally overwriting ->methods[] with a blank FunctionLikeDefinition for methods declared on the reflection class. This caused oArray to be re-analyzed from vendor source AST and discarded Scramble's paginator schema for any endpoints documented afterwards.

This change checks whether ->methods[] was already defined for the current class and marked as fully analyzed before creating a fresh unanalyzed definition, preserving extension-defined schemas while continuing to analyze overridden methods on child classes as expected.

Changes

  • In ClassDefinition::lazilyLoadMethodDefinition(), preserve existing method definitions when they belong to the current class and are fully analyzed.
  • Added regression test in AnonymousResourceCollectionTypeToSchemaTest ensuring pagination schemas for resource collections remain intact when documented after a raw paginator endpoint.

When a class definition has method definitions attached via extensions (such as AfterLengthAwarePaginatorDefinitionCreatedExtension), lazily loading methods should not overwrite them with an unanalyzed FunctionLikeDefinition if the method was already defined for this class and fully analyzed.

This prevents raw paginator endpoints from corrupting the pagination schema of subsequent endpoints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Returning a raw LengthAwarePaginator changes the pagination schema of endpoints documented after it

2 participants