Skip to content
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

Typescript generator. Using allOf in an external reference produces RangeError: Maximum call stack size exceeded. #1479

Closed
AlbinAndersson96 opened this issue Aug 17, 2023 · 8 comments · Fixed by #1757
Labels
bug Something isn't working

Comments

@AlbinAndersson96
Copy link

Describe the bug

When using allOf in an external schema and referencing said schema from the root, it potentially throws the below error when generating with the default Typescript generator.

RangeError: Maximum call stack size exceeded
    at Function.values (<anonymous>)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:104:41)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)
    at ConstrainedUnionModel.getNearestDependencies (<proj_root>\src\node_modules\@asyncapi\modelina\lib\cjs\models\ConstrainedMetaModel.js:112:35)

How to Reproduce

Generate models from the following spec files:

asyncapi.yaml

asyncapi: '2.6.0'
info:
  title: 'This is a title'
  version: '2.0.0'

channels:
  this/is/a/topic:
    publish:
      operationId: opId
      message:
        $ref: '#/components/messages/problemResponse'
  
components:
  messages:
    problemResponse:
      title: Problem Response
      contentType: application/problem+json
      payload:
        $ref: './problem.yaml#/parentProblems'

problem.yaml

parentProblems:
  x-parser-schema-id: problem
  oneOf:
    - $ref: '#/problem'
    - $ref: '#/parentProblems'
problem:
  x-parser-schema-id: problem
  type: object
  properties:
    type:
      type: string
      format: uri
  discriminator: '__extensionObjectType__'

Expected behavior

We expect the data models to generate, or alternatively throw an informative error if the use case isn't supported.

@AlbinAndersson96 AlbinAndersson96 added the bug Something isn't working label Aug 17, 2023
@github-actions
Copy link
Contributor

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

jonaslagoni commented Aug 17, 2023

This also re-produces it:

asyncapi: '2.6.0'
info:
  title: 'Persistent Storage'
  version: '2.0.0'

channels:
  this/is/a/topic:
    publish:
      operationId: opId
      message:
        $ref: '#/components/messages/problemResponse'
  
components:
  messages:
    problemResponse:
      title: Problem Response
      contentType: application/problem+json
      payload:
        $ref: '#/components/schemas/parentProblems'
  schemas: 
    parentProblems:
      oneOf:
        - $ref: '#/components/schemas/problem'
        - $ref: '#/components/schemas/parentProblems'
    problem:
      x-parser-schema-id: problem
      type: object
      properties:
        type:
          type: string
          format: URI

@jonaslagoni
Copy link
Member

@AlbinAndersson96 what is the expected output for this small example?

@AlbinAndersson96
Copy link
Author

AlbinAndersson96 commented Aug 18, 2023

@jonaslagoni Probably something similar to this when generating with defaults. Can't remember if named exports is the default but if it isn't just replace my export with the default.

import Problem from './Problem';

type ParentProblem = Problem | ParentProblem; // Very unsure about this. A type referencing itself?
export { ParentProblem };
class Problem {
  private _type?: string;

  constructor(input: {
    type?: string,
  }) {
    this._type = input.type;
  }

  get type(): string | undefined { return this._type; }
  set type(_type: string | undefined) { this._type= _type; }
}
export { Problem };

@AlbinAndersson96
Copy link
Author

AlbinAndersson96 commented Aug 18, 2023

EDIT: The original example in this comment did in fact NOT trigger the issue. The edited one does however

That said. The self-reference of ParentProblem is tripping me up a bit with how to actually generate it. This example also triggers the issue, without the self-reference.

asyncapi.yaml

asyncapi: '2.6.0'
info:
  title: 'Persistent Storage'
  version: '2.0.0'

channels:
  this/is/a/topic:
    publish:
      operationId: opId
      message:
        $ref: '#/components/messages/problemResponse'
  
components:
  messages:
    problemResponse:
      title: Problem Response
      contentType: application/problem+json
      payload:
        $ref: '#/components/schemas/problem'

  schemas:
    problem:
      $ref: './problem.yaml#/parentProblems'

problem.yaml

parentProblems:
  oneOf:
  - $ref: '#/problem'
  - $ref: '#/validationProblem'
problem:
  x-parser-schema-id: problem
  type: object
  properties:
    type:
      type: string
      format: uri
  discriminator: '__extensionObjectType__'
validationProblem:
  allOf:
    - $ref: '#/problem'
    - type: object
      properties:
        errors:
          type: object
          additionalProperties: true

Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity 😴

It will be closed in 120 days if no further activity occurs. To unstale this issue, add a comment with a detailed explanation.

There can be many reasons why some specific issue has no activity. The most probable cause is lack of time, not lack of interest. AsyncAPI Initiative is a Linux Foundation project not owned by a single for-profit company. It is a community-driven initiative ruled under open governance model.

Let us figure out together how to push this issue forward. Connect with us through one of many communication channels we established here.

Thank you for your patience ❤️

@github-actions github-actions bot added the stale label Dec 17, 2023
@jonaslagoni
Copy link
Member

Just encountered this problem, working on the fix "again" 🙃

@jonaslagoni
Copy link
Member

Should be fixed as of v3 ✌️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants