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

Reference type error results in non compiling code #234

Closed
jiachen1120 opened this issue Feb 23, 2019 · 3 comments
Closed

Reference type error results in non compiling code #234

jiachen1120 opened this issue Feb 23, 2019 · 3 comments
Assignees
Labels

Comments

@jiachen1120
Copy link
Contributor

jiachen1120 commented Feb 23, 2019

The name where the model generation for the types is suppressed but the types are not replaced with their corresponding primitive boxed types or array types. It results in non-compiling code.

e.g. I had schemas

"UserId": {
  "type": "string",
   "minLength" : 8,
   "maxLength: 32
},
"Pair": {
  "type": "object",
  "required": [
      "primary",
      "secondary"
  ],
  "properties": {
     "primary" : {
        "$ref" : "#/components/schemas/UserId"
      },
     "secondary" : {
        "$ref" : "#/components/schemas/UserId"
      }
  }
}

I would get the following model for Pair

class Pair {
  UserId primary;
  UserId secondary;
  
  // irrelevant details deleted
}

but will not get the model for UserId. Obviously the code would not compile.

Originally posted by @243826 in #204 (comment)

@jiachen1120 jiachen1120 changed the title Reference type error lead to fail compli Reference type error results in non compiling code Feb 23, 2019
@jiachen1120
Copy link
Contributor Author

All property's types start with $ref will be set to its own name. This is incorrect and should be replaced with the type it references.

The above specification should generate the following code

class Pair {
  String primary;
  String secondary;
  
  // irrelevant details deleted
}

@243826
Copy link
Contributor

243826 commented Feb 26, 2019

I ended up modifying the code in the light-codegen a bit and have a solution. Please review PR #238

stevehu pushed a commit that referenced this issue Mar 5, 2019
* support for references for arrays

* added a unit test to validate the the array references are created appropriately even when they are deep

* Fixed references of enum types.
@stevehu
Copy link
Contributor

stevehu commented Mar 20, 2019

@stevehu stevehu closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants