Is there a way to inline enums? #176
-
If I have |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi @electrosaur, Is the As per https://victools.github.io/jsonschema-generator/#generator-options
That should produce something like this: {
"type": "object",
"properties": {
"y": {
"type": "string",
"enum": ["HOURS", "DAYS", ...]
}
}
} If you want to generally avoid that enums are being referenced via the
The documentation of custom definition providers in general can be found here: |
Beta Was this translation helpful? Give feedback.
-
Hi Carsten:
Thanks for the prompt response.
Maybe I'm not doing it right. I have say TimeUnit timeUnit as a member
of my POJO. I'm getting
`timeUnit -> "{"$ref":"#/$defs/java.util.concurrent.TimeUnit"}"`
Maybe it's clashing with the DEFINITIONS_FOR_ALL_OBJECTS?
My code is:
```java
SchemaGeneratorConfigBuilder configBuilder =new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09,OptionPreset.PLAIN_JSON)
.with(module)
.with(FLATTENED_ENUMS)
.with(DEFINITIONS_FOR_ALL_OBJECTS);
configBuilder.forTypesInGeneral()
.withIdResolver(scope ->scope.getType().getErasedType().getName());
configBuilder.forTypesInGeneral()
.withDefinitionNamingStrategy(new DefaultSchemaDefinitionNamingStrategy() {
@OverRide public String getDefinitionNameForKey(DefinitionKey key,SchemaGenerationContext generationContext) {
return key.getType().getErasedType().getName();
}
});
```
And I'm reading the fields of the object via
`schema.get("properties").fields().forEachRemaining(...)`
Shankar
|
Beta Was this translation helpful? Give feedback.
Hi @electrosaur,
Is the
Option.FLATTENED_ENUMS
fulfilling your requirement?As per https://victools.github.io/jsonschema-generator/#generator-options
That should produce something like this:
If you want to generally avoid that enums are being referenced via the
$defs
/definitions
, then please refer to my answer on this issue: #123