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

Do not inline enum class #144

Open
huehnerlady opened this issue May 18, 2021 · 1 comment
Open

Do not inline enum class #144

huehnerlady opened this issue May 18, 2021 · 1 comment

Comments

@huehnerlady
Copy link

Hi,

I am trying to generate a schema from my classes. so far I do like the feel of this library, but I did run into a problem which would prevent me actually using it: The enum classes get inlined instead of separated.
I saw that this was already asked in #11, but seemed to have been closed without fixing it?

It was asked for a Valid json:
I would expect, that the following Java class

public class Foo {

  public FooEnum value1;
  public FooEnum value2;
}


public enum FooEnum {
  FIRST_VALUE,
  SECOND_VALUE,
  THIRD_VALUE;
}

would generate the following schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Foo",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "value1": {
      "type": "string",
      "$ref": "#/definitions/FooEnum"
    },
    "value2": {
      "type": "string",
      "$ref": "#/definitions/FooEnum"
    }
  },
  "definitions": {
    "FooEnum": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    }
  }
}

but it generates:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Foo",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "value1": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    },
    "value2": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    }
  }
}

Is there the possibility to maybe fix that?

@stellingsimon
Copy link

This is causing problems for our use cases, too. So far we've been able to revert the undesired behaviour in a wrapper for the generator, but now we stumbled across a use-case which cannot be fixed externally.

Consider the following example:

public class Foo {

  public FooEnum value1;
  public AnotherFooEnum value2;
}


public enum FooEnum {
  FIRST_VALUE,
  SECOND_VALUE,
  THIRD_VALUE;
}

public enum AnotherFooEnum {
  FIRST_VALUE,
  SECOND_VALUE,
  THIRD_VALUE;
}

should generate

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Foo",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "value1": {
      "type": "string",
      "$ref": "#/definitions/FooEnum"
    },
    "value2": {
      "type": "string",
      "$ref": "#/definitions/AnotherFooEnum"
    }
  },
  "definitions": {
    "FooEnum": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    }
    Another"FooEnum": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    }
  }
}

but generates

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Foo",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "value1": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    },
    "value2": {
      "type": "string",
      "enum": [
        "FIRST_VALUE",
        "SECOND_VALUE",
        "THIRD_VALUE"
      ]
    }
  }
}

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

2 participants