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

RangeError: Maximum call stack size exceeded #1197

Open
renatoathaydes opened this issue Dec 29, 2020 · 4 comments
Open

RangeError: Maximum call stack size exceeded #1197

renatoathaydes opened this issue Dec 29, 2020 · 4 comments

Comments

@renatoathaydes
Copy link

Describe the bug

Running this command:

spot generate --contract api.ts --language yaml --generator openapi3 --out build/

I get this error, once my model reaches a certain size (as it seems):

13 verbose stack Error: curity-haapi-model@1.0.0 generate: `spot generate --contract api.ts --language yaml --generator openapi3 --out build/`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:315:20)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:315:20)
13 verbose stack     at maybeClose (internal/child_process.js:1048:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)

To Reproduce
Steps to reproduce the behavior:

Create the api.ts file:

import { api, body, endpoint, request, response, String } from "@airtasker/spot";

@api({ name: "HAAPI" })
class Api { }

@endpoint({
  method: "POST",
  path: "/my-api"
})
class MyEndpoint {
  @request
  request(
    @body body: Request
  ) { }

  @response({ status: 200 })
  successfulResponse(
    @body body: MyResponse
  ) { }

  @response({ status: 400 })
  problemResponse(
    @body body: ProblemResponse
  ) { }

}

interface Request { }

interface ProblemResponse {
  type: string
  status: number
  title: string | null
  titleKey: string | null
  detail: string | null
  detailKey: string | null
  instance: string | null
}

type MyResponse = Step

// All MyResponse types extend from BaseResponse
interface BaseResponse {
  // TODO add more types
  type: "step"
  links: Link[]
  messages: Message[]
}

interface Step extends BaseResponse {
  type: "step"
  actions: Action[]
}

interface Link {
  href: string;
  rel: "self" | "continue";
  message: string | null;
  messageKey: string | null;
}

interface Message {
  text: string | null
  key: string | null
  classList: string[]
}

type Action = FormAction// | SelectorAction

interface FormAction {
  template: "form"
  // notice that kind can be any string... here we just enumerate the most common kinds
  kind: "form" | "redirect" | string
  model: FormModel
}

// interface SelectorAction {
//   template: "selector"
//   // notice that kind can be any string... here we just enumerate the most common kinds
//   kind: "selector-authenticator" | string
//   title: string | null,
//   titleKey: string | null,
//   model: SelectorModel
// }

interface FormModel {
  href: string
  method: "GET" | "POST" | "PATCH" | "DELETE" | "PUT"
  mediaType: string
  title: string | null
  titleKey: string | null
  actionTitle: string | null
  actionTitleKey: string | null
  fields: FormField[]
}

// interface SelectorModel {
//   title: string | null
//   titleKey: string | null
//   options: Action[]
// }

interface FormField {
  name: string
  type: "input" | "hidden" | "text" | "email" | "context"
  label: string | null
  labelKey: string | null
  value: string | null
}

Run spot generate --contract api.ts --language yaml --generator openapi3 --out build/.

It works fine... un-comment the few commented-out types in the example above and try again.

It will fail with the error mentioned above.

Expected behavior

It should not fail.

@renatoathaydes
Copy link
Author

Oh... I've just actually noticed that this seems to be related to the fact that the the commented-out type, SelectorModel, introduces type recursion!

Is there a workaround for cases like this?

@renatoathaydes
Copy link
Author

I assume this error is caused by the lack of support for recursive types mentioned at #1081?

@lfportal
Copy link
Contributor

lfportal commented Jan 4, 2021

Hi @renatoathaydes, sorry for the delayed response. Yup its exactly what you assumed, Spot currently doesn't expect recursive types.

@DjakaTechnology
Copy link

Hello, is there any workaround for this issue while we wait for recursive support?

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

No branches or pull requests

3 participants